Skip to content

Commit 1ee3087

Browse files
chore: enable eslint-plugin-jsdoc internally (#8145)
* chore: enable eslint-plugin-jsdoc internally * Disable jsdoc/check-param-names, with link to issue * Sort jsdoc rule disables and add links to issues * Switch typescript-estree-import.ts to line comments
1 parent 958feca commit 1ee3087

34 files changed

+135
-75
lines changed

Diff for: .eslintrc.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports = {
1010
'eslint-plugin',
1111
'import',
1212
'jest',
13+
'jsdoc',
1314
'simple-import-sort',
1415
'unicorn',
1516
],
@@ -20,6 +21,7 @@ module.exports = {
2021
extends: [
2122
'eslint:recommended',
2223
'plugin:eslint-plugin/recommended',
24+
'plugin:jsdoc/recommended-typescript-error',
2325
'plugin:@typescript-eslint/strict-type-checked',
2426
'plugin:@typescript-eslint/stylistic-type-checked',
2527
],
@@ -140,6 +142,7 @@ module.exports = {
140142
'error',
141143
{ commentPattern: '.*intentional fallthrough.*' },
142144
],
145+
'one-var': ['error', 'never'],
143146

144147
//
145148
// eslint-plugin-eslint-comment
@@ -215,7 +218,24 @@ module.exports = {
215218
// enforce a sort order across the codebase
216219
'simple-import-sort/imports': 'error',
217220

218-
'one-var': ['error', 'never'],
221+
//
222+
// eslint-plugin-jsdoc
223+
//
224+
225+
// We often use @remarks or other ad-hoc tag names
226+
'jsdoc/check-tag-names': 'off',
227+
// https://github.com/gajus/eslint-plugin-jsdoc/issues/1169
228+
'jsdoc/check-param-names': 'off',
229+
// https://github.com/gajus/eslint-plugin-jsdoc/issues/1175
230+
'jsdoc/require-jsdoc': 'off',
231+
'jsdoc/require-param': 'off',
232+
'jsdoc/require-returns': 'off',
233+
'jsdoc/require-yields': 'off',
234+
'jsdoc/tag-lines': 'off',
235+
236+
//
237+
// eslint-plugin-unicorn
238+
//
219239

220240
'unicorn/no-typeof-undefined': 'error',
221241
},

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"eslint-plugin-eslint-plugin": "^5.1.0",
8989
"eslint-plugin-import": "^2.27.5",
9090
"eslint-plugin-jest": "^27.2.2",
91+
"eslint-plugin-jsdoc": "^46.9.1",
9192
"eslint-plugin-jsx-a11y": "^6.7.1",
9293
"eslint-plugin-react": "^7.32.2",
9394
"eslint-plugin-react-hooks": "^4.6.0",
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
/**
2-
* Nx is picking up on the fact that we technically have a circular dependency between ast-spec
3-
* and typescript-estree.
4-
*
5-
* This circular dependency only occurs in the tests/ for ast-spec and not in the main package source.
6-
*
7-
* We could therefore solve this by separating the ast-spec tests out into their own package, but the
8-
* other option is to get Nx to turn a blind eye to the circular dependency by removing
9-
* @typescript-eslint/typescript-estree as an explicit devDependency in the package.json and just doing an import here.
10-
*
11-
* This file is ignored via a root `.nxignore`
12-
*
13-
* This should be the only place in the package that we import from typescript-estree.
14-
*/
1+
// Nx is picking up on the fact that we technically have a circular dependency between ast-spec
2+
// and typescript-estree.
3+
//
4+
// This circular dependency only occurs in the tests/ for ast-spec and not in the main package source.
5+
//
6+
// We could therefore solve this by separating the ast-spec tests out into their own package, but the
7+
// other option is to get Nx to turn a blind eye to the circular dependency by removing
8+
// @typescript-eslint/typescript-estree as an explicit devDependency in the package.json and just doing an import here.
9+
//
10+
// This file is ignored via a root `.nxignore`
11+
//
12+
// This should be the only place in the package that we import from typescript-estree.
1513

1614
// eslint-disable-next-line no-restricted-imports -- the only safe and valid import from typescript-estree in this package
1715
export { parse, TSError } from '@typescript-eslint/typescript-estree';

Diff for: packages/eslint-plugin/src/rules/adjacent-overload-signatures.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export default createRule({
129129

130130
/**
131131
* Check the body for overload methods.
132-
* @param {ASTNode} node the body to be inspected.
132+
* @param node the body to be inspected.
133133
*/
134134
function checkBodyForOverloadMethods(node: RuleNode): void {
135135
const members = getMembers(node);

Diff for: packages/eslint-plugin/src/rules/consistent-type-imports.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,8 @@ export default createRule<Options, MessageIds>({
277277
report.unusedSpecifiers.length === 0 &&
278278
report.node.importKind !== 'type'
279279
) {
280-
/** checks if import has type assertions
280+
/**
281+
* checks if import has type assertions
281282
* ```
282283
* import * as type from 'mod' assert { type: 'json' };
283284
* ```

Diff for: packages/eslint-plugin/src/rules/func-call-spacing.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ export default createRule<Options, MessageIds>({
8282

8383
/**
8484
* Check if open space is present in a function name
85-
* @param {ASTNode} node node to evaluate
86-
* @returns {void}
85+
* @param node node to evaluate
8786
* @private
8887
*/
8988
function checkSpacing(

Diff for: packages/eslint-plugin/src/rules/member-delimiter-style.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ export default createRule<Options, MessageIds>({
314314

315315
/**
316316
* Check the member separator being used matches the delimiter.
317-
* @param {ASTNode} node the node to be evaluated.
317+
* @param node the node to be evaluated.
318318
*/
319319
function checkMemberSeparatorStyle(
320320
node: TSESTree.TSInterfaceBody | TSESTree.TSTypeLiteral,

Diff for: packages/eslint-plugin/src/rules/member-ordering.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,6 @@ function getMemberRawName(
438438
* Gets the member name based on the member type.
439439
*
440440
* @param node the node to be evaluated.
441-
* @param sourceCode
442441
*/
443442
function getMemberName(
444443
node: Member,
@@ -801,7 +800,7 @@ export default createRule<Options, MessageIds>({
801800
* Checks if the members are alphabetically sorted.
802801
*
803802
* @param members Members to be validated.
804-
* @param caseSensitive indicates if the alpha ordering is case sensitive or not.
803+
* @param order What order the members should be sorted in.
805804
*
806805
* @return True if all members are correctly sorted.
807806
*/

Diff for: packages/eslint-plugin/src/rules/no-loop-func.ts

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export default createRule<Options, MessageIds>({
3535
* - has any references which refers to an unsafe variable.
3636
*
3737
* @param node The AST node to check.
38-
* @returns Whether or not the node is within a loop.
3938
*/
4039
function checkForLoops(
4140
node:

Diff for: packages/eslint-plugin/src/rules/no-shadow.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ export default createRule<Options, MessageIds>({
545545

546546
/**
547547
* Checks the current context for shadowed variables.
548-
* @param {Scope} scope Fixme
548+
* @param scope Fixme
549549
*/
550550
function checkForShadows(scope: TSESLint.Scope.Scope): void {
551551
// ignore global augmentation

Diff for: packages/eslint-plugin/src/rules/no-unnecessary-condition.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ export default createRule<Options, MessageId>({
310310
* NOTE: It's also unnecessary if the types that don't overlap at all
311311
* but that case is handled by the Typescript compiler itself.
312312
* Known exceptions:
313-
* * https://github.com/microsoft/TypeScript/issues/32627
314-
* * https://github.com/microsoft/TypeScript/issues/37160 (handled)
313+
* - https://github.com/microsoft/TypeScript/issues/32627
314+
* - https://github.com/microsoft/TypeScript/issues/37160 (handled)
315315
*/
316316
const BOOL_OPERATORS = new Set([
317317
'<',

Diff for: packages/eslint-plugin/src/rules/no-unused-vars.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ export default createRule<Options, MessageIds>({
159159
function collectUnusedVariables(): TSESLint.Scope.Variable[] {
160160
/**
161161
* Checks whether a node is a sibling of the rest property or not.
162-
* @param {ASTNode} node a node to check
163-
* @returns {boolean} True if the node is a sibling of the rest property, otherwise false.
162+
* @param node a node to check
163+
* @returns True if the node is a sibling of the rest property, otherwise false.
164164
*/
165165
function hasRestSibling(node: TSESTree.Node): boolean {
166166
return (

Diff for: packages/eslint-plugin/src/rules/padding-line-between-statements.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ function isCJSRequire(node: TSESTree.Node): boolean {
182182
/**
183183
* Checks whether the given node is a block-like statement.
184184
* This checks the last token of the node is the closing brace of a block.
185-
* @param sourceCode The source code to get tokens.
186185
* @param node The node to check.
186+
* @param sourceCode The source code to get tokens.
187187
* @returns `true` if the node is a block-like statement.
188188
* @private
189189
*/
@@ -323,8 +323,8 @@ function isExpression(
323323
*
324324
* foo()
325325
* ;[1, 2, 3].forEach(bar)
326-
* @param sourceCode The source code to get tokens.
327326
* @param node The node to get.
327+
* @param sourceCode The source code to get tokens.
328328
* @returns The actual last token.
329329
* @private
330330
*/

Diff for: packages/eslint-plugin/src/rules/prefer-function-type.ts

-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ export default createRule({
7070
/**
7171
* @param member The TypeElement being checked
7272
* @param node The parent of member being checked
73-
* @param tsThisTypes
7473
*/
7574
function checkMember(
7675
member: TSESTree.TypeElement,

Diff for: packages/eslint-plugin/src/rules/prefer-regexp-exec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ export default createRule({
4646

4747
/**
4848
* Check if a given node type is a string.
49-
* @param node The node type to check.
49+
* @param type The node type to check.
5050
*/
5151
function isStringType(type: ts.Type): boolean {
5252
return getTypeName(checker, type) === 'string';
5353
}
5454

5555
/**
5656
* Check if a given node type is a RegExp.
57-
* @param node The node type to check.
57+
* @param type The node type to check.
5858
*/
5959
function isRegExpType(type: ts.Type): boolean {
6060
return getTypeName(checker, type) === 'RegExp';

Diff for: packages/eslint-plugin/src/rules/prefer-string-starts-ends-with.ts

-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ export default createRule({
7878
/**
7979
* Check if a given node is a `Literal` node that is a character.
8080
* @param node The node to check.
81-
* @param kind The method name to get a character.
8281
*/
8382
function isCharacter(node: TSESTree.Node): node is TSESTree.Literal {
8483
const evaluated = getStaticValue(node, globalScope);

Diff for: packages/eslint-plugin/src/rules/require-array-sort-compare.ts

-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ export default createRule<Options, MessageIds>({
5454

5555
/**
5656
* Check if a given node is an array which all elements are string.
57-
* @param node
5857
*/
5958
function isStringArrayNode(node: TSESTree.Expression): boolean {
6059
const type = services.getTypeAtLocation(node);

Diff for: packages/eslint-plugin/src/rules/space-before-function-paren.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ export default createRule<Options, MessageIds>({
7070

7171
/**
7272
* Determines whether a function has a name.
73-
* @param {ASTNode} node The function node.
74-
* @returns {boolean} Whether the function has a name.
73+
* @param node The function node.
74+
* @returns Whether the function has a name.
7575
*/
7676
function isNamedFunction(
7777
node:
@@ -97,8 +97,7 @@ export default createRule<Options, MessageIds>({
9797

9898
/**
9999
* Gets the config for a given function
100-
* @param {ASTNode} node The function node
101-
* @returns {string} "always", "never", or "ignore"
100+
* @param node The function node
102101
*/
103102
function getConfigForFunction(
104103
node:
@@ -129,8 +128,7 @@ export default createRule<Options, MessageIds>({
129128

130129
/**
131130
* Checks the parens of a function node
132-
* @param {ASTNode} node A function node
133-
* @returns {void}
131+
* @param node A function node
134132
*/
135133
function checkFunction(
136134
node:

Diff for: packages/eslint-plugin/src/util/astUtils.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ export * from '@typescript-eslint/utils/ast-utils';
1111
// Could be export { getNameLocationInGlobalDirectiveComment } from 'eslint/lib/rules/utils/ast-utils'
1212
/**
1313
* Get the `loc` object of a given name in a `/*globals` directive comment.
14-
* @param {SourceCode} sourceCode The source code to convert index to loc.
15-
* @param {Comment} comment The `/*globals` directive comment which include the name.
16-
* @param {string} name The name to find.
17-
* @returns {SourceLocation} The `loc` object.
14+
* @param sourceCode The source code to convert index to loc.
15+
* @param comment The `/*globals` directive comment which include the name.
16+
* @param name The name to find.
17+
* @returns The `loc` object.
1818
*/
1919
export function getNameLocationInGlobalDirectiveComment(
2020
sourceCode: TSESLint.SourceCode,

Diff for: packages/eslint-plugin/src/util/collectUnusedVariables.ts

-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ const MERGABLE_TYPES = new Set([
397397
/**
398398
* Determine if the variable is directly exported
399399
* @param variable the variable to check
400-
* @param target the type of node that is expected to be exported
401400
*/
402401
function isMergableExported(variable: TSESLint.Scope.Variable): boolean {
403402
// If all of the merged things are of the same type, TS will error if not all of them are exported - so we only need to find one

Diff for: packages/eslint-plugin/tests/rules/no-unnecessary-condition.test.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,7 @@ function test<T>(a: T) {
254254
}
255255
`,
256256

257-
/**
258-
* Predicate functions
259-
**/
257+
// Predicate functions
260258
`
261259
// with literal arrow function
262260
[0, 1, 2].filter(x => x);

Diff for: packages/parser/tests/tools/test-utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function createSnapshotTestBlock(
4343
config = Object.assign({}, defaultConfig, config);
4444

4545
/**
46-
* @returns {Object} the AST object
46+
* @returns the AST object
4747
*/
4848
function parse(): TSESTree.Program {
4949
const ast = parser.parseForESLint(code, config).ast;

Diff for: packages/rule-tester/src/utils/SourceCodeFixer.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function compareMessagesByLocation(a: LintMessage, b: LintMessage): number {
3434
* smart about the fixes and won't apply fixes over the same area in the text.
3535
* @param sourceText The text to apply the changes to.
3636
* @param messages The array of messages reported by ESLint.
37-
* @returns {Object} An object containing the fixed text and any unfixed messages.
37+
* @returns An object containing the fixed text and any unfixed messages.
3838
*/
3939
export function applyFixes(
4040
sourceText: string,
@@ -54,8 +54,8 @@ export function applyFixes(
5454

5555
/**
5656
* Try to use the 'fix' from a problem.
57-
* @param {Message} problem The message object to apply fixes from
58-
* @returns {boolean} Whether fix was successfully applied
57+
* @param problem The message object to apply fixes from
58+
* @returns Whether fix was successfully applied
5959
*/
6060
function attemptFix(problem: LintMessageWithFix): boolean {
6161
const fix = problem.fix;

Diff for: packages/rule-tester/src/utils/config-validator.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function validateRuleSchema(
9696
* Validates a rule's options against its schema.
9797
* @param rule The rule that the config is being validated for
9898
* @param ruleId The rule's unique name.
99-
* @param {Array|number} options The given options for the rule.
99+
* @param options The given options for the rule.
100100
* @param source The name of the configuration source to report in any errors. If null or undefined,
101101
* no source is prepended to the message.
102102
* @throws {Error} Upon any bad rule configuration.

Diff for: packages/scope-manager/src/ScopeManager.ts

-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class ScopeManager {
3939
public readonly declaredVariables: WeakMap<TSESTree.Node, Variable[]>;
4040
/**
4141
* The root scope
42-
* @public
4342
*/
4443
public globalScope: GlobalScope | null;
4544
public readonly nodeToScope: WeakMap<TSESTree.Node, Scope[]>;
@@ -93,7 +92,6 @@ class ScopeManager {
9392
* Get the variables that a given AST node defines. The gotten variables' `def[].node`/`def[].parent` property is the node.
9493
* If the node does not define any variable, this returns an empty array.
9594
* @param node An AST node to get their variables.
96-
* @public
9795
*/
9896
public getDeclaredVariables(node: TSESTree.Node): Variable[] {
9997
return this.declaredVariables.get(node) ?? [];
@@ -106,7 +104,6 @@ class ScopeManager {
106104
* @param node An AST node to get their scope.
107105
* @param inner If the node has multiple scopes, this returns the outermost scope normally.
108106
* If `inner` is `true` then this returns the innermost scope.
109-
* @public
110107
*/
111108
public acquire(node: TSESTree.Node, inner = false): Scope | null {
112109
function predicate(testScope: Scope): boolean {

Diff for: packages/scope-manager/src/referencer/VisitorBase.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ abstract class VisitorBase {
2929
/**
3030
* Default method for visiting children.
3131
* @param node the node whose children should be visited
32-
* @param exclude a list of keys to not visit
32+
* @param excludeArr a list of keys to not visit
3333
*/
3434
visitChildren<T extends TSESTree.Node>(
3535
node: T | null | undefined,

0 commit comments

Comments
 (0)