Require JSDoc Hierarchy
Require JSDoc summary lines to follow the hierarchy chain derived from the file path and method name.
Summary
The require-jsdoc-hierarchy rule reports any JSDoc summary line on a class or method that does not match the expected hierarchy string.
The expected hierarchy is built from the file path segments after the first matching anchor directory (default: src), with each segment title-cased and separated by -. For methods, the method name is appended as the final segment. Known abbreviations (e.g., api to API, eslint to ESLint) are applied automatically.
Why Use This Rule?
- Ensures every JSDoc summary line is consistent and predictable across the codebase.
- Makes it possible to locate a class or method in the file tree by reading its JSDoc summary.
- Eliminates subjective or inconsistent summary text by deriving it mechanically from the file path.
Examples
Configuration
Options
warning
ignoreFiles is an escape hatch for files where this rule genuinely does not apply. It is not intended for routine use.
| Option | Type | Default | Description |
|---|---|---|---|
anchorDirectories | string[] | ['src'] | Directory names that serve as path anchors. |
ignoreFiles | string[] | [] | File patterns to skip. |
knownNames | Record<string, string> | {} | Custom brand/abbreviation mappings for prettifying. |
stripDirectories | string[] | ['types'] | Directory names to filter out from path parts. |
Autofix
This rule provides automatic fixes. Run ESLint with the --fix flag:
npx eslint --fix . --rule '@cbnventures/nova/require-jsdoc-hierarchy: error'
Troubleshooting
- Warning fires even though the summary looks correct — Check for extra or missing spaces around
-separators, and verify that known abbreviations match exactly (e.g.,APInotApi,ESLintnotEslint). - File is not under any anchor directory — The rule tries each
anchorDirectoriesentry in order. If none match, it falls back to using the filename stem as the hierarchy base (e.g.,sidebars.tsbecomesSidebars.). - Constructors are not checked — The rule skips constructor methods intentionally.