Skip to content

Commit 3c9aea3

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

18 files changed

+54
-53
lines changed

.eslintrc.json

+8-3
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

+10-6
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

+5-5
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

+3-4
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

+1-2
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

+5-5
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

+6-4
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

-3
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

+3-4
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

+1
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);

src/compiler/factory/utilities.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1675,7 +1675,7 @@ export function createAccessorPropertyGetRedirector(factory: NodeFactory, node:
16751675
*
16761676
* @internal
16771677
*/
1678-
export function createAccessorPropertySetRedirector(factory: NodeFactory, node: PropertyDeclaration, modifiers: readonly Modifier[] | undefined, name: PropertyName, receiver: Expression = factory.createThis()) {
1678+
export function createAccessorPropertySetRedirector(factory: NodeFactory, node: PropertyDeclaration, modifiers: readonly Modifier[] | undefined, name: PropertyName, receiver: Expression = factory.createThis()): SetAccessorDeclaration {
16791679
return factory.createSetAccessorDeclaration(
16801680
modifiers,
16811681
name,

src/compiler/moduleNameResolver.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ interface PackageJson extends PackageJsonPathFields {
348348
version?: string;
349349
}
350350

351-
function readPackageJsonField<TMatch, K extends MatchingKeys<PackageJson, string | undefined>>(jsonContent: PackageJson, fieldName: K, typeOfTag: "string", state: ModuleResolutionState): PackageJson[K] | undefined;
351+
function readPackageJsonField<K extends MatchingKeys<PackageJson, string | undefined>>(jsonContent: PackageJson, fieldName: K, typeOfTag: "string", state: ModuleResolutionState): PackageJson[K] | undefined;
352352
function readPackageJsonField<K extends MatchingKeys<PackageJson, object | undefined>>(jsonContent: PackageJson, fieldName: K, typeOfTag: "object", state: ModuleResolutionState): PackageJson[K] | undefined;
353353
function readPackageJsonField<K extends keyof PackageJson>(jsonContent: PackageJson, fieldName: K, typeOfTag: "string" | "object", state: ModuleResolutionState): PackageJson[K] | undefined {
354354
if (!hasProperty(jsonContent, fieldName)) {

src/compiler/watchPublic.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -258,18 +258,18 @@ export interface ProgramHost<T extends BuilderProgram> {
258258
getModuleResolutionCache?(): ModuleResolutionCache | undefined;
259259

260260
jsDocParsingMode?: JSDocParsingMode;
261-
}
262-
/**
263-
* Internal interface used to wire emit through same host
264-
*
265-
* @internal
266-
*/
267-
export interface ProgramHost<T extends BuilderProgram> {
261+
262+
// Internal interface used to wire emit through same host
263+
268264
// TODO: GH#18217 Optional methods are frequently asserted
265+
/** @internal */
269266
createDirectory?(path: string): void;
267+
/** @internal */
270268
writeFile?(path: string, data: string, writeByteOrderMark?: boolean): void;
271269
// For testing
270+
/** @internal */
272271
storeFilesChangingSignatureDuringEmit?: boolean;
272+
/** @internal */
273273
now?(): Date;
274274
}
275275

src/server/editorServices.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ export function convertScriptKindName(scriptKindName: protocol.ScriptKindName) {
504504

505505
/** @internal */
506506
export function convertUserPreferences(preferences: protocol.UserPreferences): UserPreferences {
507-
const { lazyConfiguredProjectsFromExternalProject, ...userPreferences } = preferences;
507+
const { lazyConfiguredProjectsFromExternalProject: _, ...userPreferences } = preferences;
508508
return userPreferences;
509509
}
510510

src/services/codefixes/fixAddMissingConstraint.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function addMissingConstraint(changes: textChanges.ChangeTracker, program: Progr
132132
}
133133

134134
function tryGetConstraintFromDiagnosticMessage(messageText: string | DiagnosticMessageChain) {
135-
const [_, constraint] = flattenDiagnosticMessageText(messageText, "\n", 0).match(/`extends (.*)`/) || [];
135+
const [, constraint] = flattenDiagnosticMessageText(messageText, "\n", 0).match(/`extends (.*)`/) || [];
136136
return constraint;
137137
}
138138

src/services/codefixes/fixNaNEquality.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,6 @@ function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, ar
8787
}
8888

8989
function getSuggestion(messageText: string | DiagnosticMessageChain) {
90-
const [_, suggestion] = flattenDiagnosticMessageText(messageText, "\n", 0).match(/'(.*)'/) || [];
90+
const [, suggestion] = flattenDiagnosticMessageText(messageText, "\n", 0).match(/'(.*)'/) || [];
9191
return suggestion;
9292
}

src/services/refactors/moveToFile.ts

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
getModuleSpecifier,
33
} from "../../compiler/moduleSpecifiers";
44
import {
5-
__String,
65
AnyImportOrRequireStatement,
76
append,
87
ApplicableRefactorInfo,

src/tsconfig-base.json

-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
"useUnknownInCatchVariables": false,
2222
"noImplicitOverride": true,
2323

24-
"noUnusedLocals": true,
25-
"noUnusedParameters": true,
26-
"allowUnusedLabels": false,
27-
2824
"skipLibCheck": true,
2925

3026
"alwaysStrict": true,

0 commit comments

Comments
 (0)