Skip to content

enable @typescript-eslint/no-unused-vars #57123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f63fde8
enable no-unused-vars
abrahamguo Jan 22, 2024
2b30e24
format
abrahamguo Jan 22, 2024
141e474
correct lockfile
abrahamguo Jan 22, 2024
1dfaf68
revert lockfile
abrahamguo Jan 22, 2024
ba1df11
revert package.json
abrahamguo Jan 22, 2024
f937aae
new ignorepatterns
abrahamguo Jan 22, 2024
6480177
tweaks
abrahamguo Jan 22, 2024
dbea78b
dumb mistake
abrahamguo Jan 22, 2024
4b48354
Merge branch 'main' of github.com:abrahamguo/TypeScript into no-unuse…
abrahamguo Jan 23, 2024
a083d48
suppress
abrahamguo Jan 23, 2024
4cd2960
Merge branch 'main' of github.com:abrahamguo/TypeScript into no-unuse…
abrahamguo Jan 25, 2024
3c9cd1d
remove unused type params
abrahamguo Jan 25, 2024
a963787
Merge branch 'main' of github.com:abrahamguo/TypeScript into no-unuse…
abrahamguo Jan 27, 2024
d67a4f6
remove nounused from tsconfigs
abrahamguo Jan 27, 2024
1101dca
remove allowunusedlabels
abrahamguo Jan 27, 2024
c44c704
more readable regex
abrahamguo Jan 27, 2024
0d12055
Merge branch 'main' of github.com:abrahamguo/TypeScript into no-unuse…
abrahamguo Jan 28, 2024
778b343
switch to jsdoc imports
abrahamguo Jan 28, 2024
d1ba2ce
Merge branch 'main' of github.com:abrahamguo/TypeScript into no-unuse…
abrahamguo Jan 28, 2024
efda314
restore SetAccessorDeclaration import
abrahamguo Jan 28, 2024
1185e6b
improve comment
abrahamguo Jan 28, 2024
c524b68
Merge branch 'main' of github.com:abrahamguo/TypeScript into no-unuse…
abrahamguo Jan 29, 2024
0f15b4e
inline nonunion typedefs
abrahamguo Jan 29, 2024
e9e939c
declaration merging
abrahamguo Jan 29, 2024
121a1db
add explicit return type
abrahamguo Jan 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,14 @@
}
}
],

// Todo: For each of these, investigate whether we want to enable them ✨
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
// Ignore: (solely underscores | starting with exactly one underscore)
"argsIgnorePattern": "^(_+$|_[^_])",
"varsIgnorePattern": "^(_+$|_[^_])"
}
],

// Pending https://github.com/typescript-eslint/typescript-eslint/issues/4820
"@typescript-eslint/prefer-optional-chain": "off",
Expand Down
16 changes: 10 additions & 6 deletions scripts/eslint/rules/argument-trivia.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
const { AST_NODE_TYPES, TSESTree, ESLintUtils } = require("@typescript-eslint/utils");
const { AST_NODE_TYPES, ESLintUtils } = require("@typescript-eslint/utils");
const { createRule } = require("./utils.cjs");
const ts = require("typescript");

/**
* @typedef {import("@typescript-eslint/utils").TSESTree.CallExpression | import("@typescript-eslint/utils").TSESTree.NewExpression} CallOrNewExpression
*/

const unset = Symbol();
/**
* @template T
Expand Down Expand Up @@ -42,7 +46,7 @@ module.exports = createRule({

/** @type {(name: string) => boolean} */
const isSetOrAssert = name => name.startsWith("set") || name.startsWith("assert");
/** @type {(node: TSESTree.Node) => boolean} */
/** @type {(node: import("@typescript-eslint/utils").TSESTree.Node) => boolean} */
const isTrivia = node => {
if (node.type === AST_NODE_TYPES.Identifier) {
return node.name === "undefined";
Expand All @@ -56,7 +60,7 @@ module.exports = createRule({
return false;
};

/** @type {(node: TSESTree.CallExpression | TSESTree.NewExpression) => boolean} */
/** @type {(node: CallOrNewExpression) => boolean} */
const shouldIgnoreCalledExpression = node => {
if (node.callee && node.callee.type === AST_NODE_TYPES.MemberExpression) {
const methodName = node.callee.property.type === AST_NODE_TYPES.Identifier
Expand Down Expand Up @@ -97,7 +101,7 @@ module.exports = createRule({
return false;
};

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

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

if (!comment || comment.type !== "Block") {
Expand Down Expand Up @@ -170,7 +174,7 @@ module.exports = createRule({
}
};

/** @type {(node: TSESTree.CallExpression | TSESTree.NewExpression) => void} */
/** @type {(node: CallOrNewExpression) => void} */
const checkArgumentTrivia = node => {
if (shouldIgnoreCalledExpression(node)) {
return;
Expand Down
10 changes: 5 additions & 5 deletions scripts/eslint/rules/debug-assert.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { AST_NODE_TYPES, TSESTree } = require("@typescript-eslint/utils");
const { AST_NODE_TYPES } = require("@typescript-eslint/utils");
const { createRule } = require("./utils.cjs");

module.exports = createRule({
Expand All @@ -17,22 +17,22 @@ module.exports = createRule({
defaultOptions: [],

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

/** @type {(node: TSESTree.MemberExpression) => boolean} */
/** @type {(node: import("@typescript-eslint/utils").TSESTree.MemberExpression) => boolean} */
const isDebugAssert = node => (
node.object.type === AST_NODE_TYPES.Identifier
&& node.object.name === "Debug"
&& node.property.type === AST_NODE_TYPES.Identifier
&& node.property.name === "assert"
);

/** @type {(node: TSESTree.CallExpression) => void} */
/** @type {(node: import("@typescript-eslint/utils").TSESTree.CallExpression) => void} */
const checkDebugAssert = node => {
const args = node.arguments;
const argsLen = args.length;
Expand Down
7 changes: 3 additions & 4 deletions scripts/eslint/rules/jsdoc-format.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const { TSESTree } = require("@typescript-eslint/utils");
const { createRule } = require("./utils.cjs");

module.exports = createRule({
Expand Down Expand Up @@ -29,7 +28,7 @@ module.exports = createRule({
return text.startsWith(jsdocStart);
}

/** @type {(c: TSESTree.Comment, indexInComment: number) => TSESTree.SourceLocation} */
/** @type {(c: import("@typescript-eslint/utils").TSESTree.Comment, indexInComment: number) => import("@typescript-eslint/utils").TSESTree.SourceLocation} */
const getAtInternalLoc = (c, indexInComment) => {
const line = c.loc.start.line;
return {
Expand All @@ -44,7 +43,7 @@ module.exports = createRule({
};
};

/** @type {(c: TSESTree.Comment) => TSESTree.SourceLocation} */
/** @type {(c: import("@typescript-eslint/utils").TSESTree.Comment) => import("@typescript-eslint/utils").TSESTree.SourceLocation} */
const getJSDocStartLoc = c => {
return {
start: c.loc.start,
Expand All @@ -55,7 +54,7 @@ module.exports = createRule({
};
};

/** @type {(node: TSESTree.Node) => void} */
/** @type {(node: import("@typescript-eslint/utils").TSESTree.Node) => void} */
const checkDeclaration = node => {
const blockComments = sourceCode.getCommentsBefore(node).filter(c => c.type === "Block");
if (blockComments.length === 0) {
Expand Down
3 changes: 1 addition & 2 deletions scripts/eslint/rules/no-in-operator.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const { TSESTree } = require("@typescript-eslint/utils");
const { createRule } = require("./utils.cjs");

module.exports = createRule({
Expand All @@ -17,7 +16,7 @@ module.exports = createRule({

create(context) {
const IN_OPERATOR = "in";
/** @type {(node: TSESTree.BinaryExpression) => void} */
/** @type {(node: import("@typescript-eslint/utils").TSESTree.BinaryExpression) => void} */
const checkInOperator = node => {
if (node.operator === IN_OPERATOR) {
context.report({ messageId: "noInOperatorError", node });
Expand Down
10 changes: 5 additions & 5 deletions scripts/eslint/rules/no-keywords.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { TSESTree, AST_NODE_TYPES } = require("@typescript-eslint/utils");
const { AST_NODE_TYPES } = require("@typescript-eslint/utils");
const { createRule } = require("./utils.cjs");

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

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

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

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

/** @type {(node: TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration | TSESTree.FunctionExpression | TSESTree.TSMethodSignature | TSESTree.TSFunctionType) => void} */
/** @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} */
const checkParams = node => {
if (!node || !node.params || !node.params.length) {
return;
Expand Down
10 changes: 6 additions & 4 deletions scripts/eslint/rules/only-arrow-functions.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const { AST_NODE_TYPES, TSESTree } = require("@typescript-eslint/utils");
const { AST_NODE_TYPES } = require("@typescript-eslint/utils");
const { createRule } = require("./utils.cjs");

/** @typedef {import("@typescript-eslint/utils").TSESTree.FunctionDeclaration | import("@typescript-eslint/utils").TSESTree.FunctionExpression} FunctionDeclarationOrExpression */

module.exports = createRule({
name: "only-arrow-functions",
meta: {
Expand All @@ -27,10 +29,10 @@ module.exports = createRule({
}],

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

/** @type {(node: TSESTree.Node) => boolean} */
/** @type {(node: import("@typescript-eslint/utils").TSESTree.Node) => boolean} */
const isMethodType = node => {
const types = [
AST_NODE_TYPES.MethodDefinition,
Expand All @@ -57,7 +59,7 @@ module.exports = createRule({
}
};

/** @type {(node: TSESTree.FunctionDeclaration | TSESTree.FunctionExpression) => void} */
/** @type {(node: FunctionDeclarationOrExpression) => void} */
const exitFunction = node => {
const methodUsesThis = stack.pop();

Expand Down
3 changes: 0 additions & 3 deletions scripts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@
"strict": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"allowUnusedLabels": false,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"allowJs": true,
"checkJs": true
},
Expand Down
7 changes: 3 additions & 4 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
__String,
CharacterCodes,
Comparer,
Comparison,
Expand Down Expand Up @@ -286,15 +285,15 @@ export function filter<T>(array: T[], f: (x: T) => boolean): T[];
/** @internal */
export function filter<T, U extends T>(array: readonly T[], f: (x: T) => x is U): readonly U[];
/** @internal */
export function filter<T, U extends T>(array: readonly T[], f: (x: T) => boolean): readonly T[];
export function filter<T>(array: readonly T[], f: (x: T) => boolean): readonly T[];
/** @internal */
export function filter<T, U extends T>(array: T[] | undefined, f: (x: T) => x is U): U[] | undefined;
/** @internal */
export function filter<T>(array: T[] | undefined, f: (x: T) => boolean): T[] | undefined;
/** @internal */
export function filter<T, U extends T>(array: readonly T[] | undefined, f: (x: T) => x is U): readonly U[] | undefined;
/** @internal */
export function filter<T, U extends T>(array: readonly T[] | undefined, f: (x: T) => boolean): readonly T[] | undefined;
export function filter<T>(array: readonly T[] | undefined, f: (x: T) => boolean): readonly T[] | undefined;
/** @internal */
export function filter<T>(array: readonly T[] | undefined, f: (x: T) => boolean): readonly T[] | undefined {
if (array) {
Expand Down Expand Up @@ -830,7 +829,7 @@ export function insertSorted<T>(array: SortedArray<T>, insert: T, compare: Compa
}

/** @internal */
export function sortAndDeduplicate<T>(array: readonly string[]): SortedReadonlyArray<string>;
export function sortAndDeduplicate(array: readonly string[]): SortedReadonlyArray<string>;
/** @internal */
export function sortAndDeduplicate<T>(array: readonly T[], comparer: Comparer<T>, equalityComparer?: EqualityComparer<T>): SortedReadonlyArray<T>;
/** @internal */
Expand Down
1 change: 1 addition & 0 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4131,6 +4131,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
writeSpace();
nextPos = emitTokenWithComment(SyntaxKind.AsKeyword, nextPos, writeKeyword, node);
writeSpace();
// eslint-disable-next-line @typescript-eslint/no-unused-vars
nextPos = emitTokenWithComment(SyntaxKind.NamespaceKeyword, nextPos, writeKeyword, node);
writeSpace();
emit(node.name);
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/factory/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1675,7 +1675,7 @@ export function createAccessorPropertyGetRedirector(factory: NodeFactory, node:
*
* @internal
*/
export function createAccessorPropertySetRedirector(factory: NodeFactory, node: PropertyDeclaration, modifiers: readonly Modifier[] | undefined, name: PropertyName, receiver: Expression = factory.createThis()) {
export function createAccessorPropertySetRedirector(factory: NodeFactory, node: PropertyDeclaration, modifiers: readonly Modifier[] | undefined, name: PropertyName, receiver: Expression = factory.createThis()): SetAccessorDeclaration {
return factory.createSetAccessorDeclaration(
modifiers,
name,
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/moduleNameResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ interface PackageJson extends PackageJsonPathFields {
version?: string;
}

function readPackageJsonField<TMatch, K extends MatchingKeys<PackageJson, string | undefined>>(jsonContent: PackageJson, fieldName: K, typeOfTag: "string", state: ModuleResolutionState): PackageJson[K] | undefined;
function readPackageJsonField<K extends MatchingKeys<PackageJson, string | undefined>>(jsonContent: PackageJson, fieldName: K, typeOfTag: "string", state: ModuleResolutionState): PackageJson[K] | undefined;
function readPackageJsonField<K extends MatchingKeys<PackageJson, object | undefined>>(jsonContent: PackageJson, fieldName: K, typeOfTag: "object", state: ModuleResolutionState): PackageJson[K] | undefined;
function readPackageJsonField<K extends keyof PackageJson>(jsonContent: PackageJson, fieldName: K, typeOfTag: "string" | "object", state: ModuleResolutionState): PackageJson[K] | undefined {
if (!hasProperty(jsonContent, fieldName)) {
Expand Down
14 changes: 7 additions & 7 deletions src/compiler/watchPublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,18 +258,18 @@ export interface ProgramHost<T extends BuilderProgram> {
getModuleResolutionCache?(): ModuleResolutionCache | undefined;

jsDocParsingMode?: JSDocParsingMode;
}
/**
* Internal interface used to wire emit through same host
*
* @internal
*/
export interface ProgramHost<T extends BuilderProgram> {

// Internal interface used to wire emit through same host

// TODO: GH#18217 Optional methods are frequently asserted
/** @internal */
createDirectory?(path: string): void;
/** @internal */
writeFile?(path: string, data: string, writeByteOrderMark?: boolean): void;
// For testing
/** @internal */
storeFilesChangingSignatureDuringEmit?: boolean;
/** @internal */
now?(): Date;
}

Expand Down
2 changes: 1 addition & 1 deletion src/server/editorServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ export function convertScriptKindName(scriptKindName: protocol.ScriptKindName) {

/** @internal */
export function convertUserPreferences(preferences: protocol.UserPreferences): UserPreferences {
const { lazyConfiguredProjectsFromExternalProject, ...userPreferences } = preferences;
const { lazyConfiguredProjectsFromExternalProject: _, ...userPreferences } = preferences;
return userPreferences;
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/codefixes/fixAddMissingConstraint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function addMissingConstraint(changes: textChanges.ChangeTracker, program: Progr
}

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

Expand Down
2 changes: 1 addition & 1 deletion src/services/codefixes/fixNaNEquality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, ar
}

function getSuggestion(messageText: string | DiagnosticMessageChain) {
const [_, suggestion] = flattenDiagnosticMessageText(messageText, "\n", 0).match(/'(.*)'/) || [];
const [, suggestion] = flattenDiagnosticMessageText(messageText, "\n", 0).match(/'(.*)'/) || [];
return suggestion;
}
1 change: 0 additions & 1 deletion src/services/refactors/moveToFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
getModuleSpecifier,
} from "../../compiler/moduleSpecifiers";
import {
__String,
AnyImportOrRequireStatement,
append,
ApplicableRefactorInfo,
Expand Down
4 changes: 0 additions & 4 deletions src/tsconfig-base.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
"useUnknownInCatchVariables": false,
"noImplicitOverride": true,

"noUnusedLocals": true,
"noUnusedParameters": true,
"allowUnusedLabels": false,

"skipLibCheck": true,

"alwaysStrict": true,
Expand Down