Add ESLint rules to enforce our docs standards
See original GitHub issueFeature Description
Essentially the same as #924, but for JavaScript.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
There should be ESLint rules to enforce the following:
Semantical
- Every description of everything starts with a capital letter (descriptions, parameter docs, return docs, …).
- Every description of everything ends in a dot (descriptions, parameter docs, return docs, …).
- For functions, the first word of the description must end in an “s” (this is probably 99% reliable, but most importantly should never yield a false positive - I don’t think there are any exceptions to the grammatical rule of 3P verbs ending in an “s”).
Organizational
- Every
paramandreturntag has a type and description. - Every function doc-block should have a
sincetag. - The order of tags (if present, for each) should be
since(multiple entries allowed),deprecated,private,param(multiple entries allowed),return. - For methods and functions, tags should be grouped:
since/deprecated/privateshould be grouped together, separated by a blank line fromparam/returnwhich should be grouped together. - All
paramtag types and descriptions in a single doc-block should be indented in a way that they are aligned with each other.
Implementation Brief
- Build on the work in #722 (PR: #1847) that allows us to write custom ESLint rules
- For requiring
paramandreturntypes, etc., add to.eslintrc.json:
"jsdoc/check-types": ["error"],
"jsdoc/require-param": ["error"],
"jsdoc/require-param-description": ["error"],
"jsdoc/require-param-name": ["error"],
"jsdoc/require-param-type": ["error"],
"jsdoc/require-returns-check": ["error"],
"jsdoc/require-returns-description": ["error"],
"jsdoc/require-returns-type": ["error"],
"jsdoc/require-returns": ["error"],
"jsdoc/no-undefined-types": ["error"],
"jsdoc/valid-types": ["error"],
- Add rules for each of the points above
- Consider using https://github.com/gajus/eslint-plugin-jsdoc for some of the above rules and as inspiration/a utility library for our own JSDoc rules.
- Parse any JSDoc comments with a JSDoc parser and ensure tags like
@sinceexist and match our format
JSDoc blocks can be straightforwardly-extracted using this code in an ESLint rule:
'jsdoc-rule-name': {
create( context ) {
const source = context.getSourceCode();
return {
'*': ( node ) => {
const jsDoc = source.getJSDocComment( node );
if ( ! jsDoc ) {
return;
}
if ( ! jsDocPassesCheck( jsDoc ) ) {
context.report( { node, message: `Missing something in JSDoc.`, data: { name: node.name } } );
}
},
};
},
}
though there is likely a more efficient selector 😄
Afterward: be sure to fix all errors flagged by ESLint.
Because of the unknowns in managing the parsers and the amount of errors encountered when enabling even the suggested rules from eslint-plugin-jsdoc, this is a reasonably-larged sized issue and is best-handled by someone familiar with ESLint (eg. probably me 😆 ).
QA Brief
- Ensure no ESLint errors are encountered, and create/modify a few JSDoc blocks with JSDoc entries that should cause the above checks to fail and ensure an error is raised when running
npm run lint:js.
Changelog entry
- N/A
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Rules - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >Rules - ESLint - Pluggable JavaScript Linter
Rules are the core building block of ESLint. A rule validates if your code meets a certain expectation, and what to do if...
Read more >Working with Rules - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >Configuring ESLint - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >Configuration Files - ESLint - Pluggable JavaScript Linter
You can put your ESLint project configuration in a configuration file. You can include built-in rules, how you want them enforced, plugins with...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@tofumatt @aaemnnosttv Since this is not critical for plugin usage and therefore shouldn’t block the release, I suggest we create a follow-up issue to fix the above valid points and then consider this one completed.
@felixarntz @tofumatt the new issue is here (https://github.com/google/site-kit-wp/issues/2154) and ready for an IB 👍