Skip to content

chore: enabled stylistic-type-checked internally #7138

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
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 14 additions & 12 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ module.exports = {
'eslint:recommended',
'plugin:eslint-plugin/recommended',
'plugin:@typescript-eslint/recommended-type-checked',
// TODO: consider enabling strict-type-checked and/or stylistic-type-checked
'plugin:@typescript-eslint/stylistic-type-checked',
// TODO: consider enabling strict-type-checked
],
parserOptions: {
sourceType: 'module',
Expand Down Expand Up @@ -52,11 +53,18 @@ module.exports = {
// make sure we're not leveraging any deprecated APIs
'deprecation/deprecation': 'error',

// TODO(#7138): Investigate enabling these soon ✨
'@typescript-eslint/consistent-indexed-object-style': 'off',
'@typescript-eslint/prefer-nullish-coalescing': 'off',

// TODO(#7130): Investigate changing these in or removing these from presets
'@typescript-eslint/no-confusing-void-expression': 'off',
'@typescript-eslint/prefer-string-starts-ends-with': 'off',

//
// our plugin :D
//

'@typescript-eslint/array-type': 'error',
'@typescript-eslint/ban-ts-comment': [
'error',
{
Expand All @@ -67,7 +75,6 @@ module.exports = {
minimumDescriptionLength: 5,
},
],
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
'@typescript-eslint/consistent-type-imports': [
'error',
{ prefer: 'type-imports', disallowTypeAnnotations: true },
Expand All @@ -76,18 +83,10 @@ module.exports = {
'error',
{ allowIIFEs: true },
],
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-empty-function': [
'error',
{ allow: ['arrowFunctions'] },
],
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/prefer-for-of': 'error',
'@typescript-eslint/prefer-optional-chain': 'error',
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/prefer-as-const': 'error',
'@typescript-eslint/restrict-template-expressions': [
'error',
{
Expand All @@ -98,7 +97,6 @@ module.exports = {
allowRegExp: true,
},
],
'@typescript-eslint/sort-type-constituents': 'error',
'@typescript-eslint/no-unused-vars': [
'error',
{ varsIgnorePattern: '^_', argsIgnorePattern: '^_' },
Expand Down Expand Up @@ -238,6 +236,10 @@ module.exports = {
'jest/globals': true,
},
rules: {
'@typescript-eslint/no-empty-function': [
'error',
{ allow: ['arrowFunctions'] },
],
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/comma-dangle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export default util.createRule<Options, MessageIds>({
'always-multiline': forceCommaIfMultiline,
'only-multiline': allowCommaIfMultiline,
never: forbidComma,
ignore: (): void => {},
ignore: undefined,
};

function last(nodes: TSESTree.Node[]): TSESTree.Node | null {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export default util.createRule<Options, MessageIds>({
function checkDuplicate(
node: TSESTree.TSIntersectionType | TSESTree.TSUnionType,
): void {
const cachedTypeMap: Map<Type, TSESTree.TypeNode> = new Map();
const cachedTypeMap = new Map<Type, TSESTree.TypeNode>();
node.types.reduce<TSESTree.TypeNode[]>(
(uniqueConstituents, constituentNode) => {
const duplicatedPreviousConstituentInAst = uniqueConstituents.find(
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/no-restricted-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export default createRule<Options, MessageIds>({
}

const restrictedPaths = getRestrictedPaths(options);
const allowedTypeImportPathNameSet: Set<string> = new Set();
const allowedTypeImportPathNameSet = new Set<string>();
for (const restrictedPath of restrictedPaths) {
if (
typeof restrictedPath === 'object' &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,9 @@ function verifyForAlways(
messageId: 'expectedBlankLine',
fix(fixer) {
const sourceCode = context.getSourceCode();
let prevToken = getActualLastToken(
prevNode,
sourceCode,
) as TSESTree.Token;
let prevToken = getActualLastToken(prevNode, sourceCode)!;
const nextToken =
(sourceCode.getFirstTokenBetween(prevToken, nextNode, {
sourceCode.getFirstTokenBetween(prevToken, nextNode, {
includeComments: true,

/**
Expand Down Expand Up @@ -473,7 +470,7 @@ function verifyForAlways(
}
return true;
},
}) as TSESTree.Token) || nextNode;
})! || nextNode;
const insertText = util.isTokenOnSameLine(prevToken, nextToken)
? '\n\n'
: '\n';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export default createRule({

if (discriminantType.isUnion()) {
const unionTypes = tsutils.unionTypeParts(discriminantType);
const caseTypes: Set<ts.Type> = new Set();
const caseTypes = new Set<ts.Type>();
for (const switchCase of node.cases) {
if (switchCase.test == null) {
// Switch has 'default' branch - do nothing.
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/util/astUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function forEachReturnStatement<T>(
function traverse(node: ts.Node): T | undefined {
switch (node.kind) {
case ts.SyntaxKind.ReturnStatement:
return visitor(<ts.ReturnStatement>node);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return visitor(node as ts.ReturnStatement);
case ts.SyntaxKind.CaseBlock:
case ts.SyntaxKind.Block:
case ts.SyntaxKind.IfStatement:
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/tests/configs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe('recommended-type-checked.ts', () => {

describe('strict.ts', () => {
const unfilteredConfigRules: Record<string, string> =
plugin.configs['strict'].rules;
plugin.configs.strict.rules;

it('contains all strict rules, excluding type checked ones', () => {
const configRules = filterRules(unfilteredConfigRules);
Expand Down Expand Up @@ -166,7 +166,7 @@ describe('strict-type-checked.ts', () => {

describe('stylistic.ts', () => {
const unfilteredConfigRules: Record<string, string> =
plugin.configs['stylistic'].rules;
plugin.configs.stylistic.rules;

it('contains all stylistic rules, excluding deprecated or type checked ones', () => {
const configRules = filterRules(unfilteredConfigRules);
Expand Down
4 changes: 2 additions & 2 deletions packages/scope-manager/src/scope/ScopeBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ abstract class ScopeBase<
block: TBlock,
isMethodDefinition: boolean,
) {
const upperScopeAsScopeBase = upperScope as Scope;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised TS allowed this - the reason this cast was there was because upperScope is typed as TUpper - and there was a lot of weird behaviour that stemmed from it being a generic instead of the concrete type.

I think there was also some weirdness due to the cyclic nature of the files? I don't fully remmeber though

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷

const upperScopeAsScopeBase = upperScope!;

this.type = type;
this.#dynamic =
Expand Down Expand Up @@ -386,7 +386,7 @@ abstract class ScopeBase<
}

protected delegateToUpperScope(ref: Reference): void {
const upper = this.upper as Scope as AnyScope;
const upper = this.upper! as AnyScope;
if (upper?.leftToResolve) {
upper.leftToResolve.push(ref);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/dot-notation -- ['implicit'] is private */
import {
expectToBeForScope,
expectToBeFunctionScope,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/dot-notation -- ['implicit'] is private */
import { DefinitionType } from '../../src/definition';
import {
expectToBeGlobalScope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ function createDefaultProgram(
const commandLine = ts.getParsedCommandLineOfConfigFile(
tsconfigPath,
createDefaultCompilerOptionsFromExtra(parseSettings),
{ ...ts.sys, onUnRecoverableConfigFileDiagnostic: () => {} },
{
...ts.sys,
// TODO: file issue on TypeScript to suggest making optional?
// eslint-disable-next-line @typescript-eslint/no-empty-function
onUnRecoverableConfigFileDiagnostic: () => {},
},
);

if (!commandLine) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ function createWatchProgram(
ts.sys,
ts.createAbstractBuilder,
diagnosticReporter,
// TODO: file issue on TypeScript to suggest making optional?
// eslint-disable-next-line @typescript-eslint/no-empty-function
/*reportWatchStatus*/ () => {},
) as WatchCompilerHostOfConfigFile<ts.BuilderProgram>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function createParseSettings(
typeof options.loggerFn === 'function'
? options.loggerFn
: options.loggerFn === false
? (): void => {}
? (): void => {} // eslint-disable-line @typescript-eslint/no-empty-function
: console.log, // eslint-disable-line no-console
preserveNodeMaps: options.preserveNodeMaps !== false,
programs: Array.isArray(options.programs) ? options.programs : null,
Expand Down
1 change: 1 addition & 0 deletions packages/typescript-estree/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ function getProgramAndAST(
return createNoProgram(parseSettings);
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface EmptyObject {}
type AST<T extends TSESTreeOptions> = TSESTree.Program &
(T['comment'] extends true ? { comments: TSESTree.Comment[] } : EmptyObject) &
Expand Down
2 changes: 2 additions & 0 deletions packages/typescript-estree/src/ts-estree/ts-nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type * as ts from 'typescript';

// Workaround to support new TS version features for consumers on old TS versions
// Eg: https://github.com/typescript-eslint/typescript-eslint/issues/2388, https://github.com/typescript-eslint/typescript-eslint/issues/2784
/* eslint-disable @typescript-eslint/no-empty-interface */
declare module 'typescript' {
// added in TS 4.0
export interface NamedTupleMember extends ts.Node {}
Expand All @@ -16,6 +17,7 @@ declare module 'typescript' {
// added in TS 4.9
export interface SatisfiesExpression extends ts.Node {}
}
/* eslint-enable @typescript-eslint/no-empty-interface */

export type TSToken = ts.Token<ts.SyntaxKind>;

Expand Down
Loading