eslint-plugin-jsdoc 64.3.5 → 64.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"url": "http://gajus.com"
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@es-joy/jsdoccomment": "~0.
|
|
8
|
+
"@es-joy/jsdoccomment": "~0.97.0",
|
|
9
9
|
"@es-joy/resolve.exports": "1.2.0",
|
|
10
10
|
"@typescript-eslint/utils": "^8.69.0",
|
|
11
11
|
"are-docs-informative": "^0.1.1",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"camelcase": "^9.0.0",
|
|
52
52
|
"chai": "^6.2.2",
|
|
53
53
|
"decamelize": "^6.0.1",
|
|
54
|
-
"eslint": "10.
|
|
54
|
+
"eslint": "10.10.0",
|
|
55
55
|
"eslint-config-canonical": "^47.4.2",
|
|
56
56
|
"gitdown": "^4.1.1",
|
|
57
57
|
"glob": "^13.0.6",
|
|
@@ -60,10 +60,10 @@
|
|
|
60
60
|
"jsdoc-type-pratt-parser": "^9.2.1",
|
|
61
61
|
"json-schema": "^0.4.0",
|
|
62
62
|
"json-schema-to-typescript": "^16.0.0",
|
|
63
|
-
"lint-staged": "^17.
|
|
63
|
+
"lint-staged": "^17.5.0",
|
|
64
64
|
"mocha": "^12.0.0",
|
|
65
65
|
"open-editor": "^6.0.0",
|
|
66
|
-
"playwright": "^1.
|
|
66
|
+
"playwright": "^1.63.0",
|
|
67
67
|
"replace": "^1.2.2",
|
|
68
68
|
"rimraf": "^6.1.3",
|
|
69
69
|
"semantic-release": "^25.0.9",
|
|
@@ -157,5 +157,5 @@
|
|
|
157
157
|
"test-cov": "TIMING=1 c8 --reporter text pnpm run test-no-cov",
|
|
158
158
|
"test-index": "pnpm run test-no-cov test/rules/index.js"
|
|
159
159
|
},
|
|
160
|
-
"version": "64.3.
|
|
160
|
+
"version": "64.3.7"
|
|
161
161
|
}
|
|
@@ -482,8 +482,10 @@ export default iterateJsdoc(({
|
|
|
482
482
|
.concat(tsModuleVariables)
|
|
483
483
|
.concat(/** @type {string[]} */ (definedPreferredTypes))
|
|
484
484
|
.concat((() => {
|
|
485
|
-
// Other
|
|
486
|
-
|
|
485
|
+
// Other class members are not in scope, but we need them (e.g., for a
|
|
486
|
+
// sibling property or method referenced by `{@link}`), and we grab
|
|
487
|
+
// them here
|
|
488
|
+
if (node?.type === 'MethodDefinition' || node?.type === 'PropertyDefinition') {
|
|
487
489
|
return /** @type {import('estree').ClassBody} */ (node.parent).body.flatMap((methodOrProp) => {
|
|
488
490
|
if (methodOrProp.type === 'MethodDefinition') {
|
|
489
491
|
// eslint-disable-next-line unicorn/no-lonely-if -- Pattern
|
|
@@ -363,6 +363,51 @@ export default iterateJsdoc(({
|
|
|
363
363
|
checker.isTupleType(assertedType);
|
|
364
364
|
};
|
|
365
365
|
|
|
366
|
+
/**
|
|
367
|
+
* An array-literal annotation whose element type is a literal (or union of
|
|
368
|
+
* literals) — `type {ViewType[]}` on `['single-panel', 'user']` —
|
|
369
|
+
* narrows the element type that the bare literal would widen (`string[]` ->
|
|
370
|
+
* `ViewType[]`). Like the tuple idiom, the literal takes that element type
|
|
371
|
+
* only *from* the annotation, so the contextually-typed initializer echoes
|
|
372
|
+
* the asserted array straight back and the genuine narrowing looks redundant.
|
|
373
|
+
* @param {any} assertedType `ts.Type`
|
|
374
|
+
* @param {import('@typescript-eslint/utils').TSESTree.Node | null | undefined} operand
|
|
375
|
+
* @returns {boolean}
|
|
376
|
+
*/
|
|
377
|
+
const narrowsArrayLiteralElement = (assertedType, operand) => {
|
|
378
|
+
if (operand?.type !== 'ArrayExpression' || !checker.isArrayType(assertedType)) {
|
|
379
|
+
return false;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
const [
|
|
383
|
+
elementType,
|
|
384
|
+
] = checker.getTypeArguments(assertedType);
|
|
385
|
+
return isLiteralType(elementType);
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Whether `operand` is an object literal carrying a method or function-valued
|
|
390
|
+
* property. Under a surrounding `@type` object annotation such a function is
|
|
391
|
+
* contextually typed by the annotation — its otherwise-implicit-`any`
|
|
392
|
+
* parameters (and hence its signature) come straight from it — so
|
|
393
|
+
* `getTypeAtLocation` echoes the asserted object shape back and a genuine
|
|
394
|
+
* typing looks redundant. As elsewhere in this rule the uncontaminated type
|
|
395
|
+
* cannot be recovered here, so such literals are left alone (at the cost of
|
|
396
|
+
* missing the rare object annotation that only restates a fully
|
|
397
|
+
* self-evident method signature).
|
|
398
|
+
* @param {import('@typescript-eslint/utils').TSESTree.Node | null | undefined} operand
|
|
399
|
+
* @returns {boolean}
|
|
400
|
+
*/
|
|
401
|
+
const hasContextuallyTypedFunctionMember = (operand) => {
|
|
402
|
+
return operand?.type === 'ObjectExpression' &&
|
|
403
|
+
operand.properties.some((property) => {
|
|
404
|
+
return property.type === 'Property' && (
|
|
405
|
+
property.value.type === 'FunctionExpression' ||
|
|
406
|
+
property.value.type === 'ArrowFunctionExpression'
|
|
407
|
+
);
|
|
408
|
+
});
|
|
409
|
+
};
|
|
410
|
+
|
|
366
411
|
/**
|
|
367
412
|
* Whether every element of `tupleType` is a literal type, so a `const`
|
|
368
413
|
* assertion would reproduce the same element types (`['foo', 1]` but not
|
|
@@ -445,6 +490,13 @@ export default iterateJsdoc(({
|
|
|
445
490
|
return;
|
|
446
491
|
}
|
|
447
492
|
|
|
493
|
+
if (
|
|
494
|
+
narrowsArrayLiteralElement(declAssertedType, decl.init) ||
|
|
495
|
+
hasContextuallyTypedFunctionMember(decl.init)
|
|
496
|
+
) {
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
|
|
448
500
|
if (isRedundantAssertion(declInferredType, declAssertedType)) {
|
|
449
501
|
utils.reportJSDoc(message, types[0], fixer, true, {
|
|
450
502
|
type: assertedTypeStr,
|
|
@@ -522,6 +574,13 @@ export default iterateJsdoc(({
|
|
|
522
574
|
return;
|
|
523
575
|
}
|
|
524
576
|
|
|
577
|
+
if (
|
|
578
|
+
narrowsArrayLiteralElement(castAssertedType, node) ||
|
|
579
|
+
hasContextuallyTypedFunctionMember(node)
|
|
580
|
+
) {
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
|
|
525
584
|
if (!isRedundantAssertion(castInferredType, castAssertedType)) {
|
|
526
585
|
return;
|
|
527
586
|
}
|