Skip to content

Commit 4963da2

Browse files
authored
meta: Eslint JSDoc plugin (#147)
1 parent a2df781 commit 4963da2

File tree

13 files changed

+297
-28
lines changed

13 files changed

+297
-28
lines changed

eslint.config.mjs

+31
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,43 @@
11
import pluginJs from '@eslint/js';
22
import eslintConfigPrettier from 'eslint-config-prettier';
3+
import jsdoc from 'eslint-plugin-jsdoc';
34
import globals from 'globals';
45

56
export default [
67
// @see https://eslint.org/docs/latest/use/configure/configuration-files#specifying-files-and-ignores
78
{
89
files: ['src/**/*.mjs'],
10+
plugins: {
11+
jsdoc: jsdoc,
12+
},
913
languageOptions: { globals: globals.node },
14+
rules: {
15+
'jsdoc/check-alignment': 'error',
16+
'jsdoc/check-indentation': 'error',
17+
'jsdoc/require-jsdoc': [
18+
'error',
19+
{
20+
require: {
21+
FunctionDeclaration: true,
22+
MethodDefinition: true,
23+
ClassDeclaration: true,
24+
ArrowFunctionExpression: true,
25+
FunctionExpression: true,
26+
},
27+
},
28+
],
29+
'jsdoc/require-param': 'error',
30+
},
31+
},
32+
// Override rules for test files to disable JSDoc rules
33+
{
34+
files: ['src/**/*.test.mjs'],
35+
rules: {
36+
'jsdoc/check-alignment': 'off',
37+
'jsdoc/check-indentation': 'off',
38+
'jsdoc/require-jsdoc': 'off',
39+
'jsdoc/require-param': 'off',
40+
},
1041
},
1142
// @see https://eslint.org/docs/latest/use/configure/configuration-files#specifying-files-and-ignores
1243
{

package-lock.json

+155
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"@types/node": "^22.9.0",
2222
"eslint": "^9.13.0",
2323
"eslint-config-prettier": "^9.1.0",
24+
"eslint-plugin-jsdoc": "^50.5.0",
2425
"globals": "^15.11.0",
2526
"husky": "^9.1.6",
2627
"lint-staged": "^15.2.10",

src/generators/json-simple/index.mjs

+9-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ export default {
2929

3030
dependsOn: 'ast',
3131

32+
/**
33+
* Generates the simplified JSON version of the API docs
34+
* @param {Input} input
35+
* @param {Partial<GeneratorOptions>} options
36+
*/
3237
async generate(input, options) {
3338
// Gets a remark processor for stringifying the AST tree into JSON
3439
const remarkProcessor = getRemark();
@@ -45,7 +50,10 @@ export default {
4550
createQueries.UNIST.isHeading,
4651
]);
4752

48-
// For the JSON generate we want to transform the whole content into JSON
53+
/**
54+
* For the JSON generate we want to transform the whole content into JSON
55+
* @returns {string} The stringified JSON version of the content
56+
*/
4957
content.toJSON = () => remarkProcessor.stringify(content);
5058

5159
return { ...node, content };

src/generators/legacy-html-all/index.mjs

+12-7
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import { getRemarkRehype } from '../../utils/remark.mjs';
1212

1313
/**
1414
* @typedef {{
15-
* api: string;
16-
* added: string;
17-
* section: string;
18-
* version: string;
19-
* toc: string;
20-
* nav: string;
21-
* content: string;
15+
* api: string;
16+
* added: string;
17+
* section: string;
18+
* version: string;
19+
* toc: string;
20+
* nav: string;
21+
* content: string;
2222
* }} TemplateValues
2323
*
2424
* This generator generates the legacy HTML pages of the legacy API docs
@@ -41,6 +41,11 @@ export default {
4141

4242
dependsOn: 'legacy-html',
4343

44+
/**
45+
* Generates the `all.html` file from the `legacy-html` generator
46+
* @param {Input} input
47+
* @param {Partial<GeneratorOptions>} options
48+
*/
4449
async generate(input, { version, releases, output }) {
4550
const inputWithoutIndex = input.filter(entry => entry.api !== 'index');
4651

src/generators/legacy-html/index.mjs

+12-7
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ import { getRemarkRehype } from '../../utils/remark.mjs';
1414

1515
/**
1616
* @typedef {{
17-
* api: string;
18-
* added: string;
19-
* section: string;
20-
* version: string;
21-
* toc: string;
22-
* nav: string;
23-
* content: string;
17+
* api: string;
18+
* added: string;
19+
* section: string;
20+
* version: string;
21+
* toc: string;
22+
* nav: string;
23+
* content: string;
2424
* }} TemplateValues
2525
*
2626
* This generator generates the legacy HTML pages of the legacy API docs
@@ -43,6 +43,11 @@ export default {
4343

4444
dependsOn: 'ast',
4545

46+
/**
47+
* Generates the legacy version of the API docs in HTML
48+
* @param {Input} input
49+
* @param {Partial<GeneratorOptions>} options
50+
*/
4651
async generate(input, { releases, version, output }) {
4752
// This array holds all the generated values for each module
4853
const generatedValues = [];

0 commit comments

Comments
 (0)