JSDoc Configuration
Configure JSDoc validation with JS Style Kit
Overview
JS Style Kit includes comprehensive JSDoc validation through the eslint-plugin-jsdoc
plugin. This helps ensure consistent and well-documented code, which is particularly useful for library projects.
Basic Configuration
JSDoc validation is enabled by default with relaxed requirements. To configure it, use the jsdoc
option in your ESLint configuration:
Configuration Options
Disabling JSDoc Validation
To completely disable JSDoc validation:
Requiring JSDoc Comments
For library projects or code bases where documentation is critical, you can require JSDoc comments:
When requireJsdoc
is set to true
, JSDoc comments are required for:
- Function declarations
- Function expressions
- Arrow function expressions
- Class declarations
- Class expressions
- Method definitions
TypeScript Integration
When both JSDoc and TypeScript are enabled (TypeScript is enabled by default), JS Style Kit adjusts the JSDoc rules to work better with TypeScript:
- Disables the
jsdoc/no-types
rule since TypeScript already provides type information - Disables the
jsdoc/no-undefined-types
rule to avoid conflicts with TypeScript types
JSDoc Rules
JS Style Kit includes a comprehensive set of rules to validate JSDoc comments:
Structural Rules
- Consistent tag alignment
- Proper tag ordering
- Correct tag spacing
- Proper asterisk prefixing
- Multiline block formatting
Content Rules
- Require parameter descriptions
- Require return descriptions
- Require property descriptions
- Check parameter names match function parameters
- Check property names
- Validate types
- Check tag values
Example of Valid JSDoc
Here’s an example of a valid JSDoc comment under JS Style Kit’s rules:
With TypeScript
When using TypeScript, type annotations in JSDoc are discouraged since TypeScript already provides type information:
Best Practices
- Be Consistent: Use JSDoc consistently throughout your codebase
- Focus on Descriptions: With TypeScript, focus on describing what parameters and returns mean, not their types
- Enable Requirements for Libraries: For libraries or packages intended for public consumption, enable
requireJsdoc: true
- Use Examples: Add example usage with the
@example
tag for complex functions - Document Exceptions: Use
@throws
to document exceptions that might be thrown