Add lint rule to validate type descriptions in README#1396
Conversation
|
I’ve opened a discussion in the ESLint repository about this: eslint/eslint#20704. |
b9e8ca8 to
9404a76
Compare
Enabling `"types": ["node"]` globally is risky because a source `.d.ts` file may silently depend on Node.js types. It will compile fine in this repo (since `@types/node` is installed as a dev dependency) but break for consumers who do not have `@types/node`.
cf95d5d to
7d63f4c
Compare
7d63f4c to
4a608a8
Compare
| @@ -1,5 +1,5 @@ | |||
| /** | |||
| Given a [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types) return the {@link Primitive | primitive type} it belongs to, or `never` if it's not a primitive. | |||
| Given a [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types) return the [primitive type](https://developer.mozilla.org/en-US/docs/Glossary/Primitive) it belongs to, or `never` if it's not a primitive. | |||
There was a problem hiding this comment.
Updated the link to an external link, because otherwise the README description would need manual adjusting because it'd be really complicated to automatically figure out where a particular symbol lives.
If a symbol link is absolutely required, then we'd have to disable the lint-rule for that specific list item and adjust the description manually, as mentioned here:
type-fest/lint-rules/readme-jsdoc-sync.js
Lines 84 to 89 in 8fb539c
| import {jsdocCodeblocksProcessor} from './lint-processors/jsdoc-codeblocks.js'; | ||
|
|
||
| /** @type {import('xo').FlatXoConfig} */ | ||
| /** @type {Array<import('eslint').Linter.Config>} */ |
There was a problem hiding this comment.
Had to switch to eslint type because of this issue.
| "test:tsc": "node --max-old-space-size=6144 ./node_modules/.bin/tsc", | ||
| "test:tsd": "node --max-old-space-size=6144 ./node_modules/.bin/tsd", | ||
| "test:xo": "node --max-old-space-size=6144 ./node_modules/.bin/xo --ignores=lint-processors/fixtures/**/*.d.ts", | ||
| "test:xo": "node --max-old-space-size=6144 ./node_modules/.bin/xo --ignores=lint-processors/fixtures/**/*.d.ts '**/*.{js,ts}' readme.md", |
There was a problem hiding this comment.
This is because XO doesn't seem to lint .md files even if there's an entry for .md files in the config.
|
I initially expected only minor discrepancies between the README and JSDoc descriptions, such as typos. However, there were several instances where the two were entirely different. So, I had to review them manually and select the better version. And at certain places, I had to make changes beyond just picking between the two. As a result, for some types, the JSDoc description has changed, while for some others, the README description has changed. And for some, both have changed. |
This PR adds a lint rule that enforces that type descriptions in the README exactly match the first line of their source JSDoc.
readme-jsdoc-lint-rule-demo.mov
The lint caught around 60 mismatches in the existing README file.