Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meta: Eslint JSDoc plugin #147

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions eslint.config.mjs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why the recommended config can't be used?

jsdoc.configs['flat/recommended-error']

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seem to be stricter rules than the ones we apply, I can even say that I am against some of the rules being applied as recommended

I tried to combine the rules we already apply as much as possible when using/developing features or for a more efficient review process

Original file line number Diff line number Diff line change
@@ -1,12 +1,43 @@
import pluginJs from '@eslint/js';
import eslintConfigPrettier from 'eslint-config-prettier';
import jsdoc from 'eslint-plugin-jsdoc';
import globals from 'globals';

export default [
// @see https://eslint.org/docs/latest/use/configure/configuration-files#specifying-files-and-ignores
{
files: ['src/**/*.mjs'],
plugins: {
jsdoc: jsdoc,
},
languageOptions: { globals: globals.node },
rules: {
'jsdoc/check-alignment': 'error',
'jsdoc/check-indentation': 'error',
'jsdoc/require-jsdoc': [
'error',
{
require: {
FunctionDeclaration: true,
MethodDefinition: true,
ClassDeclaration: true,
ArrowFunctionExpression: true,
FunctionExpression: true,
},
},
],
'jsdoc/require-param': 'error',
},
},
// Override rules for test files to disable JSDoc rules
{
files: ['src/**/*.test.mjs'],
rules: {
'jsdoc/check-alignment': 'off',
'jsdoc/check-indentation': 'off',
'jsdoc/require-jsdoc': 'off',
'jsdoc/require-param': 'off',
},
},
// @see https://eslint.org/docs/latest/use/configure/configuration-files#specifying-files-and-ignores
{
Expand Down
155 changes: 155 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@types/node": "^22.9.0",
"eslint": "^9.13.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jsdoc": "^50.5.0",
"globals": "^15.11.0",
"husky": "^9.1.6",
"lint-staged": "^15.2.10",
Expand Down
10 changes: 9 additions & 1 deletion src/generators/json-simple/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ export default {

dependsOn: 'ast',

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

// For the JSON generate we want to transform the whole content into JSON
/**
* For the JSON generate we want to transform the whole content into JSON
* @returns {string} The stringified JSON version of the content
*/
content.toJSON = () => remarkProcessor.stringify(content);

return { ...node, content };
Expand Down
19 changes: 12 additions & 7 deletions src/generators/legacy-html-all/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import { getRemarkRehype } from '../../utils/remark.mjs';

/**
* @typedef {{
* api: string;
* added: string;
* section: string;
* version: string;
* toc: string;
* nav: string;
* content: string;
* api: string;
* added: string;
* section: string;
* version: string;
* toc: string;
* nav: string;
* content: string;
* }} TemplateValues
*
* This generator generates the legacy HTML pages of the legacy API docs
Expand All @@ -41,6 +41,11 @@ export default {

dependsOn: 'legacy-html',

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

Expand Down
19 changes: 12 additions & 7 deletions src/generators/legacy-html/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import { getRemarkRehype } from '../../utils/remark.mjs';

/**
* @typedef {{
* api: string;
* added: string;
* section: string;
* version: string;
* toc: string;
* nav: string;
* content: string;
* api: string;
* added: string;
* section: string;
* version: string;
* toc: string;
* nav: string;
* content: string;
* }} TemplateValues
*
* This generator generates the legacy HTML pages of the legacy API docs
Expand All @@ -43,6 +43,11 @@ export default {

dependsOn: 'ast',

/**
* Generates the legacy version of the API docs in HTML
* @param {Input} input
* @param {Partial<GeneratorOptions>} options
*/
async generate(input, { releases, version, output }) {
// This array holds all the generated values for each module
const generatedValues = [];
Expand Down
Loading
Loading