ESLint Plugin for TSDoc Syntax Validation
eslint-plugin-tsdoc is an ESLint plugin designed to enforce the TSDoc specification for documentation comments within TypeScript projects. It ensures that doc comments adhere to a structured format, improving consistency and machine-readability for tools like API extractors. The plugin's current stable version is 0.5.2 and it is actively maintained by the TSDoc project, indicating ongoing support and alignment with the TSDoc specification. Unlike general JSDoc validators, this plugin is specifically tailored for TypeScript and integrates seamlessly with the `@typescript-eslint` ecosystem, requiring its parser and plugin for correct operation. Its primary differentiation is strict adherence to the TSDoc standard, providing a more formal and type-aware documentation approach compared to looser JSDoc interpretations. Release cadence is typically driven by TSDoc spec updates or bug fixes, rather than a fixed schedule.
Common errors
-
Error: Plugin "tsdoc" was not found. Please check the plugin name, or consider installing it with npm.
cause The plugin name in the ESLint configuration `plugins` array is incorrect or missing the `eslint-plugin-` prefix.fixChange `plugins: ['tsdoc']` to `plugins: ['eslint-plugin-tsdoc']` or ensure the package is correctly installed. -
Parsing error: 'parserOptions.project' has been set for @typescript-eslint/parser. The file does not exist: /path/to/project/undefined
cause `parserOptions.project` or `tsconfigRootDir` is incorrectly configured, leading ESLint to look for a non-existent `tsconfig.json` file.fixVerify that `parserOptions.project` correctly points to your `tsconfig.json` (e.g., `./tsconfig.json`) and that `tsconfigRootDir` is correctly set to `__dirname` or the absolute root of your project containing `tsconfig.json`. -
Rule 'tsdoc/syntax' is not found.
cause The `tsdoc/syntax` rule is referenced in the `rules` section but the `eslint-plugin-tsdoc` plugin is not correctly loaded, or the rule name is mistyped.fixEnsure `eslint-plugin-tsdoc` is listed in the `plugins` array in your `.eslintrc.js` and that the rule name `tsdoc/syntax` is spelled correctly, including the `tsdoc/` prefix.
Warnings
- breaking Major versions of `@typescript-eslint/parser` or `@typescript-eslint/eslint-plugin` can introduce breaking changes that might affect how `eslint-plugin-tsdoc` interacts with your TypeScript code. Ensure compatibility when upgrading.
- gotcha Incorrect configuration of `parserOptions.project` or `tsconfigRootDir` in your ESLint setup can prevent `@typescript-eslint/parser` (and thus `eslint-plugin-tsdoc`) from correctly resolving type information, leading to parsing errors or rules not firing correctly, especially in monorepos.
- gotcha Failing to install or correctly configure `@typescript-eslint/parser` and `@typescript-eslint/eslint-plugin` will cause ESLint to fail to parse TypeScript files or recognize the TSDoc plugin's context.
Install
-
npm install eslint-plugin-tsdoc -
yarn add eslint-plugin-tsdoc -
pnpm add eslint-plugin-tsdoc
Imports
- eslint-plugin-tsdoc (plugin name)
plugins: [ "@typescript-eslint", "tsdoc" ]
plugins: [ "@typescript-eslint/eslint-plugin", "eslint-plugin-tsdoc" ]
- tsdoc/syntax (rule name)
rules: { "syntax": "warn" }rules: { "tsdoc/syntax": "warn" } - ESLint Configuration Object
export default { // ... config object ... };module.exports = { // ... config object ... };
Quickstart
npm install --save-dev eslint typescript @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-plugin-tsdoc
// .eslintrc.js
module.exports = {
plugins: [
"@typescript-eslint/eslint-plugin",
"eslint-plugin-tsdoc"
],
extends: [
'plugin:@typescript-eslint/recommended'
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: "./tsconfig.json",
tsconfigRootDir: __dirname,
ecmaVersion: 2018,
sourceType: "module"
},
rules: {
"tsdoc/syntax": "warn"
}
};