From ac1ef72d64f26249f0cec232d5111522afd2090a Mon Sep 17 00:00:00 2001 From: Andrey Mikheychik Date: Sun, 10 Nov 2024 19:05:40 -0600 Subject: [PATCH] Disalble remaining TSLint rules The `@typescript-eslint/eslint-plugin-tslint` does not support ESLint v9, and out of the remaining TSLint rules only a few rules do not have a replacement. The following remaining rules were removed: - `encoding` - UTF-8 is configured in `tsconfig.json` (the `charset` option). - `import-spacing` - covered by the `@stylistic/ts/keyword-spacing` and `@stylistic/ts/object-curly-spacing` rules. - `no-default-import` - irrelevant, as it requires a list of modules. - `no-inferred-empty-object-type` - the rule is not irrelevant since TS 3.4. - `no-mergeable-namespace` - irrelevant, as `@typescript-eslint/no-namespace` is enabled and namespaces are not allowed. - `no-tautology-expression` - covered by the `no-self-compare`, `sonarjs/ no-identical-expressions`, and `no-constant-condition` rules. - `no-unnecessary-callback-wrapper` - does not have a replacement. Without this rule the following code will not be flagged: ``` input.map(x => same(x)) ``` - `prefer-conditional-expression` - the rule is covered by the `unicorn/prefer-ternary` rule, if needed, but `unicorn/prefer-ternary` is disabled by default. - `prefer-switch` - covered by the `unicorn/prefer-switch` rule. - `prefer-while` - covered by the `sonarjs/prefer-while` rule. - `return-undefined` - partially covered by the `no-useless-return` rule. - `static-this` - does not have a replacement. Without this rule the following code will not be flagged: ``` public static example() { return this.name; } ``` - `strict-comparisons` - does not have a replacement. Without this rule the following code will not be flagged: ``` const o1 = {}; const o2 = {}; if (o1 > o2) { /*...*/ } ``` - `strict-type-predicates` - does not have a replacement, but has already been disabled. - `switch-final-break` - does not have a replacement, due to `@typescript-eslint/switch-exhaustiveness-check`, the final statement in a `switch` is always `default`, so the issue is non-critical. Without this rule the following code will not be flagged: ``` switch (a) { case 'a': r = 1; break; default: r = 2; } ``` --- src/rules.ts | 6 -- .../typescript-eslint-tslint-config.spec.ts | 56 ------------------- .../rules/typescript-eslint-tslint-config.ts | 56 ------------------- src/rules/typescript-eslint/tslint.ts | 4 +- src/rules/unicorn/index.adoc | 1 + 5 files changed, 2 insertions(+), 121 deletions(-) delete mode 100644 src/rules/typescript-eslint/rules/typescript-eslint-tslint-config.spec.ts delete mode 100644 src/rules/typescript-eslint/rules/typescript-eslint-tslint-config.ts diff --git a/src/rules.ts b/src/rules.ts index 501fa77..dae0510 100644 --- a/src/rules.ts +++ b/src/rules.ts @@ -18,12 +18,6 @@ export { TypescriptEslintNamingConventionSelector, TypescriptEslintNamingConventionUnderscore, } from './rules/typescript-eslint/rules/typescript-eslint-naming-convention'; -export { - TsLintRule, - TsLintRules, - TypescriptEslintTslintConfig, - typescriptEslintTslintConfig, -} from './rules/typescript-eslint/rules/typescript-eslint-tslint-config'; export { UnicornPreventAbbreviationReplacements, UnicornPreventAbbreviations, diff --git a/src/rules/typescript-eslint/rules/typescript-eslint-tslint-config.spec.ts b/src/rules/typescript-eslint/rules/typescript-eslint-tslint-config.spec.ts deleted file mode 100644 index a8888cf..0000000 --- a/src/rules/typescript-eslint/rules/typescript-eslint-tslint-config.spec.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { describe, expect, it } from '@jest/globals'; - -import { TypescriptEslintTslintConfig, typescriptEslintTslintConfig } from './typescript-eslint-tslint-config'; - -describe(typescriptEslintTslintConfig, () => { - it('creates default configuration for the @typescript-eslint/tslint/config rule', () => { - expect(typescriptEslintTslintConfig()) - .toStrictEqual({ - rules: { - 'encoding': true, - 'import-spacing': true, - 'no-default-import': true, - 'no-inferred-empty-object-type': true, - 'no-mergeable-namespace': true, - 'no-tautology-expression': true, - 'no-unnecessary-callback-wrapper': true, - 'prefer-conditional-expression': [true, 'check-else-if'], - 'prefer-switch': [true, { 'min-cases': 2 }], - 'prefer-while': true, - 'return-undefined': true, - 'static-this': true, - 'strict-comparisons': [true, { - 'allow-object-equal-comparison': true, - 'allow-string-order-comparison': true, - }], - 'switch-final-break': [true, 'always'], - }, - rulesDirectory: [], - } as TypescriptEslintTslintConfig); - }); - - it('overrides and extends default rules', () => { - expect(typescriptEslintTslintConfig({ - 'strict-comparisons': false, - }, ['tslint'])) - .toStrictEqual({ - rules: { - 'encoding': true, - 'import-spacing': true, - 'no-default-import': true, - 'no-inferred-empty-object-type': true, - 'no-mergeable-namespace': true, - 'no-tautology-expression': true, - 'no-unnecessary-callback-wrapper': true, - 'prefer-conditional-expression': [true, 'check-else-if'], - 'prefer-switch': [true, { 'min-cases': 2 }], - 'prefer-while': true, - 'return-undefined': true, - 'static-this': true, - 'strict-comparisons': false, - 'switch-final-break': [true, 'always'], - }, - rulesDirectory: ['tslint'], - } as TypescriptEslintTslintConfig); - }); -}); diff --git a/src/rules/typescript-eslint/rules/typescript-eslint-tslint-config.ts b/src/rules/typescript-eslint/rules/typescript-eslint-tslint-config.ts deleted file mode 100644 index c95e37a..0000000 --- a/src/rules/typescript-eslint/rules/typescript-eslint-tslint-config.ts +++ /dev/null @@ -1,56 +0,0 @@ -export type TsLintRule = boolean | [boolean, unknown]; -export type TsLintRules = Record; - -export interface TypescriptEslintTslintConfig { - rules: TsLintRules; - rulesDirectory?: string[]; -} - -const format: TsLintRules = { - 'import-spacing': true, -}; - -const functionality: TsLintRules = { - 'no-inferred-empty-object-type': true, - 'no-tautology-expression': true, - 'prefer-conditional-expression': [true, 'check-else-if'], - 'static-this': true, - 'strict-comparisons': [true, { - 'allow-object-equal-comparison': true, - 'allow-string-order-comparison': true, - }], - // Relies on deprecated API - // DeprecationWarning: 'originalKeywordKind' has been deprecated since v5.0.0 - // and will no longer be usable after v5.2.0. Use 'identifierToKeywordKind(identifier)' instead. - // 'strict-type-predicates': true, -}; - -const maintainability: TsLintRules = { - 'no-default-import': true, - 'no-mergeable-namespace': true, -}; - -const style: TsLintRules = { - 'encoding': true, - 'no-unnecessary-callback-wrapper': true, - 'prefer-switch': [true, { 'min-cases': 2 }], - 'prefer-while': true, - 'return-undefined': true, - 'switch-final-break': [true, 'always'], -}; - -export function typescriptEslintTslintConfig( - rules: TsLintRules = {}, - directories: string[] = [], -): TypescriptEslintTslintConfig { - return { - rules: { - ...format, - ...functionality, - ...maintainability, - ...style, - ...rules, - }, - rulesDirectory: directories, - }; -} diff --git a/src/rules/typescript-eslint/tslint.ts b/src/rules/typescript-eslint/tslint.ts index c4dea19..1440c3c 100644 --- a/src/rules/typescript-eslint/tslint.ts +++ b/src/rules/typescript-eslint/tslint.ts @@ -1,10 +1,8 @@ -import { typescriptEslintTslintConfig } from './rules/typescript-eslint-tslint-config'; - export = { plugins: [ '@typescript-eslint/tslint', ], rules: { - '@typescript-eslint/tslint/config': ['warn', typescriptEslintTslintConfig()], + '@typescript-eslint/tslint/config': 'off', }, }; diff --git a/src/rules/unicorn/index.adoc b/src/rules/unicorn/index.adoc index d383c36..0fa17a4 100644 --- a/src/rules/unicorn/index.adoc +++ b/src/rules/unicorn/index.adoc @@ -579,6 +579,7 @@ The `link:https://github.com/sindresorhus/eslint-plugin-unicorn[eslint-plugin-un | Yes | Yes | Off +4+| Reduces readability for `yield`, `await`, `throw` statements. | `link:{eslint-unicorn-rules}/prefer-ternary.md[unicorn/prefer-top-level-await]` |