agentleFS
loskyerttloskyertt/agent_skills/code-comment-guidelines/SKILL.md

code-comment-guidelines

Skill0 starsChanged 6 months agoMITView on GitHub

Code comment guidelines based on industry best practices. Use when reviewing code, writing new code, or when asked about comment quality. Applies to all languages but specializes in TypeScript/JavaScript. Enforces "JSDoc for public APIs only, no redundant comments" principle. Automatically suggests comment additions, removals, or refactoring alternatives.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

7 rules. About 0 are common, 7 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈7

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Prefer refactoring over commenting

    line 18
  2. Distinctive:

    Use this checklist to determine if a comment is needed:

    line 32
  3. Distinctive:

    Action: If logic is complex, extract to well-named functions/variables.

    line 46
  4. Distinctive:

    Action: Remove comments that duplicate type information.

    line 93
  5. Distinctive:

    When analyzing code, automatically:

    line 97
  6. Distinctive:

    When reviewing code comments, provide:

    line 201
  7. Distinctive:

    Recommended Changes: Add JSDoc, remove redundant comments, extract helper function

    line 218

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Code Comment Guidelines

Enforce industry best practices for code comments based on principles from Robert C. Martin (Clean Code), Martin Fowler (Refactoring), and other software engineering experts.

Core Principle

"JSDoc for public APIs only, no redundant comments"

  • Comments are a last resort, not a first choice
  • Code should be self-explanatory through good naming and structure
  • Comments explain WHY, never WHAT or HOW
  • Prefer refactoring over commenting

When to Use This Skill

Invoke this skill when:

  1. Code review: Evaluating comment quality in pull requests
  2. Writing code: Deciding whether to add a comment
  3. Refactoring: Removing outdated or redundant comments
  4. Documentation: Writing JSDoc for public APIs
  5. Quality checks: Asked to "check comments" or "improve documentation"

Decision Framework

Use this checklist to determine if a comment is needed:

Step 1: Can you refactor instead?

// ❌ Bad: Comment explains complex logic
// Calculate total with tax and discount
const total = price - price * discount + (price - price * discount) * taxRate;

// ✅ Good: Refactor to self-documenting code
const discountedPrice = price * (1 - discount);
const total = discountedPrice * (1 + taxRate);

Action: If logic is complex, extract to well-named functions/variables.

Step 2: Is this a public API?

// ✅ Required: Public exported function needs JSDoc
/**
 * Calculates tax-inclusive total price after discount
 * @param price - Base price in cents
 * @param discount - Discount rate (0-1)
 * @param taxRate - Tax rate (0-1)
 * @returns Final price in cents
 */
export function calculateTotal(price: number, discount: number, taxRate: number): number {
  const discountedPrice = price * (1 - discount);
  return discountedPrice * (1 + taxRate);
}

Action: All exported functions, classes, and complex constants require JSDoc.

Step 3: Is there a non-obvious technical reason?

// ✅ Good: Explains performance optimization
// Convert to Map for O(1) lookup instead of O(n) array.find()
// Reduces search time from ~500ms to <1ms with 1000+ items
const postsMap = new Map(posts.map((p) => [p.id, p]));

Action: Comment only when explaining:

  • Performance optimizations with measurements
  • Library constraints or workarounds
  • Hardware/browser compatibility issues
  • Non-obvious algorithm choices

Step 4: Does TypeScript already document this?

// ❌ Redundant: Type already documents this
const user: User = fetchUser(); // Returns a User object

// ✅ Good: Type is sufficient
const user: User = fetchUser();

Action: Remove comments that duplicate type information.

Automatic Actions

When analyzing code, automatically:

1. Flag Redundant Comments

// ❌ Remove: Repeats what code says
counter++; // Increment counter
if (user === null) return null; // Return null if user is null

Suggestion: "Remove redundant comment. Code is self-explanatory."

2. Suggest Refactoring

// ❌ Comment indicates refactoring opportunity
// Loop through users and check if email matches
for (let i = 0; i < users.length; i++) {
  if (users[i].email === email) return users[i];
}

// ✅ Suggest: Extract to function
function findUserByEmail(email: string): User | undefined {
  return users.find((u) => u.email === email);
}

Suggestion: "Extract to function findUserByEmail() instead of commenting."

3. Request JSDoc for Public APIs

// ❌ Missing documentation
export function processPayment(amount: number, currency: string) {
  // implementation
}

// ✅ Suggest: Add JSDoc
/**
 * Process payment transaction
 * @param amount - Payment amount in smallest currency unit (e.g., cents)
 * @param currency - ISO 4217 currency code (e.g., "USD")
 * @throws {PaymentError} If payment gateway rejects transaction
 */
export function processPayment(amount: number, currency: string) {
  // implementation
}

Suggestion: "Add JSDoc documentation for exported function."

4. Improve Existing Comments

// ❌ Low-quality comment
// TODO: fix this later

// ✅ Suggest improvement
// TODO(issue-#123): Implement exponential backoff for retry logic

Suggestion: "Make TODO specific with issue link and description."

Language-Specific Guidance

TypeScript/JavaScript

For TypeScript-specific patterns (React hooks, Server Components, type guards, etc.), refer to:

See typescript-specific.md for:

  • JSDoc requirements for public APIs
  • React component documentation
  • Server vs Client Components
  • Type guard documentation
  • useMemo/useCallback comment patterns

General Programming

For language-agnostic principles with examples in multiple languages, refer to:

See examples.md for:

  • Redundant comment examples
  • Function documentation patterns
  • Performance optimization comments
  • Business logic refactoring
  • Complex algorithm documentation

Expert Principles

For detailed rationale behind these guidelines, refer to:

See experts.md for:

  • Robert C. Martin (Uncle Bob) - "Comments are a failure"
  • Martin Fowler - "Comment needs are code smells"
  • Jeff Atwood - "Code = HOW, Comments = WHY"
  • Steve McConnell - "Elevate abstraction level"
  • Linus Torvalds - "Explain design decisions"
  • John Carmack - "Small functions eliminate comments"

Output Format

When reviewing code comments, provide:

  1. Overall Assessment: Comment quality score (Good / Needs Improvement / Poor)
  2. Specific Issues: List each problem with location
  3. Suggestions: Concrete improvements with code examples
  4. Refactoring Opportunities: Where refactoring eliminates comment needs

Example Output

Overall Assessment: Needs Improvement

Issues Found:

  1. Line 12: Redundant comment // Calculate total price → Remove
  2. Line 34: Missing JSDoc for export function applyDiscount() → Add documentation
  3. Line 56: Complex logic needs refactoring → Extract to calculateBulkDiscount()

Recommended Changes: Add JSDoc, remove redundant comments, extract helper function

Quick Reference

SituationComment?Alternative
Simple operation❌ NoSelf-explanatory code
Public API (exported)✅ Yes (JSDoc)N/A - Required
Complex algorithm✅ Yes (high-level)+ Good naming
Performance optimization✅ Yes (with metrics)N/A
Business logic❌ NoNamed constants/functions
Library workaround✅ Yes (with link)N/A
Type information❌ NoTypeScript types
Magic number❌ NoNamed constant
TODO note✅ Yes (specific + link)Issue tracker

Remember

"Don't comment bad code—rewrite it." - Robert C. Martin

The best comment is the one you don't need to write.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.