@typescript-eslint/eslint-plugin 8.25.1-alpha.17 → 8.25.1-alpha.18
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.
@@ -2,6 +2,7 @@ export type MessageIds = 'omittingRestParameter' | 'omittingSingleParameter' | '
|
|
2
2
|
export type Options = [
|
3
3
|
{
|
4
4
|
ignoreDifferentlyNamedParameters?: boolean;
|
5
|
+
ignoreOverloadsWithDifferentJSDoc?: boolean;
|
5
6
|
}
|
6
7
|
];
|
7
8
|
declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<MessageIds, Options, import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"unified-signatures.d.ts","sourceRoot":"","sources":["../../src/rules/unified-signatures.ts"],"names":[],"mappings":"AAuDA,MAAM,MAAM,UAAU,GAClB,uBAAuB,GACvB,yBAAyB,GACzB,2BAA2B,CAAC;AAEhC,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,gCAAgC,CAAC,EAAE,OAAO,CAAC;
|
1
|
+
{"version":3,"file":"unified-signatures.d.ts","sourceRoot":"","sources":["../../src/rules/unified-signatures.ts"],"names":[],"mappings":"AAuDA,MAAM,MAAM,UAAU,GAClB,uBAAuB,GACvB,yBAAyB,GACzB,2BAA2B,CAAC;AAEhC,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,gCAAgC,CAAC,EAAE,OAAO,CAAC;QAC3C,iCAAiC,CAAC,EAAE,OAAO,CAAC;KAC7C;CACF,CAAC;;AAEF,wBAyiBG"}
|
@@ -25,6 +25,10 @@ exports.default = (0, util_1.createRule)({
|
|
25
25
|
type: 'boolean',
|
26
26
|
description: 'Whether two parameters with different names at the same index should be considered different even if their types are the same.',
|
27
27
|
},
|
28
|
+
ignoreOverloadsWithDifferentJSDoc: {
|
29
|
+
type: 'boolean',
|
30
|
+
description: 'Whether two overloads with different JSDoc comments should be considered different even if their parameter and return types are the same.',
|
31
|
+
},
|
28
32
|
},
|
29
33
|
},
|
30
34
|
],
|
@@ -32,9 +36,10 @@ exports.default = (0, util_1.createRule)({
|
|
32
36
|
defaultOptions: [
|
33
37
|
{
|
34
38
|
ignoreDifferentlyNamedParameters: false,
|
39
|
+
ignoreOverloadsWithDifferentJSDoc: false,
|
35
40
|
},
|
36
41
|
],
|
37
|
-
create(context, [{ ignoreDifferentlyNamedParameters }]) {
|
42
|
+
create(context, [{ ignoreDifferentlyNamedParameters, ignoreOverloadsWithDifferentJSDoc }]) {
|
38
43
|
//----------------------------------------------------------------------
|
39
44
|
// Helpers
|
40
45
|
//----------------------------------------------------------------------
|
@@ -126,6 +131,13 @@ exports.default = (0, util_1.createRule)({
|
|
126
131
|
}
|
127
132
|
}
|
128
133
|
}
|
134
|
+
if (ignoreOverloadsWithDifferentJSDoc) {
|
135
|
+
const aComment = getBlockCommentForNode(getExportingNode(a) ?? a);
|
136
|
+
const bComment = getBlockCommentForNode(getExportingNode(b) ?? b);
|
137
|
+
if (aComment?.value !== bComment?.value) {
|
138
|
+
return false;
|
139
|
+
}
|
140
|
+
}
|
129
141
|
return (typesAreEqual(a.returnType, b.returnType) &&
|
130
142
|
// Must take the same type parameters.
|
131
143
|
// If one uses a type parameter (from outside) and the other doesn't, they shouldn't be joined.
|
@@ -306,6 +318,15 @@ exports.default = (0, util_1.createRule)({
|
|
306
318
|
addFailures(failures);
|
307
319
|
currentScope = scopes.pop();
|
308
320
|
}
|
321
|
+
/**
|
322
|
+
* @returns the first valid JSDoc comment annotating `node`
|
323
|
+
*/
|
324
|
+
function getBlockCommentForNode(node) {
|
325
|
+
return context.sourceCode
|
326
|
+
.getCommentsBefore(node)
|
327
|
+
.reverse()
|
328
|
+
.find(comment => comment.type === utils_1.AST_TOKEN_TYPES.Block);
|
329
|
+
}
|
309
330
|
function addOverload(signature, key, containingNode) {
|
310
331
|
key ??= getOverloadKey(signature);
|
311
332
|
if (currentScope &&
|
@@ -78,6 +78,50 @@ function f(b: string): void;
|
|
78
78
|
</TabItem>
|
79
79
|
</Tabs>
|
80
80
|
|
81
|
+
### `ignoreOverloadsWithDifferentJSDoc`
|
82
|
+
|
83
|
+
{/* insert option description */}
|
84
|
+
|
85
|
+
Examples of code for this rule with `ignoreOverloadsWithDifferentJSDoc`:
|
86
|
+
|
87
|
+
<Tabs>
|
88
|
+
<TabItem value="❌ Incorrect">
|
89
|
+
|
90
|
+
```ts option='{ "ignoreOverloadsWithDifferentJSDoc": true }'
|
91
|
+
declare function f(x: string): void;
|
92
|
+
declare function f(x: boolean): void;
|
93
|
+
/**
|
94
|
+
* @deprecate
|
95
|
+
*/
|
96
|
+
declare function f(x: number): void;
|
97
|
+
/**
|
98
|
+
* @deprecate
|
99
|
+
*/
|
100
|
+
declare function f(x: null): void;
|
101
|
+
```
|
102
|
+
|
103
|
+
</TabItem>
|
104
|
+
<TabItem value="✅ Correct">
|
105
|
+
|
106
|
+
```ts option='{ "ignoreOverloadsWithDifferentJSDoc": true }'
|
107
|
+
declare function f(x: string): void;
|
108
|
+
/**
|
109
|
+
* This signature does something else.
|
110
|
+
*/
|
111
|
+
declare function f(x: boolean): void;
|
112
|
+
/**
|
113
|
+
* @async
|
114
|
+
*/
|
115
|
+
declare function f(x: number): void;
|
116
|
+
/**
|
117
|
+
* @deprecate
|
118
|
+
*/
|
119
|
+
declare function f(x: null): void;
|
120
|
+
```
|
121
|
+
|
122
|
+
</TabItem>
|
123
|
+
</Tabs>
|
124
|
+
|
81
125
|
## When Not To Use It
|
82
126
|
|
83
127
|
This is purely a stylistic rule to help with readability of function signature overloads.
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@typescript-eslint/eslint-plugin",
|
3
|
-
"version": "8.25.1-alpha.
|
3
|
+
"version": "8.25.1-alpha.18",
|
4
4
|
"description": "TypeScript plugin for ESLint",
|
5
5
|
"files": [
|
6
6
|
"dist",
|
@@ -62,10 +62,10 @@
|
|
62
62
|
},
|
63
63
|
"dependencies": {
|
64
64
|
"@eslint-community/regexpp": "^4.10.0",
|
65
|
-
"@typescript-eslint/scope-manager": "8.25.1-alpha.
|
66
|
-
"@typescript-eslint/type-utils": "8.25.1-alpha.
|
67
|
-
"@typescript-eslint/utils": "8.25.1-alpha.
|
68
|
-
"@typescript-eslint/visitor-keys": "8.25.1-alpha.
|
65
|
+
"@typescript-eslint/scope-manager": "8.25.1-alpha.18",
|
66
|
+
"@typescript-eslint/type-utils": "8.25.1-alpha.18",
|
67
|
+
"@typescript-eslint/utils": "8.25.1-alpha.18",
|
68
|
+
"@typescript-eslint/visitor-keys": "8.25.1-alpha.18",
|
69
69
|
"graphemer": "^1.4.0",
|
70
70
|
"ignore": "^5.3.1",
|
71
71
|
"natural-compare": "^1.4.0",
|
@@ -76,8 +76,8 @@
|
|
76
76
|
"@types/marked": "^5.0.2",
|
77
77
|
"@types/mdast": "^4.0.3",
|
78
78
|
"@types/natural-compare": "*",
|
79
|
-
"@typescript-eslint/rule-schema-to-typescript-types": "8.25.1-alpha.
|
80
|
-
"@typescript-eslint/rule-tester": "8.25.1-alpha.
|
79
|
+
"@typescript-eslint/rule-schema-to-typescript-types": "8.25.1-alpha.18",
|
80
|
+
"@typescript-eslint/rule-tester": "8.25.1-alpha.18",
|
81
81
|
"ajv": "^6.12.6",
|
82
82
|
"cross-env": "^7.0.3",
|
83
83
|
"cross-fetch": "*",
|