Skip to content

Commit 3c9aea3

Browse files
authored
enable @typescript-eslint/no-unused-vars (#57123)
1 parent 52ec1fe commit 3c9aea3

18 files changed

+54
-53
lines changed

.eslintrc.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,14 @@
105105
}
106106
}
107107
],
108-
109-
// Todo: For each of these, investigate whether we want to enable them ✨
110-
"@typescript-eslint/no-unused-vars": "off",
108+
"@typescript-eslint/no-unused-vars": [
109+
"error",
110+
{
111+
// Ignore: (solely underscores | starting with exactly one underscore)
112+
"argsIgnorePattern": "^(_+$|_[^_])",
113+
"varsIgnorePattern": "^(_+$|_[^_])"
114+
}
115+
],
111116

112117
// Pending https://github.com/typescript-eslint/typescript-eslint/issues/4820
113118
"@typescript-eslint/prefer-optional-chain": "off",

scripts/eslint/rules/argument-trivia.cjs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
const { AST_NODE_TYPES, TSESTree, ESLintUtils } = require("@typescript-eslint/utils");
1+
const { AST_NODE_TYPES, ESLintUtils } = require("@typescript-eslint/utils");
22
const { createRule } = require("./utils.cjs");
33
const ts = require("typescript");
44

5+
/**
6+
* @typedef {import("@typescript-eslint/utils").TSESTree.CallExpression | import("@typescript-eslint/utils").TSESTree.NewExpression} CallOrNewExpression
7+
*/
8+
59
const unset = Symbol();
610
/**
711
* @template T
@@ -42,7 +46,7 @@ module.exports = createRule({
4246

4347
/** @type {(name: string) => boolean} */
4448
const isSetOrAssert = name => name.startsWith("set") || name.startsWith("assert");
45-
/** @type {(node: TSESTree.Node) => boolean} */
49+
/** @type {(node: import("@typescript-eslint/utils").TSESTree.Node) => boolean} */
4650
const isTrivia = node => {
4751
if (node.type === AST_NODE_TYPES.Identifier) {
4852
return node.name === "undefined";
@@ -56,7 +60,7 @@ module.exports = createRule({
5660
return false;
5761
};
5862

59-
/** @type {(node: TSESTree.CallExpression | TSESTree.NewExpression) => boolean} */
63+
/** @type {(node: CallOrNewExpression) => boolean} */
6064
const shouldIgnoreCalledExpression = node => {
6165
if (node.callee && node.callee.type === AST_NODE_TYPES.MemberExpression) {
6266
const methodName = node.callee.property.type === AST_NODE_TYPES.Identifier
@@ -97,7 +101,7 @@ module.exports = createRule({
97101
return false;
98102
};
99103

100-
/** @type {(node: TSESTree.Node, i: number, getSignature: () => ts.Signature | undefined) => void} */
104+
/** @type {(node: import("@typescript-eslint/utils").TSESTree.Node, i: number, getSignature: () => ts.Signature | undefined) => void} */
101105
const checkArg = (node, i, getSignature) => {
102106
if (!isTrivia(node)) {
103107
return;
@@ -119,7 +123,7 @@ module.exports = createRule({
119123
});
120124

121125
const comments = sourceCode.getCommentsBefore(node);
122-
/** @type {TSESTree.Comment | undefined} */
126+
/** @type {import("@typescript-eslint/utils").TSESTree.Comment | undefined} */
123127
const comment = comments[comments.length - 1];
124128

125129
if (!comment || comment.type !== "Block") {
@@ -170,7 +174,7 @@ module.exports = createRule({
170174
}
171175
};
172176

173-
/** @type {(node: TSESTree.CallExpression | TSESTree.NewExpression) => void} */
177+
/** @type {(node: CallOrNewExpression) => void} */
174178
const checkArgumentTrivia = node => {
175179
if (shouldIgnoreCalledExpression(node)) {
176180
return;

scripts/eslint/rules/debug-assert.cjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { AST_NODE_TYPES, TSESTree } = require("@typescript-eslint/utils");
1+
const { AST_NODE_TYPES } = require("@typescript-eslint/utils");
22
const { createRule } = require("./utils.cjs");
33

44
module.exports = createRule({
@@ -17,22 +17,22 @@ module.exports = createRule({
1717
defaultOptions: [],
1818

1919
create(context) {
20-
/** @type {(node: TSESTree.Node) => boolean} */
20+
/** @type {(node: import("@typescript-eslint/utils").TSESTree.Node) => boolean} */
2121
const isArrowFunction = node => node.type === AST_NODE_TYPES.ArrowFunctionExpression;
22-
/** @type {(node: TSESTree.Node) => boolean} */
22+
/** @type {(node: import("@typescript-eslint/utils").TSESTree.Node) => boolean} */
2323
const isStringLiteral = node => (
2424
(node.type === AST_NODE_TYPES.Literal && typeof node.value === "string") || node.type === AST_NODE_TYPES.TemplateLiteral
2525
);
2626

27-
/** @type {(node: TSESTree.MemberExpression) => boolean} */
27+
/** @type {(node: import("@typescript-eslint/utils").TSESTree.MemberExpression) => boolean} */
2828
const isDebugAssert = node => (
2929
node.object.type === AST_NODE_TYPES.Identifier
3030
&& node.object.name === "Debug"
3131
&& node.property.type === AST_NODE_TYPES.Identifier
3232
&& node.property.name === "assert"
3333
);
3434

35-
/** @type {(node: TSESTree.CallExpression) => void} */
35+
/** @type {(node: import("@typescript-eslint/utils").TSESTree.CallExpression) => void} */
3636
const checkDebugAssert = node => {
3737
const args = node.arguments;
3838
const argsLen = args.length;

scripts/eslint/rules/jsdoc-format.cjs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const { TSESTree } = require("@typescript-eslint/utils");
21
const { createRule } = require("./utils.cjs");
32

43
module.exports = createRule({
@@ -29,7 +28,7 @@ module.exports = createRule({
2928
return text.startsWith(jsdocStart);
3029
}
3130

32-
/** @type {(c: TSESTree.Comment, indexInComment: number) => TSESTree.SourceLocation} */
31+
/** @type {(c: import("@typescript-eslint/utils").TSESTree.Comment, indexInComment: number) => import("@typescript-eslint/utils").TSESTree.SourceLocation} */
3332
const getAtInternalLoc = (c, indexInComment) => {
3433
const line = c.loc.start.line;
3534
return {
@@ -44,7 +43,7 @@ module.exports = createRule({
4443
};
4544
};
4645

47-
/** @type {(c: TSESTree.Comment) => TSESTree.SourceLocation} */
46+
/** @type {(c: import("@typescript-eslint/utils").TSESTree.Comment) => import("@typescript-eslint/utils").TSESTree.SourceLocation} */
4847
const getJSDocStartLoc = c => {
4948
return {
5049
start: c.loc.start,
@@ -55,7 +54,7 @@ module.exports = createRule({
5554
};
5655
};
5756

58-
/** @type {(node: TSESTree.Node) => void} */
57+
/** @type {(node: import("@typescript-eslint/utils").TSESTree.Node) => void} */
5958
const checkDeclaration = node => {
6059
const blockComments = sourceCode.getCommentsBefore(node).filter(c => c.type === "Block");
6160
if (blockComments.length === 0) {

scripts/eslint/rules/no-in-operator.cjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const { TSESTree } = require("@typescript-eslint/utils");
21
const { createRule } = require("./utils.cjs");
32

43
module.exports = createRule({
@@ -17,7 +16,7 @@ module.exports = createRule({
1716

1817
create(context) {
1918
const IN_OPERATOR = "in";
20-
/** @type {(node: TSESTree.BinaryExpression) => void} */
19+
/** @type {(node: import("@typescript-eslint/utils").TSESTree.BinaryExpression) => void} */
2120
const checkInOperator = node => {
2221
if (node.operator === IN_OPERATOR) {
2322
context.report({ messageId: "noInOperatorError", node });

scripts/eslint/rules/no-keywords.cjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { TSESTree, AST_NODE_TYPES } = require("@typescript-eslint/utils");
1+
const { AST_NODE_TYPES } = require("@typescript-eslint/utils");
22
const { createRule } = require("./utils.cjs");
33

44
module.exports = createRule({
@@ -37,12 +37,12 @@ module.exports = createRule({
3737
/** @type {(name: string) => boolean} */
3838
const isKeyword = name => keywords.includes(name);
3939

40-
/** @type {(node: TSESTree.Identifier) => void} */
40+
/** @type {(node: import("@typescript-eslint/utils").TSESTree.Identifier) => void} */
4141
const report = node => {
4242
context.report({ messageId: "noKeywordsError", data: { name: node.name }, node });
4343
};
4444

45-
/** @type {(node: TSESTree.ObjectPattern) => void} */
45+
/** @type {(node: import("@typescript-eslint/utils").TSESTree.ObjectPattern) => void} */
4646
const checkProperties = node => {
4747
node.properties.forEach(property => {
4848
if (
@@ -56,7 +56,7 @@ module.exports = createRule({
5656
});
5757
};
5858

59-
/** @type {(node: TSESTree.ArrayPattern) => void} */
59+
/** @type {(node: import("@typescript-eslint/utils").TSESTree.ArrayPattern) => void} */
6060
const checkElements = node => {
6161
node.elements.forEach(element => {
6262
if (
@@ -69,7 +69,7 @@ module.exports = createRule({
6969
});
7070
};
7171

72-
/** @type {(node: TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration | TSESTree.FunctionExpression | TSESTree.TSMethodSignature | TSESTree.TSFunctionType) => void} */
72+
/** @type {(node: import("@typescript-eslint/utils").TSESTree.ArrowFunctionExpression | import("@typescript-eslint/utils").TSESTree.FunctionDeclaration | import("@typescript-eslint/utils").TSESTree.FunctionExpression | import("@typescript-eslint/utils").TSESTree.TSMethodSignature | import("@typescript-eslint/utils").TSESTree.TSFunctionType) => void} */
7373
const checkParams = node => {
7474
if (!node || !node.params || !node.params.length) {
7575
return;

scripts/eslint/rules/only-arrow-functions.cjs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
const { AST_NODE_TYPES, TSESTree } = require("@typescript-eslint/utils");
1+
const { AST_NODE_TYPES } = require("@typescript-eslint/utils");
22
const { createRule } = require("./utils.cjs");
33

4+
/** @typedef {import("@typescript-eslint/utils").TSESTree.FunctionDeclaration | import("@typescript-eslint/utils").TSESTree.FunctionExpression} FunctionDeclarationOrExpression */
5+
46
module.exports = createRule({
57
name: "only-arrow-functions",
68
meta: {
@@ -27,10 +29,10 @@ module.exports = createRule({
2729
}],
2830

2931
create(context, [{ allowNamedFunctions, allowDeclarations }]) {
30-
/** @type {(node: TSESTree.FunctionDeclaration | TSESTree.FunctionExpression) => boolean} */
32+
/** @type {(node: FunctionDeclarationOrExpression) => boolean} */
3133
const isThisParameter = node => !!node.params.length && !!node.params.find(param => param.type === AST_NODE_TYPES.Identifier && param.name === "this");
3234

33-
/** @type {(node: TSESTree.Node) => boolean} */
35+
/** @type {(node: import("@typescript-eslint/utils").TSESTree.Node) => boolean} */
3436
const isMethodType = node => {
3537
const types = [
3638
AST_NODE_TYPES.MethodDefinition,
@@ -57,7 +59,7 @@ module.exports = createRule({
5759
}
5860
};
5961

60-
/** @type {(node: TSESTree.FunctionDeclaration | TSESTree.FunctionExpression) => void} */
62+
/** @type {(node: FunctionDeclarationOrExpression) => void} */
6163
const exitFunction = node => {
6264
const methodUsesThis = stack.pop();
6365

scripts/tsconfig.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@
1313
"strict": true,
1414
"skipLibCheck": true,
1515
"forceConsistentCasingInFileNames": true,
16-
"allowUnusedLabels": false,
1716
"noImplicitOverride": true,
1817
"noImplicitReturns": true,
19-
"noUnusedLocals": true,
20-
"noUnusedParameters": true,
2118
"allowJs": true,
2219
"checkJs": true
2320
},

src/compiler/core.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
__String,
32
CharacterCodes,
43
Comparer,
54
Comparison,
@@ -286,15 +285,15 @@ export function filter<T>(array: T[], f: (x: T) => boolean): T[];
286285
/** @internal */
287286
export function filter<T, U extends T>(array: readonly T[], f: (x: T) => x is U): readonly U[];
288287
/** @internal */
289-
export function filter<T, U extends T>(array: readonly T[], f: (x: T) => boolean): readonly T[];
288+
export function filter<T>(array: readonly T[], f: (x: T) => boolean): readonly T[];
290289
/** @internal */
291290
export function filter<T, U extends T>(array: T[] | undefined, f: (x: T) => x is U): U[] | undefined;
292291
/** @internal */
293292
export function filter<T>(array: T[] | undefined, f: (x: T) => boolean): T[] | undefined;
294293
/** @internal */
295294
export function filter<T, U extends T>(array: readonly T[] | undefined, f: (x: T) => x is U): readonly U[] | undefined;
296295
/** @internal */
297-
export function filter<T, U extends T>(array: readonly T[] | undefined, f: (x: T) => boolean): readonly T[] | undefined;
296+
export function filter<T>(array: readonly T[] | undefined, f: (x: T) => boolean): readonly T[] | undefined;
298297
/** @internal */
299298
export function filter<T>(array: readonly T[] | undefined, f: (x: T) => boolean): readonly T[] | undefined {
300299
if (array) {
@@ -830,7 +829,7 @@ export function insertSorted<T>(array: SortedArray<T>, insert: T, compare: Compa
830829
}
831830

832831
/** @internal */
833-
export function sortAndDeduplicate<T>(array: readonly string[]): SortedReadonlyArray<string>;
832+
export function sortAndDeduplicate(array: readonly string[]): SortedReadonlyArray<string>;
834833
/** @internal */
835834
export function sortAndDeduplicate<T>(array: readonly T[], comparer: Comparer<T>, equalityComparer?: EqualityComparer<T>): SortedReadonlyArray<T>;
836835
/** @internal */

src/compiler/emitter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4131,6 +4131,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
41314131
writeSpace();
41324132
nextPos = emitTokenWithComment(SyntaxKind.AsKeyword, nextPos, writeKeyword, node);
41334133
writeSpace();
4134+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
41344135
nextPos = emitTokenWithComment(SyntaxKind.NamespaceKeyword, nextPos, writeKeyword, node);
41354136
writeSpace();
41364137
emit(node.name);

0 commit comments

Comments
 (0)