Skip to content
inline-documentation logo

Inline Documentation

inline-documentation

Use when writing code - ensure complete JSDoc, docstrings, and inline comments assuming documentation will be generated from code

SKILL.md

Full skill instructions

Inline Documentation

Overview

Document code assuming docs will be generated from it.

Core principle: Future developers (including you) will read this code. Help them.

Announce at use: "I'm adding complete inline documentation for this code."

What to Document

Always Document

ElementDocumentation Required
Public functions/​methodsFull JSDoc/​docstring
Public classesClass-level documentation
Public interfaces/​typesDescription of purpose
Exported constantsWhat they control
Complex logicWhy, not what
Non-obvious decisionsExplain reasoning

Skip Documentation For

ElementWhy
Private trivial helpersSelf-evident
Single-line gettersObvious from name
Standard patternsWell-known idioms
Test filesTests are documentation

TypeScript/​JavaScript (JSDoc)

Function Documentation

/​**
 * Calculates the total price including tax and discounts.
 *
 * @description Applies discounts before tax calculation.
 * Discounts are applied in order of magnitude (largest first).
 *
 * @param items - Line items to calculate
 * @param taxRate - Tax rate as decimal (e.g., 0.08 for 8%)
 * @param discounts - Optional discount codes to apply
 * @returns Total price after discounts and tax
 *
 * @throws {ValidationError} If taxRate is negative
 * @throws {InvalidDiscountError} If discount code is invalid
 *
 * @example
 * ```typescript
 * const total = calculateTotal(
 *   [{ price: 100 }, { price: 50 }],
 *   0.08,
 *   ['SAVE10']
 * );
 * // Returns: 145.80 (150 - 10% discount = 135, + 8% tax)
 * ```
 */
function calculateTotal(
  items: LineItem[],
  taxRate: number,
  discounts?: string[]
): number {
  // Implementation
}

Class Documentation

/​**
 * Manages user authentication and session lifecycle.
 *
 * @description Handles login, logout, session refresh, and
 * multi-device session management. Uses JWT for stateless
 * authentication with Redis for session invalidation tracking.
 *
 * @example
 * ```typescript
 * const auth = new AuthService(config);
 * const session = await auth.login(credentials);
 * await auth.logout(session.id);
 * ```
 */
class AuthService {
  /​**
   * Creates an AuthService instance.
   *
   * @param config - Authentication configuration
   * @param config.jwtSecret - Secret for signing JWTs
   * @param config.sessionTtl - Session time-to-live in seconds
   */
  constructor(private config: AuthConfig) { }

  /​**
   * Authenticates a user and creates a session.
   *
   * @param credentials - User credentials
   * @returns Session object with tokens
   * @throws {InvalidCredentialsError} If authentication fails
   */
  async login(credentials: Credentials): Promise<Session> { }
}

Interface Documentation

/​**
 * Configuration for the caching layer.
 *
 * @description Controls cache behavior including TTL,
 * invalidation strategy, and storage backend selection.
 */
interface CacheConfig {
  /​** Time-to-live in seconds. Default: 3600 */
  ttl: number;

  /​** Maximum items to cache. Default: 1000 */
  maxSize: number;

  /​**
   * Storage backend to use.
   * - 'memory': In-process LRU cache
   * - 'redis': Distributed Redis cache
   */
  backend: 'memory' | 'redis';

  /​** Redis connection string (required if backend is 'redis') */
  redisUrl?: string;
}

Python (Docstrings)

Function Documentation

def calculate_total(
    items: list[LineItem],
    tax_rate: float,
    discounts: list[str] | None = None
) -> float:
    """Calculate the total price including tax and discounts.

    Applies discounts before tax calculation. Discounts are applied
    in order of magnitude (largest first).

    Args:
        items: Line items to calculate.
        tax_rate: Tax rate as decimal (e.g., 0.08 for 8%).
        discounts: Optional discount codes to apply.

    Returns:
        Total price after discounts and tax.

    Raises:
        ValidationError: If tax_rate is negative.
        InvalidDiscountError: If discount code is invalid.

    Example:
        >>> total = calculate_total(
        ...     [LineItem(price=100), LineItem(price=50)],
        ...     0.08,
        ...     ['SAVE10']
        ... )
        >>> total
        145.80  # 150 - 10% = 135, + 8% tax
    """
    pass

Class Documentation

class AuthService:
    """Manages user authentication and session lifecycle.

    Handles login, logout, session refresh, and multi-device
    session management. Uses JWT for stateless authentication
    with Redis for session invalidation tracking.

    Attributes:
        config: Authentication configuration.
        redis: Redis client for session tracking.

    Example:
        >>> auth = AuthService(config)
        >>> session = await auth.login(credentials)
        >>> await auth.logout(session.id)
    """

    def __init__(self, config: AuthConfig) -> None:
        """Create an AuthService instance.

        Args:
            config: Authentication configuration including
                JWT secret and session TTL.
        """
        pass

Inline Comments

When to Use

// Complex algorithms
function dijkstra(graph: Graph, start: Node): Map<Node, number> {
  // Use priority queue for O(E log V) complexity
  // instead of linear search O(V²)
  const queue = new PriorityQueue<Node>();

  // Initialize all distances to infinity except start
  const distances = new Map<Node, number>();

  // ... implementation with strategic comments
}

Explain Why, Not What

// BAD: Explains what (obvious from code)
// Increment counter by 1
counter++;

// GOOD: Explains why (not obvious)
// Retry count starts at 1 because initial attempt doesn't count
counter++;

Link to Context

// Per RFC 7519, JWT expiry is in seconds since epoch
const exp = Math.floor(Date.now() / 1000) + ttlSeconds;

// See issue #234 for why we can't use the simpler approach
const result = complexWorkaround();

Mark Non-Obvious Behavior

// IMPORTANT: Order matters here - auth must run before rate limit
app.use(authMiddleware);
app.use(rateLimitMiddleware);

// WARNING: This modifies the input array in place
items.sort((a, b) => a.priority - b.priority);

Documentation Checklist

For each public element:

Functions/​Methods

  • Brief description (first line)
  • Detailed description (if complex)
  • All parameters documented
  • Return value documented
  • Exceptions documented
  • Example provided (if non-obvious usage)

Classes

  • Class purpose described
  • Usage example provided
  • All public methods documented
  • Public properties documented

Interfaces/​Types

  • Purpose described
  • Each property documented
  • Valid values noted (for enums/​unions)

Anti-Patterns

Anti-PatternCorrect Approach
No documentationDocument all public APIs
Stale documentationUpdate docs with code changes
Obvious commentsOnly document non-obvious
Missing examplesAdd examples for complex APIs
Copy-paste docsWrite specific documentation

Generating Documentation

TypeScript

# Using TypeDoc
npx typedoc src/​index.ts --out docs

# Using TSDoc
npx @microsoft/​api-extractor run

Python

# Using Sphinx
sphinx-apidoc -o docs/​source src/
sphinx-build docs/​source docs/​build

# Using pdoc
pdoc --html src/ -o docs/

Integration

This skill is applied by:

  • issue-driven-development - Step 7
  • comprehensive-review - Documentation criterion

This skill ensures:

  • Maintainable code
  • Onboarding ease
  • Generated documentation quality
  • API discoverability

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View