V Vant Docs

Code Comments

Vant code comments convention

Purpose

AI-first code must be self-documenting. Comments help AI agents understand codebase structure, decisions, and gotchas.

Schema

All comment blocks follow this format:

/**
 * Module/Function Name
 * One-line description
 *
 * Extended description if needed.
 *
 * Usage:
 *   const mod = require('./module');
 *   mod.function(args);
 *
 * @param {type} name - Description
 * @returns {type} Description
 *
 * SECURITY:
 * - Security consideration
 * - Another consideration
 *
 * Related: link/to/doc
 */

Required Sections

1. Module Header

Every file needs header with:

2. Function Docs

Every exported function needs:

3. Inline Comments

Use for:

Style

Do

Don’t

JSDoc Tags Used

Tag Purpose Example
@param Input param @param {string} name - User name
@returns Return value @returns {object} User object
@throws Error conditions @throws {Error} If not found
@example Code example @example user.get('name')
@see Related docs @see config.md

File Convention

Each lib/ file should have:

  1. File header comment (top)
  2. Module-level constants (if any)
  3. Exported functions with JSDoc
  4. Internal functions (commented)

Security Comments

Always document:

Example

/**
 * Get user by name
 * @param {string} name - User name to lookup
 * @returns {object|null} User object or null
 * @throws {Error} If name is invalid
 *
 * SECURITY: Validates name against VAF before lookup
 */
function getUser(name) {
    vaf.check(name, { type: 'string', name: 'user' });
    // ...
}

Quality Checklist