Skip to content

Commit 4972ecd

Browse files
chore: enabled most of strict-type-checked internally (#7339)
* chore: enabled most of strict-type-checked internally * Update packages/eslint-plugin/src/util/getOperatorPrecedence.ts Co-authored-by: Brad Zacher <[email protected]> * Explicit DefinitionBase and other touchups --------- Co-authored-by: Brad Zacher <[email protected]>
1 parent 0eb86fd commit 4972ecd

31 files changed

+56
-55
lines changed

Diff for: .eslintrc.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ module.exports = {
2020
extends: [
2121
'eslint:recommended',
2222
'plugin:eslint-plugin/recommended',
23-
'plugin:@typescript-eslint/recommended-type-checked',
23+
'plugin:@typescript-eslint/strict-type-checked',
2424
'plugin:@typescript-eslint/stylistic-type-checked',
25-
// TODO: consider enabling strict-type-checked
2625
],
2726
parserOptions: {
2827
sourceType: 'module',
@@ -53,7 +52,10 @@ module.exports = {
5352
// make sure we're not leveraging any deprecated APIs
5453
'deprecation/deprecation': 'error',
5554

56-
// TODO(#7138): Investigate enabling these soon ✨
55+
// TODO(#7338): Investigate enabling these soon ✨
56+
'@typescript-eslint/consistent-indexed-object-style': 'off',
57+
'@typescript-eslint/no-unnecessary-condition': 'off',
58+
'@typescript-eslint/no-dynamic-delete': 'off',
5759
'@typescript-eslint/prefer-nullish-coalescing': 'off',
5860

5961
// TODO(#7130): Investigate changing these in or removing these from presets
@@ -85,6 +87,12 @@ module.exports = {
8587
'@typescript-eslint/no-explicit-any': 'error',
8688
'@typescript-eslint/no-non-null-assertion': 'off',
8789
'@typescript-eslint/no-var-requires': 'off',
90+
'@typescript-eslint/prefer-literal-enum-member': [
91+
'error',
92+
{
93+
allowBitwiseExpressions: true,
94+
},
95+
],
8896
'@typescript-eslint/unbound-method': 'off',
8997
'@typescript-eslint/restrict-template-expressions': [
9098
'error',

Diff for: packages/ast-spec/tests/ast-node-types.type-test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ type TakesString<T extends Record<string, string>> = T;
1212
type _Test =
1313
// forcing the test onto a new line so it isn't covered by the expect error
1414
// If there are any enum members that don't have a corresponding TSESTree.Node, then this line will error with "Type 'string | number | symbol' is not assignable to type 'string'."
15+
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
1516
TakesString<AllKeys> | void;

Diff for: packages/eslint-plugin/src/rules/default-param-last.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default createRule({
2424
* @private
2525
*/
2626
function isOptionalParam(node: TSESTree.Parameter): boolean {
27-
return 'optional' in node && node.optional === true;
27+
return 'optional' in node && node.optional;
2828
}
2929

3030
/**

Diff for: packages/eslint-plugin/src/rules/explicit-function-return-type.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export default createRule<Options, MessageIds>({
138138
case AST_NODE_TYPES.Property: {
139139
if (
140140
parent.key.type === AST_NODE_TYPES.Identifier &&
141-
parent.computed === false
141+
!parent.computed
142142
) {
143143
funcName = parent.key.name;
144144
}

Diff for: packages/eslint-plugin/src/rules/naming-convention-utils/enums.ts

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ enum Selectors {
5050
type SelectorsString = keyof typeof Selectors;
5151

5252
enum MetaSelectors {
53+
/* eslint-disable @typescript-eslint/prefer-literal-enum-member */
5354
default = -1,
5455
variableLike = 0 |
5556
Selectors.variable |
@@ -79,6 +80,7 @@ enum MetaSelectors {
7980
Selectors.classProperty |
8081
Selectors.objectLiteralProperty |
8182
Selectors.typeProperty,
83+
/* eslint-enable @typescript-eslint/prefer-literal-enum-member */
8284
}
8385
type MetaSelectorsString = keyof typeof MetaSelectors;
8486
type IndividualAndMetaSelectorsString = MetaSelectorsString | SelectorsString;

Diff for: packages/eslint-plugin/src/rules/naming-convention-utils/parse-options.ts

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ function parseOptions(context: Context): ParsedOptions {
8787
const result = getEnumNames(Selectors).reduce((acc, k) => {
8888
acc[k] = createValidator(k, context, normalizedOptions);
8989
return acc;
90+
// eslint-disable-next-line @typescript-eslint/prefer-reduce-type-parameter
9091
}, {} as ParsedOptions);
9192

9293
return result;

Diff for: packages/eslint-plugin/src/rules/no-empty-function.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export default createRule<Options, MessageIds>({
155155
isAllowedOverrideMethods &&
156156
isBodyEmpty(node) &&
157157
node.parent?.type === AST_NODE_TYPES.MethodDefinition &&
158-
node.parent.override === true
158+
node.parent.override
159159
);
160160
}
161161

Diff for: packages/eslint-plugin/src/rules/no-namespace.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@ export default createRule<Options, MessageIds>({
5252
const filename = context.getFilename();
5353

5454
function isDeclaration(node: TSESTree.Node): boolean {
55-
if (
56-
node.type === AST_NODE_TYPES.TSModuleDeclaration &&
57-
node.declare === true
58-
) {
55+
if (node.type === AST_NODE_TYPES.TSModuleDeclaration && node.declare) {
5956
return true;
6057
}
6158

Diff for: packages/eslint-plugin/src/rules/no-non-null-asserted-nullish-coalescing.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ function isDefinitionWithAssignment(definition: Definition): boolean {
2626
}
2727

2828
const variableDeclarator = definition.node;
29-
return (
30-
variableDeclarator.definite === true || variableDeclarator.init != null
31-
);
29+
return variableDeclarator.definite || variableDeclarator.init != null;
3230
}
3331

3432
export default createRule({

Diff for: packages/eslint-plugin/src/rules/no-redeclare.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ export default createRule<Options, MessageIds>({
7171
node?: TSESTree.Comment | TSESTree.Identifier;
7272
loc?: TSESTree.SourceLocation;
7373
},
74-
void,
75-
unknown
74+
void
7675
> {
7776
if (
7877
options?.builtinGlobals &&

Diff for: packages/eslint-plugin/src/rules/no-shadow.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ export default createRule<Options, MessageIds>({
284284
* @returns Whether or not the variable name is allowed.
285285
*/
286286
function isAllowed(variable: TSESLint.Scope.Variable): boolean {
287-
return options.allow!.indexOf(variable.name) !== -1;
287+
return options.allow!.includes(variable.name);
288288
}
289289

290290
/**

Diff for: packages/eslint-plugin/src/rules/no-unsafe-assignment.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export default createRule({
186186
}
187187

188188
let key: string;
189-
if (receiverProperty.computed === false) {
189+
if (!receiverProperty.computed) {
190190
key =
191191
receiverProperty.key.type === AST_NODE_TYPES.Identifier
192192
? receiverProperty.key.name

Diff for: packages/eslint-plugin/src/rules/prefer-regexp-exec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/prefer-literal-enum-member */
12
import type { TSESTree } from '@typescript-eslint/utils';
23
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
34
import * as tsutils from 'ts-api-utils';

Diff for: packages/eslint-plugin/src/util/collectUnusedVariables.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ class UnusedVarsVisitor<
323323

324324
protected TSModuleDeclaration(node: TSESTree.TSModuleDeclaration): void {
325325
// -- global augmentation can be in any file, and they do not need exports
326-
if (node.global === true) {
326+
if (node.global) {
327327
this.markVariableAsUsed('global', node.parent);
328328
}
329329
}

Diff for: packages/eslint-plugin/src/util/getOperatorPrecedence.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/prefer-literal-enum-member -- the enums come from TS so to make merging upstream easier we purposely avoid adding literal values. */
12
import type { TSESTree } from '@typescript-eslint/utils';
23
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
34
import { SyntaxKind } from 'typescript';

Diff for: packages/eslint-plugin/tools/generate-configs.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,8 @@ async function main(): Promise<void> {
7474
);
7575
const EXTENDS = ['./configs/base', './configs/eslint-recommended'];
7676

77-
type RuleEntry = [
78-
string,
79-
TSESLint.RuleModule<string, readonly unknown[], TSESLint.RuleListener>,
80-
];
77+
// TODO: migrate to import { RuleModule } from '@typescript-eslint/utils/ts-eslint'
78+
type RuleEntry = [string, TSESLint.RuleModule<string, readonly unknown[]>];
8179

8280
const allRuleEntries: RuleEntry[] = Object.entries(rules).sort((a, b) =>
8381
a[0].localeCompare(b[0]),

Diff for: packages/rule-tester/src/RuleTester.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ export class RuleTester extends TestFramework {
237237

238238
// convenience iterator to make it easy to loop all tests without a concat
239239
const allTestsIterator = {
240-
*[Symbol.iterator](): Generator<ValidTestCase<TOptions>, void, unknown> {
240+
*[Symbol.iterator](): Generator<ValidTestCase<TOptions>, void> {
241241
for (const testCase of normalizedTests.valid) {
242242
yield testCase;
243243
}

Diff for: packages/rule-tester/src/TestFramework.ts

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ let OVERRIDE_IT_SKIP: Maybe<RuleTesterTestFrameworkFunctionBase> = null;
5151
* allows the user to manually supply functions in case they want to roll their
5252
* own tooling
5353
*/
54+
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
5455
export abstract class TestFramework {
5556
/**
5657
* Runs a function after all the tests in this file have completed.

Diff for: packages/rule-tester/tests/RuleTester.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ beforeEach(() => {
119119
jest.clearAllMocks();
120120
});
121121

122-
const NOOP_RULE: RuleModule<'error', []> = {
122+
const NOOP_RULE: RuleModule<'error'> = {
123123
meta: {
124124
messages: {
125125
error: 'error',

Diff for: packages/scope-manager/src/definition/DefinitionBase.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ abstract class DefinitionBase<
99
TType extends DefinitionType,
1010
TNode extends TSESTree.Node,
1111
TParent extends TSESTree.Node | null,
12-
TName extends TSESTree.Node = TSESTree.BindingName,
12+
TName extends TSESTree.Node,
1313
> {
1414
/**
1515
* A unique ID for this instance - primarily used to help debugging and testing

Diff for: packages/scope-manager/tests/util/getSpecificNode.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
import type { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/types';
22
import { simpleTraverse } from '@typescript-eslint/typescript-estree';
33

4-
function getSpecificNode<
5-
TSelector extends AST_NODE_TYPES,
6-
TNode extends Extract<TSESTree.Node, { type: TSelector }>,
7-
>(ast: TSESTree.Node, selector: TSelector): TNode;
84
function getSpecificNode<
95
TSelector extends AST_NODE_TYPES,
106
TNode extends Extract<TSESTree.Node, { type: TSelector }>,
117
>(
128
ast: TSESTree.Node,
139
selector: TSelector,
14-
cb: (node: TNode) => boolean | null | undefined,
10+
cb?: (node: TNode) => boolean | null | undefined,
1511
): TNode;
1612
function getSpecificNode<
1713
TSelector extends AST_NODE_TYPES,

Diff for: packages/scope-manager/tests/util/serializers/DefinitionBase.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1+
import type { TSESTree } from '@typescript-eslint/types';
2+
13
import { DefinitionBase } from '../../../src/definition/DefinitionBase';
24
import { createSerializer } from './baseSerializer';
35

46
// hacking around the fact that you can't use abstract classes generically
5-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6-
class DefinitionInstance extends DefinitionBase<any, any, any> {
7+
class DefinitionInstance extends DefinitionBase<
8+
/* eslint-disable @typescript-eslint/no-explicit-any */
9+
any,
10+
any,
11+
any,
12+
/* eslint-enable @typescript-eslint/no-explicit-any */
13+
TSESTree.BindingName
14+
> {
715
isTypeDefinition = false;
816
isVariableDefinition = false;
917
}

Diff for: packages/typescript-estree/src/convert.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export class Converter {
198198
const isType =
199199
result.type === AST_NODE_TYPES.TSInterfaceDeclaration ||
200200
result.type === AST_NODE_TYPES.TSTypeAliasDeclaration;
201-
const isDeclare = 'declare' in result && result.declare === true;
201+
const isDeclare = 'declare' in result && result.declare;
202202
return this.createNode<TSESTree.ExportNamedDeclaration>(node, {
203203
type: AST_NODE_TYPES.ExportNamedDeclaration,
204204
// @ts-expect-error - TODO, narrow the types here

Diff for: packages/typescript-estree/src/parseSettings/ExpiringCache.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const DEFAULT_TSCONFIG_CACHE_DURATION_SECONDS = 30;
44
const ZERO_HR_TIME: [number, number] = [0, 0];
55

66
export interface CacheLike<Key, Value> {
7-
get(key: Key): Value | void;
7+
get(key: Key): Value | undefined;
88
set(key: Key, value: Value): this;
99
}
1010

Diff for: packages/typescript-estree/tests/lib/parse.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ describe('parseAndGenerateServices', () => {
362362
filePath: join(PROJECT_DIR, filePath),
363363
});
364364
} catch (error) {
365-
throw alignErrorPath(error as Error);
365+
alignErrorPath(error as Error);
366366
}
367367
};
368368

@@ -499,7 +499,7 @@ describe('parseAndGenerateServices', () => {
499499
filePath: join(PROJECT_DIR, filePath),
500500
});
501501
} catch (error) {
502-
throw alignErrorPath(error as Error);
502+
alignErrorPath(error as Error);
503503
}
504504
};
505505

Diff for: packages/utils/src/eslint-utils/getParserServices.ts

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
const ERROR_MESSAGE =
88
'You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser.';
99

10+
/* eslint-disable @typescript-eslint/unified-signatures */
1011
/**
1112
* Try to retrieve type-aware parser service from context.
1213
* This **_will_** throw if it is not available.
@@ -83,5 +84,6 @@ function getParserServices(
8384

8485
return context.parserServices;
8586
}
87+
/* eslint-enable @typescript-eslint/unified-signatures */
8688

8789
export { getParserServices };

Diff for: packages/utils/src/json-schema.ts

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export type JSONSchema4TypeExtended =
3333
| JSONSchema4Object;
3434

3535
// Workaround for infinite type recursion
36-
// eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style
3736
export interface JSONSchema4Object {
3837
[key: string]: JSONSchema4TypeExtended;
3938
}

Diff for: packages/utils/src/ts-eslint/SourceCode.ts

+4-16
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ declare class TokenStore {
186186
*/
187187
getTokensAfter<T extends SourceCode.CursorWithCountOptions>(
188188
node: TSESTree.Node | TSESTree.Token,
189-
options?: T,
189+
options?: T | number,
190190
): SourceCode.ReturnTypeFromOptions<T>[];
191191
/**
192192
* Gets the `count` tokens that precedes a given node or token.
@@ -196,31 +196,19 @@ declare class TokenStore {
196196
*/
197197
getTokensBefore<T extends SourceCode.CursorWithCountOptions>(
198198
node: TSESTree.Node | TSESTree.Token,
199-
options?: T,
200-
): SourceCode.ReturnTypeFromOptions<T>[];
201-
/**
202-
* Gets all of the tokens between two non-overlapping nodes.
203-
* @param left Node before the desired token range.
204-
* @param right Node after the desired token range.
205-
* @param options The option object. If this is a function then it's `options.filter`.
206-
* @returns Tokens between left and right.
207-
*/
208-
getTokensBetween<T extends SourceCode.CursorWithCountOptions>(
209-
left: TSESTree.Node | TSESTree.Token,
210-
right: TSESTree.Node | TSESTree.Token,
211-
padding?: T,
199+
options?: T | number,
212200
): SourceCode.ReturnTypeFromOptions<T>[];
213201
/**
214202
* Gets all of the tokens between two non-overlapping nodes.
215203
* @param left Node before the desired token range.
216204
* @param right Node after the desired token range.
217-
* @param padding Number of extra tokens on either side of center.
205+
* @param options The option object. If this is a number then it's `options.count`. If this is a function then it's `options.filter`.
218206
* @returns Tokens between left and right.
219207
*/
220208
getTokensBetween<T extends SourceCode.CursorWithCountOptions>(
221209
left: TSESTree.Node | TSESTree.Token,
222210
right: TSESTree.Node | TSESTree.Token,
223-
padding?: number,
211+
options?: T | number,
224212
): SourceCode.ReturnTypeFromOptions<T>[];
225213
}
226214

Diff for: packages/website-eslint/src/mock/eslint.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-extraneous-class */
12
class RuleTester {}
23
class SourceCode {}
34

Diff for: packages/website/plugins/generated-rule-docs.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const eslintPluginDirectory = path.resolve(
4040
path.join(__dirname, '../../eslint-plugin'),
4141
);
4242

43-
function nodeIsParent(node: unist.Node<unist.Data>): node is unist.Parent {
43+
function nodeIsParent(node: unist.Node): node is unist.Parent {
4444
return 'children' in node;
4545
}
4646

Diff for: packages/website/src/hooks/useHistorySelector.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useHistory } from '@docusaurus/router';
22
import type * as H from 'history';
33
import { useSyncExternalStore } from 'react';
44

5-
export type HistorySelector<T> = (history: H.History<H.LocationState>) => T;
5+
export type HistorySelector<T> = (history: H.History) => T;
66

77
export function useHistorySelector<T>(
88
selector: HistorySelector<T>,

0 commit comments

Comments
 (0)