From 0126b4f56f9197d561e90b09962ccceb4f88bc41 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Sun, 10 May 2020 12:14:50 -0700 Subject: [PATCH] feat(eslint-plugin): update recommended sets (#2001) --- .cspell.json | 1 + .eslintrc.js | 39 +++--- docs/getting-started/linting/README.md | 2 - packages/eslint-plugin/README.md | 42 +++--- packages/eslint-plugin/src/configs/all.json | 126 ------------------ packages/eslint-plugin/src/configs/all.ts | 126 ++++++++++++++++++ packages/eslint-plugin/src/configs/base.json | 5 - packages/eslint-plugin/src/configs/base.ts | 5 + .../src/configs/eslint-recommended.ts | 12 +- .../recommended-requiring-type-checking.json | 19 --- .../recommended-requiring-type-checking.ts | 21 +++ .../src/configs/recommended.json | 38 ------ .../eslint-plugin/src/configs/recommended.ts | 30 +++++ packages/eslint-plugin/src/index.ts | 8 +- .../eslint-plugin/src/rules/ban-ts-comment.ts | 2 +- .../eslint-plugin/src/rules/ban-ts-ignore.ts | 2 +- packages/eslint-plugin/src/rules/camelcase.ts | 2 +- .../src/rules/class-name-casing.ts | 2 +- .../src/rules/consistent-type-assertions.ts | 2 +- .../rules/explicit-function-return-type.ts | 2 +- .../rules/explicit-module-boundary-types.ts | 2 +- .../src/rules/interface-name-prefix.ts | 4 +- .../src/rules/member-delimiter-style.ts | 2 +- .../src/rules/naming-convention.ts | 5 - .../src/rules/no-extra-non-null-assertion.ts | 2 +- .../eslint-plugin/src/rules/no-extra-semi.ts | 2 +- .../src/rules/no-floating-promises.ts | 2 +- .../src/rules/no-implied-eval.ts | 2 +- .../no-non-null-asserted-optional-chain.ts | 2 +- .../src/rules/no-unsafe-assignment.ts | 2 +- .../eslint-plugin/src/rules/no-unsafe-call.ts | 2 +- .../src/rules/no-unsafe-member-access.ts | 2 +- .../src/rules/no-unsafe-return.ts | 2 +- .../src/rules/no-use-before-define.ts | 2 +- .../src/rules/prefer-as-const.ts | 2 +- .../src/rules/prefer-includes.ts | 2 +- .../rules/prefer-string-starts-ends-with.ts | 3 +- .../src/rules/restrict-plus-operands.ts | 2 +- .../rules/restrict-template-expressions.ts | 2 +- .../src/rules/type-annotation-spacing.ts | 2 +- .../tests/rules/naming-convention.test.ts | 1 - .../eslint-plugin/tools/generate-configs.ts | 39 ++---- tools/generate-contributors.ts | 2 +- 43 files changed, 277 insertions(+), 297 deletions(-) delete mode 100644 packages/eslint-plugin/src/configs/all.json create mode 100644 packages/eslint-plugin/src/configs/all.ts delete mode 100644 packages/eslint-plugin/src/configs/base.json create mode 100644 packages/eslint-plugin/src/configs/base.ts delete mode 100644 packages/eslint-plugin/src/configs/recommended-requiring-type-checking.json create mode 100644 packages/eslint-plugin/src/configs/recommended-requiring-type-checking.ts delete mode 100644 packages/eslint-plugin/src/configs/recommended.json create mode 100644 packages/eslint-plugin/src/configs/recommended.ts diff --git a/.cspell.json b/.cspell.json index 9df7d65a1b5..86a9b7af4f9 100644 --- a/.cspell.json +++ b/.cspell.json @@ -80,6 +80,7 @@ "rulesets", "superset", "thenables", + "transpiles", "tsconfigs", "tsutils", "typedef", diff --git a/.eslintrc.js b/.eslintrc.js index 7760aa89ea1..4974d31f8c9 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -14,10 +14,14 @@ module.exports = { }, extends: [ 'eslint:recommended', - 'plugin:@typescript-eslint/eslint-recommended', 'plugin:@typescript-eslint/recommended', 'plugin:@typescript-eslint/recommended-requiring-type-checking', ], + parserOptions: { + sourceType: 'module', + project: ['./tsconfig.eslint.json', './packages/*/tsconfig.json'], + tsconfigRootDir: __dirname, + }, rules: { // // our plugin :D @@ -25,21 +29,28 @@ module.exports = { '@typescript-eslint/consistent-type-definitions': ['error', 'interface'], '@typescript-eslint/explicit-function-return-type': 'error', + '@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-throw-literal': 'off', - '@typescript-eslint/no-use-before-define': 'off', '@typescript-eslint/no-var-requires': 'off', '@typescript-eslint/prefer-nullish-coalescing': 'error', '@typescript-eslint/prefer-optional-chain': 'error', '@typescript-eslint/unbound-method': 'off', - '@typescript-eslint/prefer-as-const': 'error', - 'no-empty-function': 'off', - '@typescript-eslint/no-empty-function': [ - 'error', - { allow: ['arrowFunctions'] }, - ], + // TODO - enable these new recommended rules + '@typescript-eslint/no-floating-promises': 'off', + '@typescript-eslint/no-unsafe-assignment': 'off', + '@typescript-eslint/no-unsafe-call': 'off', + '@typescript-eslint/no-unsafe-member-access': 'off', + '@typescript-eslint/no-unsafe-return': 'off', + '@typescript-eslint/restrict-plus-operands': 'off', + '@typescript-eslint/restrict-template-expressions': 'off', + // TODO - enable this + '@typescript-eslint/naming-convention': 'off', // // Internal repo rules @@ -53,8 +64,6 @@ module.exports = { // eslint base // - 'comma-dangle': ['error', 'always-multiline'], - 'constructor-super': 'off', curly: ['error', 'all'], 'no-mixed-operators': 'error', 'no-console': 'error', @@ -128,14 +137,6 @@ module.exports = { // Require modules with a single export to use a default export 'import/prefer-default-export': 'off', // we want everything to be named }, - parserOptions: { - sourceType: 'module', - ecmaFeatures: { - jsx: false, - }, - project: ['./tsconfig.eslint.json', './packages/*/tsconfig.json'], - tsconfigRootDir: __dirname, - }, overrides: [ // all test files { diff --git a/docs/getting-started/linting/README.md b/docs/getting-started/linting/README.md index 7936b96f237..bb1fd058e89 100644 --- a/docs/getting-started/linting/README.md +++ b/docs/getting-started/linting/README.md @@ -24,7 +24,6 @@ module.exports = { ], extends: [ 'eslint:recommended', - 'plugin:@typescript-eslint/eslint-recommended', 'plugin:@typescript-eslint/recommended', ], }; @@ -41,7 +40,6 @@ Explaining the important bits: - This allows you to use the rules within your codebase. - `extends: [ ... ]` tells ESLint that your config extends the given configurations. - `eslint:recommended` is ESLint's inbuilt "recommended" config - it turns on a small, sensible set of rules which lint for well-known best-practices. - - `plugin:@typescript-eslint/eslint-recommended` is a configuration we provide which disables a few of the recommended rules from the previous set that we know are already covered by TypeScript's typechecker. - `plugin:@typescript-eslint/recommended` is our "recommended" config - it's just like `eslint:recommended`, except it only turns on rules from our TypeScript-specific plugin. Further reading: diff --git a/packages/eslint-plugin/README.md b/packages/eslint-plugin/README.md index c57d8d09cd6..fe165f2bc9f 100644 --- a/packages/eslint-plugin/README.md +++ b/packages/eslint-plugin/README.md @@ -97,15 +97,15 @@ Pro Tip: For larger codebases you may want to consider splitting our linting int | [`@typescript-eslint/adjacent-overload-signatures`](./docs/rules/adjacent-overload-signatures.md) | Require that member overloads be consecutive | :heavy_check_mark: | | | | [`@typescript-eslint/array-type`](./docs/rules/array-type.md) | Requires using either `T[]` or `Array` for arrays | | :wrench: | | | [`@typescript-eslint/await-thenable`](./docs/rules/await-thenable.md) | Disallows awaiting a value that is not a Thenable | :heavy_check_mark: | | :thought_balloon: | -| [`@typescript-eslint/ban-ts-comment`](./docs/rules/ban-ts-comment.md) | Bans `// @ts-` comments from being used | | | | +| [`@typescript-eslint/ban-ts-comment`](./docs/rules/ban-ts-comment.md) | Bans `// @ts-` comments from being used | :heavy_check_mark: | | | | [`@typescript-eslint/ban-types`](./docs/rules/ban-types.md) | Bans specific types from being used | :heavy_check_mark: | :wrench: | | | [`@typescript-eslint/class-literal-property-style`](./docs/rules/class-literal-property-style.md) | Ensures that literals on classes are exposed in a consistent style | | :wrench: | | -| [`@typescript-eslint/consistent-type-assertions`](./docs/rules/consistent-type-assertions.md) | Enforces consistent usage of type assertions | :heavy_check_mark: | | | +| [`@typescript-eslint/consistent-type-assertions`](./docs/rules/consistent-type-assertions.md) | Enforces consistent usage of type assertions | | | | | [`@typescript-eslint/consistent-type-definitions`](./docs/rules/consistent-type-definitions.md) | Consistent with type definition either `interface` or `type` | | :wrench: | | -| [`@typescript-eslint/explicit-function-return-type`](./docs/rules/explicit-function-return-type.md) | Require explicit return types on functions and class methods | :heavy_check_mark: | | | +| [`@typescript-eslint/explicit-function-return-type`](./docs/rules/explicit-function-return-type.md) | Require explicit return types on functions and class methods | | | | | [`@typescript-eslint/explicit-member-accessibility`](./docs/rules/explicit-member-accessibility.md) | Require explicit accessibility modifiers on class properties and methods | | :wrench: | | -| [`@typescript-eslint/explicit-module-boundary-types`](./docs/rules/explicit-module-boundary-types.md) | Require explicit return and argument types on exported functions' and classes' public class methods | | | | -| [`@typescript-eslint/member-delimiter-style`](./docs/rules/member-delimiter-style.md) | Require a specific member delimiter style for interfaces and type literals | :heavy_check_mark: | :wrench: | | +| [`@typescript-eslint/explicit-module-boundary-types`](./docs/rules/explicit-module-boundary-types.md) | Require explicit return and argument types on exported functions' and classes' public class methods | :heavy_check_mark: | | | +| [`@typescript-eslint/member-delimiter-style`](./docs/rules/member-delimiter-style.md) | Require a specific member delimiter style for interfaces and type literals | | :wrench: | | | [`@typescript-eslint/member-ordering`](./docs/rules/member-ordering.md) | Require a consistent member declaration order | | | | | [`@typescript-eslint/method-signature-style`](./docs/rules/method-signature-style.md) | Enforces using a particular method signature syntax. | | :wrench: | | | [`@typescript-eslint/naming-convention`](./docs/rules/naming-convention.md) | Enforces naming conventions for everything across a codebase | | | :thought_balloon: | @@ -113,17 +113,17 @@ Pro Tip: For larger codebases you may want to consider splitting our linting int | [`@typescript-eslint/no-dynamic-delete`](./docs/rules/no-dynamic-delete.md) | Disallow the delete operator with computed key expressions | | :wrench: | | | [`@typescript-eslint/no-empty-interface`](./docs/rules/no-empty-interface.md) | Disallow the declaration of empty interfaces | :heavy_check_mark: | :wrench: | | | [`@typescript-eslint/no-explicit-any`](./docs/rules/no-explicit-any.md) | Disallow usage of the `any` type | :heavy_check_mark: | :wrench: | | -| [`@typescript-eslint/no-extra-non-null-assertion`](./docs/rules/no-extra-non-null-assertion.md) | Disallow extra non-null assertion | | :wrench: | | +| [`@typescript-eslint/no-extra-non-null-assertion`](./docs/rules/no-extra-non-null-assertion.md) | Disallow extra non-null assertion | :heavy_check_mark: | :wrench: | | | [`@typescript-eslint/no-extraneous-class`](./docs/rules/no-extraneous-class.md) | Forbids the use of classes as namespaces | | | | -| [`@typescript-eslint/no-floating-promises`](./docs/rules/no-floating-promises.md) | Requires Promise-like values to be handled appropriately | | | :thought_balloon: | +| [`@typescript-eslint/no-floating-promises`](./docs/rules/no-floating-promises.md) | Requires Promise-like values to be handled appropriately | :heavy_check_mark: | | :thought_balloon: | | [`@typescript-eslint/no-for-in-array`](./docs/rules/no-for-in-array.md) | Disallow iterating over an array with a for-in loop | :heavy_check_mark: | | :thought_balloon: | -| [`@typescript-eslint/no-implied-eval`](./docs/rules/no-implied-eval.md) | Disallow the use of `eval()`-like methods | | | :thought_balloon: | +| [`@typescript-eslint/no-implied-eval`](./docs/rules/no-implied-eval.md) | Disallow the use of `eval()`-like methods | :heavy_check_mark: | | :thought_balloon: | | [`@typescript-eslint/no-inferrable-types`](./docs/rules/no-inferrable-types.md) | Disallows explicit type declarations for variables or parameters initialized to a number, string, or boolean | :heavy_check_mark: | :wrench: | | | [`@typescript-eslint/no-invalid-void-type`](./docs/rules/no-invalid-void-type.md) | Disallows usage of `void` type outside of generic or return types | | | | | [`@typescript-eslint/no-misused-new`](./docs/rules/no-misused-new.md) | Enforce valid definition of `new` and `constructor` | :heavy_check_mark: | | | | [`@typescript-eslint/no-misused-promises`](./docs/rules/no-misused-promises.md) | Avoid using promises in places not designed to handle them | :heavy_check_mark: | | :thought_balloon: | | [`@typescript-eslint/no-namespace`](./docs/rules/no-namespace.md) | Disallow the use of custom TypeScript modules and namespaces | :heavy_check_mark: | | | -| [`@typescript-eslint/no-non-null-asserted-optional-chain`](./docs/rules/no-non-null-asserted-optional-chain.md) | Disallows using a non-null assertion after an optional chain expression | | | | +| [`@typescript-eslint/no-non-null-asserted-optional-chain`](./docs/rules/no-non-null-asserted-optional-chain.md) | Disallows using a non-null assertion after an optional chain expression | :heavy_check_mark: | | | | [`@typescript-eslint/no-non-null-assertion`](./docs/rules/no-non-null-assertion.md) | Disallows non-null assertions using the `!` postfix operator | :heavy_check_mark: | | | | [`@typescript-eslint/no-parameter-properties`](./docs/rules/no-parameter-properties.md) | Disallow the use of parameter properties in class constructors | | | | | [`@typescript-eslint/no-require-imports`](./docs/rules/no-require-imports.md) | Disallows invocation of `require()` | | | | @@ -135,16 +135,16 @@ Pro Tip: For larger codebases you may want to consider splitting our linting int | [`@typescript-eslint/no-unnecessary-qualifier`](./docs/rules/no-unnecessary-qualifier.md) | Warns when a namespace qualifier is unnecessary | | :wrench: | :thought_balloon: | | [`@typescript-eslint/no-unnecessary-type-arguments`](./docs/rules/no-unnecessary-type-arguments.md) | Enforces that type arguments will not be used if not required | | :wrench: | :thought_balloon: | | [`@typescript-eslint/no-unnecessary-type-assertion`](./docs/rules/no-unnecessary-type-assertion.md) | Warns if a type assertion does not change the type of an expression | :heavy_check_mark: | :wrench: | :thought_balloon: | -| [`@typescript-eslint/no-unsafe-assignment`](./docs/rules/no-unsafe-assignment.md) | Disallows assigning any to variables and properties | | | :thought_balloon: | -| [`@typescript-eslint/no-unsafe-call`](./docs/rules/no-unsafe-call.md) | Disallows calling an any type value | | | :thought_balloon: | -| [`@typescript-eslint/no-unsafe-member-access`](./docs/rules/no-unsafe-member-access.md) | Disallows member access on any typed variables | | | :thought_balloon: | -| [`@typescript-eslint/no-unsafe-return`](./docs/rules/no-unsafe-return.md) | Disallows returning any from a function | | | :thought_balloon: | +| [`@typescript-eslint/no-unsafe-assignment`](./docs/rules/no-unsafe-assignment.md) | Disallows assigning any to variables and properties | :heavy_check_mark: | | :thought_balloon: | +| [`@typescript-eslint/no-unsafe-call`](./docs/rules/no-unsafe-call.md) | Disallows calling an any type value | :heavy_check_mark: | | :thought_balloon: | +| [`@typescript-eslint/no-unsafe-member-access`](./docs/rules/no-unsafe-member-access.md) | Disallows member access on any typed variables | :heavy_check_mark: | | :thought_balloon: | +| [`@typescript-eslint/no-unsafe-return`](./docs/rules/no-unsafe-return.md) | Disallows returning any from a function | :heavy_check_mark: | | :thought_balloon: | | [`@typescript-eslint/no-unused-vars-experimental`](./docs/rules/no-unused-vars-experimental.md) | Disallow unused variables and arguments | | | | | [`@typescript-eslint/no-var-requires`](./docs/rules/no-var-requires.md) | Disallows the use of require statements except in import statements | :heavy_check_mark: | | | -| [`@typescript-eslint/prefer-as-const`](./docs/rules/prefer-as-const.md) | Prefer usage of `as const` over literal type | | :wrench: | | +| [`@typescript-eslint/prefer-as-const`](./docs/rules/prefer-as-const.md) | Prefer usage of `as const` over literal type | :heavy_check_mark: | :wrench: | | | [`@typescript-eslint/prefer-for-of`](./docs/rules/prefer-for-of.md) | Prefer a ‘for-of’ loop over a standard ‘for’ loop if the index is only used to access the array being iterated | | | | | [`@typescript-eslint/prefer-function-type`](./docs/rules/prefer-function-type.md) | Use function types instead of interfaces with call signatures | | :wrench: | | -| [`@typescript-eslint/prefer-includes`](./docs/rules/prefer-includes.md) | Enforce `includes` method over `indexOf` method | :heavy_check_mark: | :wrench: | :thought_balloon: | +| [`@typescript-eslint/prefer-includes`](./docs/rules/prefer-includes.md) | Enforce `includes` method over `indexOf` method | | :wrench: | :thought_balloon: | | [`@typescript-eslint/prefer-namespace-keyword`](./docs/rules/prefer-namespace-keyword.md) | Require the use of the `namespace` keyword instead of the `module` keyword to declare custom TypeScript modules | :heavy_check_mark: | :wrench: | | | [`@typescript-eslint/prefer-nullish-coalescing`](./docs/rules/prefer-nullish-coalescing.md) | Enforce the usage of the nullish coalescing operator instead of logical chaining | | :wrench: | :thought_balloon: | | [`@typescript-eslint/prefer-optional-chain`](./docs/rules/prefer-optional-chain.md) | Prefer using concise optional chain expressions instead of chained logical ands | | :wrench: | | @@ -152,16 +152,16 @@ Pro Tip: For larger codebases you may want to consider splitting our linting int | [`@typescript-eslint/prefer-readonly-parameter-types`](./docs/rules/prefer-readonly-parameter-types.md) | Requires that function parameters are typed as readonly to prevent accidental mutation of inputs | | | :thought_balloon: | | [`@typescript-eslint/prefer-reduce-type-parameter`](./docs/rules/prefer-reduce-type-parameter.md) | Prefer using type parameter when calling `Array#reduce` instead of casting | | :wrench: | :thought_balloon: | | [`@typescript-eslint/prefer-regexp-exec`](./docs/rules/prefer-regexp-exec.md) | Enforce that `RegExp#exec` is used instead of `String#match` if no global flag is provided | :heavy_check_mark: | | :thought_balloon: | -| [`@typescript-eslint/prefer-string-starts-ends-with`](./docs/rules/prefer-string-starts-ends-with.md) | Enforce the use of `String#startsWith` and `String#endsWith` instead of other equivalent methods of checking substrings | :heavy_check_mark: | :wrench: | :thought_balloon: | +| [`@typescript-eslint/prefer-string-starts-ends-with`](./docs/rules/prefer-string-starts-ends-with.md) | Enforce the use of `String#startsWith` and `String#endsWith` instead of other equivalent methods of checking substrings | | :wrench: | :thought_balloon: | | [`@typescript-eslint/prefer-ts-expect-error`](./docs/rules/prefer-ts-expect-error.md) | Recommends using `// @ts-expect-error` over `// @ts-ignore` | | :wrench: | | | [`@typescript-eslint/promise-function-async`](./docs/rules/promise-function-async.md) | Requires any function or method that returns a Promise to be marked async | | | :thought_balloon: | | [`@typescript-eslint/require-array-sort-compare`](./docs/rules/require-array-sort-compare.md) | Requires `Array#sort` calls to always provide a `compareFunction` | | | :thought_balloon: | -| [`@typescript-eslint/restrict-plus-operands`](./docs/rules/restrict-plus-operands.md) | When adding two variables, operands must both be of type number or of type string | | | :thought_balloon: | -| [`@typescript-eslint/restrict-template-expressions`](./docs/rules/restrict-template-expressions.md) | Enforce template literal expressions to be of string type | | | :thought_balloon: | +| [`@typescript-eslint/restrict-plus-operands`](./docs/rules/restrict-plus-operands.md) | When adding two variables, operands must both be of type number or of type string | :heavy_check_mark: | | :thought_balloon: | +| [`@typescript-eslint/restrict-template-expressions`](./docs/rules/restrict-template-expressions.md) | Enforce template literal expressions to be of string type | :heavy_check_mark: | | :thought_balloon: | | [`@typescript-eslint/strict-boolean-expressions`](./docs/rules/strict-boolean-expressions.md) | Restricts the types allowed in boolean expressions | | | :thought_balloon: | | [`@typescript-eslint/switch-exhaustiveness-check`](./docs/rules/switch-exhaustiveness-check.md) | Exhaustiveness checking in switch with union type | | | :thought_balloon: | | [`@typescript-eslint/triple-slash-reference`](./docs/rules/triple-slash-reference.md) | Sets preference level for triple slash directives versus ES6-style import declarations | :heavy_check_mark: | | | -| [`@typescript-eslint/type-annotation-spacing`](./docs/rules/type-annotation-spacing.md) | Require consistent spacing around type annotations | :heavy_check_mark: | :wrench: | | +| [`@typescript-eslint/type-annotation-spacing`](./docs/rules/type-annotation-spacing.md) | Require consistent spacing around type annotations | | :wrench: | | | [`@typescript-eslint/typedef`](./docs/rules/typedef.md) | Requires type annotations to exist | | | | | [`@typescript-eslint/unbound-method`](./docs/rules/unbound-method.md) | Enforces unbound methods are called with their expected scope | :heavy_check_mark: | | :thought_balloon: | | [`@typescript-eslint/unified-signatures`](./docs/rules/unified-signatures.md) | Warns for any two overloads that could be unified into one by using a union or an optional/rest parameter | | | | @@ -192,12 +192,12 @@ In these cases, we create what we call an extension rule; a rule within our plug | [`@typescript-eslint/no-dupe-class-members`](./docs/rules/no-dupe-class-members.md) | Disallow duplicate class members | | | | | [`@typescript-eslint/no-empty-function`](./docs/rules/no-empty-function.md) | Disallow empty functions | :heavy_check_mark: | | | | [`@typescript-eslint/no-extra-parens`](./docs/rules/no-extra-parens.md) | Disallow unnecessary parentheses | | :wrench: | | -| [`@typescript-eslint/no-extra-semi`](./docs/rules/no-extra-semi.md) | Disallow unnecessary semicolons | | :wrench: | | +| [`@typescript-eslint/no-extra-semi`](./docs/rules/no-extra-semi.md) | Disallow unnecessary semicolons | :heavy_check_mark: | :wrench: | | | [`@typescript-eslint/no-invalid-this`](./docs/rules/no-invalid-this.md) | disallow `this` keywords outside of classes or class-like objects | | | | | [`@typescript-eslint/no-magic-numbers`](./docs/rules/no-magic-numbers.md) | Disallow magic numbers | | | | | [`@typescript-eslint/no-unused-expressions`](./docs/rules/no-unused-expressions.md) | Disallow unused expressions | | | | | [`@typescript-eslint/no-unused-vars`](./docs/rules/no-unused-vars.md) | Disallow unused variables | :heavy_check_mark: | | | -| [`@typescript-eslint/no-use-before-define`](./docs/rules/no-use-before-define.md) | Disallow the use of variables before they are defined | :heavy_check_mark: | | | +| [`@typescript-eslint/no-use-before-define`](./docs/rules/no-use-before-define.md) | Disallow the use of variables before they are defined | | | | | [`@typescript-eslint/no-useless-constructor`](./docs/rules/no-useless-constructor.md) | Disallow unnecessary constructors | | | | | [`@typescript-eslint/quotes`](./docs/rules/quotes.md) | Enforce the consistent use of either backticks, double, or single quotes | | :wrench: | | | [`@typescript-eslint/require-await`](./docs/rules/require-await.md) | Disallow async functions which have no `await` expression | :heavy_check_mark: | | :thought_balloon: | diff --git a/packages/eslint-plugin/src/configs/all.json b/packages/eslint-plugin/src/configs/all.json deleted file mode 100644 index 3182e67de26..00000000000 --- a/packages/eslint-plugin/src/configs/all.json +++ /dev/null @@ -1,126 +0,0 @@ -{ - "extends": "./configs/base.json", - "rules": { - "@typescript-eslint/adjacent-overload-signatures": "error", - "@typescript-eslint/array-type": "error", - "@typescript-eslint/await-thenable": "error", - "@typescript-eslint/ban-ts-comment": "error", - "@typescript-eslint/ban-types": "error", - "brace-style": "off", - "@typescript-eslint/brace-style": "error", - "@typescript-eslint/class-literal-property-style": "error", - "comma-spacing": "off", - "@typescript-eslint/comma-spacing": "error", - "@typescript-eslint/consistent-type-assertions": "error", - "@typescript-eslint/consistent-type-definitions": "error", - "default-param-last": "off", - "@typescript-eslint/default-param-last": "error", - "dot-notation": "off", - "@typescript-eslint/dot-notation": "error", - "@typescript-eslint/explicit-function-return-type": "error", - "@typescript-eslint/explicit-member-accessibility": "error", - "@typescript-eslint/explicit-module-boundary-types": "error", - "func-call-spacing": "off", - "@typescript-eslint/func-call-spacing": "error", - "indent": "off", - "@typescript-eslint/indent": "error", - "lines-between-class-members": "off", - "@typescript-eslint/lines-between-class-members": "error", - "init-declarations": "off", - "@typescript-eslint/init-declarations": "error", - "keyword-spacing": "off", - "@typescript-eslint/keyword-spacing": "error", - "@typescript-eslint/member-delimiter-style": "error", - "@typescript-eslint/member-ordering": "error", - "@typescript-eslint/method-signature-style": "error", - "@typescript-eslint/naming-convention": "error", - "no-array-constructor": "off", - "@typescript-eslint/no-array-constructor": "error", - "@typescript-eslint/no-base-to-string": "error", - "no-dupe-class-members": "off", - "@typescript-eslint/no-dupe-class-members": "error", - "@typescript-eslint/no-dynamic-delete": "error", - "no-empty-function": "off", - "@typescript-eslint/no-empty-function": "error", - "@typescript-eslint/no-empty-interface": "error", - "@typescript-eslint/no-explicit-any": "error", - "@typescript-eslint/no-extra-non-null-assertion": "error", - "no-extra-parens": "off", - "@typescript-eslint/no-extra-parens": "error", - "no-extra-semi": "off", - "@typescript-eslint/no-extra-semi": "error", - "@typescript-eslint/no-extraneous-class": "error", - "@typescript-eslint/no-floating-promises": "error", - "@typescript-eslint/no-for-in-array": "error", - "@typescript-eslint/no-implied-eval": "error", - "@typescript-eslint/no-inferrable-types": "error", - "no-invalid-this": "off", - "@typescript-eslint/no-invalid-this": "error", - "@typescript-eslint/no-invalid-void-type": "error", - "no-magic-numbers": "off", - "@typescript-eslint/no-magic-numbers": "error", - "@typescript-eslint/no-misused-new": "error", - "@typescript-eslint/no-misused-promises": "error", - "@typescript-eslint/no-namespace": "error", - "@typescript-eslint/no-non-null-asserted-optional-chain": "error", - "@typescript-eslint/no-non-null-assertion": "error", - "@typescript-eslint/no-parameter-properties": "error", - "@typescript-eslint/no-require-imports": "error", - "@typescript-eslint/no-this-alias": "error", - "@typescript-eslint/no-throw-literal": "error", - "@typescript-eslint/no-type-alias": "error", - "@typescript-eslint/no-unnecessary-boolean-literal-compare": "error", - "@typescript-eslint/no-unnecessary-condition": "error", - "@typescript-eslint/no-unnecessary-qualifier": "error", - "@typescript-eslint/no-unnecessary-type-arguments": "error", - "@typescript-eslint/no-unnecessary-type-assertion": "error", - "@typescript-eslint/no-unsafe-assignment": "error", - "@typescript-eslint/no-unsafe-call": "error", - "@typescript-eslint/no-unsafe-member-access": "error", - "@typescript-eslint/no-unsafe-return": "error", - "no-unused-expressions": "off", - "@typescript-eslint/no-unused-expressions": "error", - "no-unused-vars": "off", - "@typescript-eslint/no-unused-vars": "error", - "@typescript-eslint/no-unused-vars-experimental": "error", - "no-use-before-define": "off", - "@typescript-eslint/no-use-before-define": "error", - "no-useless-constructor": "off", - "@typescript-eslint/no-useless-constructor": "error", - "@typescript-eslint/no-var-requires": "error", - "@typescript-eslint/prefer-as-const": "error", - "@typescript-eslint/prefer-for-of": "error", - "@typescript-eslint/prefer-function-type": "error", - "@typescript-eslint/prefer-includes": "error", - "@typescript-eslint/prefer-namespace-keyword": "error", - "@typescript-eslint/prefer-nullish-coalescing": "error", - "@typescript-eslint/prefer-optional-chain": "error", - "@typescript-eslint/prefer-readonly": "error", - "@typescript-eslint/prefer-readonly-parameter-types": "error", - "@typescript-eslint/prefer-reduce-type-parameter": "error", - "@typescript-eslint/prefer-regexp-exec": "error", - "@typescript-eslint/prefer-string-starts-ends-with": "error", - "@typescript-eslint/prefer-ts-expect-error": "error", - "@typescript-eslint/promise-function-async": "error", - "quotes": "off", - "@typescript-eslint/quotes": "error", - "@typescript-eslint/require-array-sort-compare": "error", - "require-await": "off", - "@typescript-eslint/require-await": "error", - "@typescript-eslint/restrict-plus-operands": "error", - "@typescript-eslint/restrict-template-expressions": "error", - "no-return-await": "off", - "@typescript-eslint/return-await": "error", - "semi": "off", - "@typescript-eslint/semi": "error", - "space-before-function-paren": "off", - "@typescript-eslint/space-before-function-paren": "error", - "@typescript-eslint/strict-boolean-expressions": "error", - "@typescript-eslint/switch-exhaustiveness-check": "error", - "@typescript-eslint/triple-slash-reference": "error", - "@typescript-eslint/type-annotation-spacing": "error", - "@typescript-eslint/typedef": "error", - "@typescript-eslint/unbound-method": "error", - "@typescript-eslint/unified-signatures": "error" - } -} diff --git a/packages/eslint-plugin/src/configs/all.ts b/packages/eslint-plugin/src/configs/all.ts new file mode 100644 index 00000000000..a02d6db9d69 --- /dev/null +++ b/packages/eslint-plugin/src/configs/all.ts @@ -0,0 +1,126 @@ +export = { + extends: ['./configs/base', './configs/eslint-recommended'], + rules: { + '@typescript-eslint/adjacent-overload-signatures': 'error', + '@typescript-eslint/array-type': 'error', + '@typescript-eslint/await-thenable': 'error', + '@typescript-eslint/ban-ts-comment': 'error', + '@typescript-eslint/ban-types': 'error', + 'brace-style': 'off', + '@typescript-eslint/brace-style': 'error', + '@typescript-eslint/class-literal-property-style': 'error', + 'comma-spacing': 'off', + '@typescript-eslint/comma-spacing': 'error', + '@typescript-eslint/consistent-type-assertions': 'error', + '@typescript-eslint/consistent-type-definitions': 'error', + 'default-param-last': 'off', + '@typescript-eslint/default-param-last': 'error', + 'dot-notation': 'off', + '@typescript-eslint/dot-notation': 'error', + '@typescript-eslint/explicit-function-return-type': 'error', + '@typescript-eslint/explicit-member-accessibility': 'error', + '@typescript-eslint/explicit-module-boundary-types': 'error', + 'func-call-spacing': 'off', + '@typescript-eslint/func-call-spacing': 'error', + indent: 'off', + '@typescript-eslint/indent': 'error', + 'init-declarations': 'off', + '@typescript-eslint/init-declarations': 'error', + 'keyword-spacing': 'off', + '@typescript-eslint/keyword-spacing': 'error', + 'lines-between-class-members': 'off', + '@typescript-eslint/lines-between-class-members': 'error', + '@typescript-eslint/member-delimiter-style': 'error', + '@typescript-eslint/member-ordering': 'error', + '@typescript-eslint/method-signature-style': 'error', + '@typescript-eslint/naming-convention': 'error', + 'no-array-constructor': 'off', + '@typescript-eslint/no-array-constructor': 'error', + '@typescript-eslint/no-base-to-string': 'error', + 'no-dupe-class-members': 'off', + '@typescript-eslint/no-dupe-class-members': 'error', + '@typescript-eslint/no-dynamic-delete': 'error', + 'no-empty-function': 'off', + '@typescript-eslint/no-empty-function': 'error', + '@typescript-eslint/no-empty-interface': 'error', + '@typescript-eslint/no-explicit-any': 'error', + '@typescript-eslint/no-extra-non-null-assertion': 'error', + 'no-extra-parens': 'off', + '@typescript-eslint/no-extra-parens': 'error', + 'no-extra-semi': 'off', + '@typescript-eslint/no-extra-semi': 'error', + '@typescript-eslint/no-extraneous-class': 'error', + '@typescript-eslint/no-floating-promises': 'error', + '@typescript-eslint/no-for-in-array': 'error', + '@typescript-eslint/no-implied-eval': 'error', + '@typescript-eslint/no-inferrable-types': 'error', + 'no-invalid-this': 'off', + '@typescript-eslint/no-invalid-this': 'error', + '@typescript-eslint/no-invalid-void-type': 'error', + 'no-magic-numbers': 'off', + '@typescript-eslint/no-magic-numbers': 'error', + '@typescript-eslint/no-misused-new': 'error', + '@typescript-eslint/no-misused-promises': 'error', + '@typescript-eslint/no-namespace': 'error', + '@typescript-eslint/no-non-null-asserted-optional-chain': 'error', + '@typescript-eslint/no-non-null-assertion': 'error', + '@typescript-eslint/no-parameter-properties': 'error', + '@typescript-eslint/no-require-imports': 'error', + '@typescript-eslint/no-this-alias': 'error', + '@typescript-eslint/no-throw-literal': 'error', + '@typescript-eslint/no-type-alias': 'error', + '@typescript-eslint/no-unnecessary-boolean-literal-compare': 'error', + '@typescript-eslint/no-unnecessary-condition': 'error', + '@typescript-eslint/no-unnecessary-qualifier': 'error', + '@typescript-eslint/no-unnecessary-type-arguments': 'error', + '@typescript-eslint/no-unnecessary-type-assertion': 'error', + '@typescript-eslint/no-unsafe-assignment': 'error', + '@typescript-eslint/no-unsafe-call': 'error', + '@typescript-eslint/no-unsafe-member-access': 'error', + '@typescript-eslint/no-unsafe-return': 'error', + 'no-unused-expressions': 'off', + '@typescript-eslint/no-unused-expressions': 'error', + 'no-unused-vars': 'off', + '@typescript-eslint/no-unused-vars': 'error', + '@typescript-eslint/no-unused-vars-experimental': 'error', + 'no-use-before-define': 'off', + '@typescript-eslint/no-use-before-define': 'error', + 'no-useless-constructor': 'off', + '@typescript-eslint/no-useless-constructor': 'error', + '@typescript-eslint/no-var-requires': 'error', + '@typescript-eslint/prefer-as-const': 'error', + '@typescript-eslint/prefer-for-of': 'error', + '@typescript-eslint/prefer-function-type': 'error', + '@typescript-eslint/prefer-includes': 'error', + '@typescript-eslint/prefer-namespace-keyword': 'error', + '@typescript-eslint/prefer-nullish-coalescing': 'error', + '@typescript-eslint/prefer-optional-chain': 'error', + '@typescript-eslint/prefer-readonly': 'error', + '@typescript-eslint/prefer-readonly-parameter-types': 'error', + '@typescript-eslint/prefer-reduce-type-parameter': 'error', + '@typescript-eslint/prefer-regexp-exec': 'error', + '@typescript-eslint/prefer-string-starts-ends-with': 'error', + '@typescript-eslint/prefer-ts-expect-error': 'error', + '@typescript-eslint/promise-function-async': 'error', + quotes: 'off', + '@typescript-eslint/quotes': 'error', + '@typescript-eslint/require-array-sort-compare': 'error', + 'require-await': 'off', + '@typescript-eslint/require-await': 'error', + '@typescript-eslint/restrict-plus-operands': 'error', + '@typescript-eslint/restrict-template-expressions': 'error', + 'no-return-await': 'off', + '@typescript-eslint/return-await': 'error', + semi: 'off', + '@typescript-eslint/semi': 'error', + 'space-before-function-paren': 'off', + '@typescript-eslint/space-before-function-paren': 'error', + '@typescript-eslint/strict-boolean-expressions': 'error', + '@typescript-eslint/switch-exhaustiveness-check': 'error', + '@typescript-eslint/triple-slash-reference': 'error', + '@typescript-eslint/type-annotation-spacing': 'error', + '@typescript-eslint/typedef': 'error', + '@typescript-eslint/unbound-method': 'error', + '@typescript-eslint/unified-signatures': 'error', + }, +}; diff --git a/packages/eslint-plugin/src/configs/base.json b/packages/eslint-plugin/src/configs/base.json deleted file mode 100644 index 9580ed622cf..00000000000 --- a/packages/eslint-plugin/src/configs/base.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "parser": "@typescript-eslint/parser", - "parserOptions": { "sourceType": "module" }, - "plugins": ["@typescript-eslint"] -} diff --git a/packages/eslint-plugin/src/configs/base.ts b/packages/eslint-plugin/src/configs/base.ts new file mode 100644 index 00000000000..652bf9db1ee --- /dev/null +++ b/packages/eslint-plugin/src/configs/base.ts @@ -0,0 +1,5 @@ +export = { + parser: '@typescript-eslint/parser', + parserOptions: { sourceType: 'module' }, + plugins: ['@typescript-eslint'], +}; diff --git a/packages/eslint-plugin/src/configs/eslint-recommended.ts b/packages/eslint-plugin/src/configs/eslint-recommended.ts index 4999a528bdf..125c093b2bc 100644 --- a/packages/eslint-plugin/src/configs/eslint-recommended.ts +++ b/packages/eslint-plugin/src/configs/eslint-recommended.ts @@ -1,8 +1,9 @@ /** - * This is a compatibility ruleset that disables rules from eslint:recommended - * which are already handled by TypeScript. + * This is a compatibility ruleset that: + * - disables rules from eslint:recommended which are already handled by TypeScript. + * - enables rules that make sense due to TS's typechecking / transpilation. */ -export default { +export = { overrides: [ { files: ['*.ts', '*.tsx'], @@ -14,6 +15,7 @@ export default { 'no-dupe-class-members': 'off', // ts(2393) & ts(2300) 'no-dupe-keys': 'off', // ts(1117) 'no-func-assign': 'off', // ts(2539) + 'no-import-assign': 'off', // ts(2539) & ts(2540) 'no-new-symbol': 'off', // ts(2588) 'no-obj-calls': 'off', // ts(2349) 'no-redeclare': 'off', // ts(2451) @@ -22,6 +24,10 @@ export default { 'no-undef': 'off', // ts(2304) 'no-unreachable': 'off', // ts(7027) 'no-unsafe-negation': 'off', // ts(2365) & ts(2360) & ts(2358) + 'no-var': 'error', // ts transpiles let/const to var, so no need for vars any more + 'prefer-const': 'error', // ts provides better types with const + 'prefer-rest-params': 'error', // ts provides better types with rest args over arguments + 'prefer-spread': 'error', // ts transpiles spread to apply, so no need for manual apply 'valid-typeof': 'off', // ts(2367) }, }, diff --git a/packages/eslint-plugin/src/configs/recommended-requiring-type-checking.json b/packages/eslint-plugin/src/configs/recommended-requiring-type-checking.json deleted file mode 100644 index 68867b53248..00000000000 --- a/packages/eslint-plugin/src/configs/recommended-requiring-type-checking.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "extends": "./configs/base.json", - "rules": { - "@typescript-eslint/await-thenable": "error", - "@typescript-eslint/no-for-in-array": "error", - "@typescript-eslint/no-misused-promises": "error", - "@typescript-eslint/no-unnecessary-type-assertion": "error", - "@typescript-eslint/prefer-includes": "error", - "@typescript-eslint/prefer-regexp-exec": "error", - "@typescript-eslint/prefer-string-starts-ends-with": "error", - "require-await": "off", - "@typescript-eslint/require-await": "error", - "@typescript-eslint/unbound-method": "error", - "no-var": "error", - "prefer-const": "error", - "prefer-rest-params": "error", - "prefer-spread": "error" - } -} diff --git a/packages/eslint-plugin/src/configs/recommended-requiring-type-checking.ts b/packages/eslint-plugin/src/configs/recommended-requiring-type-checking.ts new file mode 100644 index 00000000000..57e29f3e401 --- /dev/null +++ b/packages/eslint-plugin/src/configs/recommended-requiring-type-checking.ts @@ -0,0 +1,21 @@ +export = { + extends: ['./configs/base', './configs/eslint-recommended'], + rules: { + '@typescript-eslint/await-thenable': 'error', + '@typescript-eslint/no-floating-promises': 'error', + '@typescript-eslint/no-for-in-array': 'error', + '@typescript-eslint/no-implied-eval': 'error', + '@typescript-eslint/no-misused-promises': 'error', + '@typescript-eslint/no-unnecessary-type-assertion': 'error', + '@typescript-eslint/no-unsafe-assignment': 'error', + '@typescript-eslint/no-unsafe-call': 'error', + '@typescript-eslint/no-unsafe-member-access': 'error', + '@typescript-eslint/no-unsafe-return': 'error', + '@typescript-eslint/prefer-regexp-exec': 'error', + 'require-await': 'off', + '@typescript-eslint/require-await': 'error', + '@typescript-eslint/restrict-plus-operands': 'error', + '@typescript-eslint/restrict-template-expressions': 'error', + '@typescript-eslint/unbound-method': 'error', + }, +}; diff --git a/packages/eslint-plugin/src/configs/recommended.json b/packages/eslint-plugin/src/configs/recommended.json deleted file mode 100644 index 7d7a5628c9d..00000000000 --- a/packages/eslint-plugin/src/configs/recommended.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "extends": "./configs/base.json", - "rules": { - "@typescript-eslint/adjacent-overload-signatures": "error", - "@typescript-eslint/ban-ts-ignore": "error", - "@typescript-eslint/ban-types": "error", - "camelcase": "off", - "@typescript-eslint/camelcase": "error", - "@typescript-eslint/class-name-casing": "error", - "@typescript-eslint/consistent-type-assertions": "error", - "@typescript-eslint/explicit-function-return-type": "warn", - "@typescript-eslint/interface-name-prefix": "error", - "@typescript-eslint/member-delimiter-style": "error", - "no-array-constructor": "off", - "@typescript-eslint/no-array-constructor": "error", - "no-empty-function": "off", - "@typescript-eslint/no-empty-function": "error", - "@typescript-eslint/no-empty-interface": "error", - "@typescript-eslint/no-explicit-any": "warn", - "@typescript-eslint/no-inferrable-types": "error", - "@typescript-eslint/no-misused-new": "error", - "@typescript-eslint/no-namespace": "error", - "@typescript-eslint/no-non-null-assertion": "warn", - "@typescript-eslint/no-this-alias": "error", - "no-unused-vars": "off", - "@typescript-eslint/no-unused-vars": "warn", - "no-use-before-define": "off", - "@typescript-eslint/no-use-before-define": "error", - "@typescript-eslint/no-var-requires": "error", - "@typescript-eslint/prefer-namespace-keyword": "error", - "@typescript-eslint/triple-slash-reference": "error", - "@typescript-eslint/type-annotation-spacing": "error", - "no-var": "error", - "prefer-const": "error", - "prefer-rest-params": "error", - "prefer-spread": "error" - } -} diff --git a/packages/eslint-plugin/src/configs/recommended.ts b/packages/eslint-plugin/src/configs/recommended.ts new file mode 100644 index 00000000000..8aac1a8a3b0 --- /dev/null +++ b/packages/eslint-plugin/src/configs/recommended.ts @@ -0,0 +1,30 @@ +export = { + extends: ['./configs/base', './configs/eslint-recommended'], + rules: { + '@typescript-eslint/adjacent-overload-signatures': 'error', + '@typescript-eslint/ban-ts-comment': 'error', + '@typescript-eslint/ban-types': 'error', + '@typescript-eslint/explicit-module-boundary-types': 'warn', + 'no-array-constructor': 'off', + '@typescript-eslint/no-array-constructor': 'error', + 'no-empty-function': 'off', + '@typescript-eslint/no-empty-function': 'error', + '@typescript-eslint/no-empty-interface': 'error', + '@typescript-eslint/no-explicit-any': 'warn', + '@typescript-eslint/no-extra-non-null-assertion': 'error', + 'no-extra-semi': 'off', + '@typescript-eslint/no-extra-semi': 'error', + '@typescript-eslint/no-inferrable-types': 'error', + '@typescript-eslint/no-misused-new': 'error', + '@typescript-eslint/no-namespace': 'error', + '@typescript-eslint/no-non-null-asserted-optional-chain': 'error', + '@typescript-eslint/no-non-null-assertion': 'warn', + '@typescript-eslint/no-this-alias': 'error', + 'no-unused-vars': 'off', + '@typescript-eslint/no-unused-vars': 'warn', + '@typescript-eslint/no-var-requires': 'error', + '@typescript-eslint/prefer-as-const': 'error', + '@typescript-eslint/prefer-namespace-keyword': 'error', + '@typescript-eslint/triple-slash-reference': 'error', + }, +}; diff --git a/packages/eslint-plugin/src/index.ts b/packages/eslint-plugin/src/index.ts index d8e55844e1d..a812b44eb7a 100644 --- a/packages/eslint-plugin/src/index.ts +++ b/packages/eslint-plugin/src/index.ts @@ -1,9 +1,9 @@ import rules from './rules'; -import all from './configs/all.json'; -import base from './configs/base.json'; -import recommended from './configs/recommended.json'; -import recommendedRequiringTypeChecking from './configs/recommended-requiring-type-checking.json'; +import all from './configs/all'; +import base from './configs/base'; +import recommended from './configs/recommended'; +import recommendedRequiringTypeChecking from './configs/recommended-requiring-type-checking'; import eslintRecommended from './configs/eslint-recommended'; export = { diff --git a/packages/eslint-plugin/src/rules/ban-ts-comment.ts b/packages/eslint-plugin/src/rules/ban-ts-comment.ts index a422349eefa..bcbc02e9a0a 100644 --- a/packages/eslint-plugin/src/rules/ban-ts-comment.ts +++ b/packages/eslint-plugin/src/rules/ban-ts-comment.ts @@ -26,7 +26,7 @@ export default util.createRule<[Options], MessageIds>({ docs: { description: 'Bans `// @ts-` comments from being used', category: 'Best Practices', - recommended: false, + recommended: 'error', }, messages: { tsDirectiveComment: diff --git a/packages/eslint-plugin/src/rules/ban-ts-ignore.ts b/packages/eslint-plugin/src/rules/ban-ts-ignore.ts index 551bb0401a9..bbeadfe5269 100644 --- a/packages/eslint-plugin/src/rules/ban-ts-ignore.ts +++ b/packages/eslint-plugin/src/rules/ban-ts-ignore.ts @@ -8,7 +8,7 @@ export default util.createRule({ docs: { description: 'Bans “// @ts-ignore” comments from being used', category: 'Best Practices', - recommended: 'error', + recommended: false, }, schema: [], messages: { diff --git a/packages/eslint-plugin/src/rules/camelcase.ts b/packages/eslint-plugin/src/rules/camelcase.ts index 0c3ba619a42..7d8c179f2b9 100644 --- a/packages/eslint-plugin/src/rules/camelcase.ts +++ b/packages/eslint-plugin/src/rules/camelcase.ts @@ -28,7 +28,7 @@ export default util.createRule({ docs: { description: 'Enforce camelCase naming convention', category: 'Stylistic Issues', - recommended: 'error', + recommended: false, extendsBaseRule: true, }, deprecated: true, diff --git a/packages/eslint-plugin/src/rules/class-name-casing.ts b/packages/eslint-plugin/src/rules/class-name-casing.ts index 6326f1910e1..5871f47db92 100644 --- a/packages/eslint-plugin/src/rules/class-name-casing.ts +++ b/packages/eslint-plugin/src/rules/class-name-casing.ts @@ -18,7 +18,7 @@ export default util.createRule({ docs: { description: 'Require PascalCased class and interface names', category: 'Best Practices', - recommended: 'error', + recommended: false, }, deprecated: true, replacedBy: ['naming-convention'], diff --git a/packages/eslint-plugin/src/rules/consistent-type-assertions.ts b/packages/eslint-plugin/src/rules/consistent-type-assertions.ts index 2457bdb08a9..cc96778cbe0 100644 --- a/packages/eslint-plugin/src/rules/consistent-type-assertions.ts +++ b/packages/eslint-plugin/src/rules/consistent-type-assertions.ts @@ -27,7 +27,7 @@ export default util.createRule({ docs: { category: 'Best Practices', description: 'Enforces consistent usage of type assertions', - recommended: 'error', + recommended: false, }, messages: { as: "Use 'as {{cast}}' instead of '<{{cast}}>'.", diff --git a/packages/eslint-plugin/src/rules/explicit-function-return-type.ts b/packages/eslint-plugin/src/rules/explicit-function-return-type.ts index f0a5978d02f..f0904f07744 100644 --- a/packages/eslint-plugin/src/rules/explicit-function-return-type.ts +++ b/packages/eslint-plugin/src/rules/explicit-function-return-type.ts @@ -27,7 +27,7 @@ export default util.createRule({ description: 'Require explicit return types on functions and class methods', category: 'Stylistic Issues', - recommended: 'warn', + recommended: false, }, messages: { missingReturnType: 'Missing return type on function.', diff --git a/packages/eslint-plugin/src/rules/explicit-module-boundary-types.ts b/packages/eslint-plugin/src/rules/explicit-module-boundary-types.ts index b00d8eb1087..265010adc6d 100644 --- a/packages/eslint-plugin/src/rules/explicit-module-boundary-types.ts +++ b/packages/eslint-plugin/src/rules/explicit-module-boundary-types.ts @@ -29,7 +29,7 @@ export default util.createRule({ description: "Require explicit return and argument types on exported functions' and classes' public class methods", category: 'Stylistic Issues', - recommended: false, + recommended: 'warn', }, messages: { missingReturnType: 'Missing return type on function.', diff --git a/packages/eslint-plugin/src/rules/interface-name-prefix.ts b/packages/eslint-plugin/src/rules/interface-name-prefix.ts index 493c5e73124..281a9eb6197 100644 --- a/packages/eslint-plugin/src/rules/interface-name-prefix.ts +++ b/packages/eslint-plugin/src/rules/interface-name-prefix.ts @@ -45,9 +45,7 @@ export default util.createRule({ description: 'Require that interface names should or should not prefixed with `I`', category: 'Stylistic Issues', - // this will always be recommended as there's no reason to use this convention - // https://github.com/typescript-eslint/typescript-eslint/issues/374 - recommended: 'error', + recommended: false, }, deprecated: true, replacedBy: ['naming-convention'], diff --git a/packages/eslint-plugin/src/rules/member-delimiter-style.ts b/packages/eslint-plugin/src/rules/member-delimiter-style.ts index 98781d2b864..75381a8df2c 100644 --- a/packages/eslint-plugin/src/rules/member-delimiter-style.ts +++ b/packages/eslint-plugin/src/rules/member-delimiter-style.ts @@ -61,7 +61,7 @@ export default util.createRule({ description: 'Require a specific member delimiter style for interfaces and type literals', category: 'Stylistic Issues', - recommended: 'error', + recommended: false, }, fixable: 'code', messages: { diff --git a/packages/eslint-plugin/src/rules/naming-convention.ts b/packages/eslint-plugin/src/rules/naming-convention.ts index 69791b205c5..59b1bdfee80 100644 --- a/packages/eslint-plugin/src/rules/naming-convention.ts +++ b/packages/eslint-plugin/src/rules/naming-convention.ts @@ -21,7 +21,6 @@ enum PredefinedFormats { strictCamelCase = 1 << 1, PascalCase = 1 << 2, StrictPascalCase = 1 << 3, - // eslint-disable-next-line @typescript-eslint/camelcase snake_case = 1 << 4, UPPER_CASE = 1 << 5, } @@ -1080,14 +1079,12 @@ https://gist.github.com/mathiasbynens/6334847 function isPascalCase(name: string): boolean { return ( name.length === 0 || - // eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with (name[0] === name[0].toUpperCase() && !name.includes('_')) ); } function isStrictPascalCase(name: string): boolean { return ( name.length === 0 || - // eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with (name[0] === name[0].toUpperCase() && hasStrictCamelHumps(name, true)) ); } @@ -1095,14 +1092,12 @@ function isStrictPascalCase(name: string): boolean { function isCamelCase(name: string): boolean { return ( name.length === 0 || - // eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with (name[0] === name[0].toLowerCase() && !name.includes('_')) ); } function isStrictCamelCase(name: string): boolean { return ( name.length === 0 || - // eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with (name[0] === name[0].toLowerCase() && hasStrictCamelHumps(name, false)) ); } diff --git a/packages/eslint-plugin/src/rules/no-extra-non-null-assertion.ts b/packages/eslint-plugin/src/rules/no-extra-non-null-assertion.ts index 44182650d14..def33bbb827 100644 --- a/packages/eslint-plugin/src/rules/no-extra-non-null-assertion.ts +++ b/packages/eslint-plugin/src/rules/no-extra-non-null-assertion.ts @@ -8,7 +8,7 @@ export default util.createRule({ docs: { description: 'Disallow extra non-null assertion', category: 'Stylistic Issues', - recommended: false, + recommended: 'error', }, fixable: 'code', schema: [], diff --git a/packages/eslint-plugin/src/rules/no-extra-semi.ts b/packages/eslint-plugin/src/rules/no-extra-semi.ts index 6481b8ac7ed..d1ffdf61d8d 100644 --- a/packages/eslint-plugin/src/rules/no-extra-semi.ts +++ b/packages/eslint-plugin/src/rules/no-extra-semi.ts @@ -11,7 +11,7 @@ export default util.createRule({ docs: { description: 'Disallow unnecessary semicolons', category: 'Possible Errors', - recommended: false, + recommended: 'error', extendsBaseRule: true, }, fixable: 'code', diff --git a/packages/eslint-plugin/src/rules/no-floating-promises.ts b/packages/eslint-plugin/src/rules/no-floating-promises.ts index 615f88f25df..2a0c86e5011 100644 --- a/packages/eslint-plugin/src/rules/no-floating-promises.ts +++ b/packages/eslint-plugin/src/rules/no-floating-promises.ts @@ -23,7 +23,7 @@ export default util.createRule({ docs: { description: 'Requires Promise-like values to be handled appropriately', category: 'Best Practices', - recommended: false, + recommended: 'error', suggestion: true, requiresTypeChecking: true, }, diff --git a/packages/eslint-plugin/src/rules/no-implied-eval.ts b/packages/eslint-plugin/src/rules/no-implied-eval.ts index 0f611859786..d983065d5b2 100644 --- a/packages/eslint-plugin/src/rules/no-implied-eval.ts +++ b/packages/eslint-plugin/src/rules/no-implied-eval.ts @@ -20,7 +20,7 @@ export default util.createRule({ docs: { description: 'Disallow the use of `eval()`-like methods', category: 'Best Practices', - recommended: false, + recommended: 'error', requiresTypeChecking: true, }, messages: { diff --git a/packages/eslint-plugin/src/rules/no-non-null-asserted-optional-chain.ts b/packages/eslint-plugin/src/rules/no-non-null-asserted-optional-chain.ts index 9ebc2d6a61f..fa14fa661b6 100644 --- a/packages/eslint-plugin/src/rules/no-non-null-asserted-optional-chain.ts +++ b/packages/eslint-plugin/src/rules/no-non-null-asserted-optional-chain.ts @@ -22,7 +22,7 @@ export default util.createRule<[], MessageIds>({ description: 'Disallows using a non-null assertion after an optional chain expression', category: 'Possible Errors', - recommended: false, + recommended: 'error', suggestion: true, }, messages: { diff --git a/packages/eslint-plugin/src/rules/no-unsafe-assignment.ts b/packages/eslint-plugin/src/rules/no-unsafe-assignment.ts index 638d3036311..e581862b0ed 100644 --- a/packages/eslint-plugin/src/rules/no-unsafe-assignment.ts +++ b/packages/eslint-plugin/src/rules/no-unsafe-assignment.ts @@ -21,7 +21,7 @@ export default util.createRule({ docs: { description: 'Disallows assigning any to variables and properties', category: 'Possible Errors', - recommended: false, + recommended: 'error', requiresTypeChecking: true, }, messages: { diff --git a/packages/eslint-plugin/src/rules/no-unsafe-call.ts b/packages/eslint-plugin/src/rules/no-unsafe-call.ts index 4cd12370822..43ca4a0140f 100644 --- a/packages/eslint-plugin/src/rules/no-unsafe-call.ts +++ b/packages/eslint-plugin/src/rules/no-unsafe-call.ts @@ -10,7 +10,7 @@ export default util.createRule<[], MessageIds>({ docs: { description: 'Disallows calling an any type value', category: 'Possible Errors', - recommended: false, + recommended: 'error', requiresTypeChecking: true, }, messages: { diff --git a/packages/eslint-plugin/src/rules/no-unsafe-member-access.ts b/packages/eslint-plugin/src/rules/no-unsafe-member-access.ts index a17818efb41..c6280dea92c 100644 --- a/packages/eslint-plugin/src/rules/no-unsafe-member-access.ts +++ b/packages/eslint-plugin/src/rules/no-unsafe-member-access.ts @@ -16,7 +16,7 @@ export default util.createRule({ docs: { description: 'Disallows member access on any typed variables', category: 'Possible Errors', - recommended: false, + recommended: 'error', requiresTypeChecking: true, }, messages: { diff --git a/packages/eslint-plugin/src/rules/no-unsafe-return.ts b/packages/eslint-plugin/src/rules/no-unsafe-return.ts index 53429898da4..b0168dc6f50 100644 --- a/packages/eslint-plugin/src/rules/no-unsafe-return.ts +++ b/packages/eslint-plugin/src/rules/no-unsafe-return.ts @@ -12,7 +12,7 @@ export default util.createRule({ docs: { description: 'Disallows returning any from a function', category: 'Possible Errors', - recommended: false, + recommended: 'error', requiresTypeChecking: true, }, messages: { diff --git a/packages/eslint-plugin/src/rules/no-use-before-define.ts b/packages/eslint-plugin/src/rules/no-use-before-define.ts index 2c66ec1ee5a..ed0240082d2 100644 --- a/packages/eslint-plugin/src/rules/no-use-before-define.ts +++ b/packages/eslint-plugin/src/rules/no-use-before-define.ts @@ -177,7 +177,7 @@ export default util.createRule({ docs: { description: 'Disallow the use of variables before they are defined', category: 'Variables', - recommended: 'error', + recommended: false, extendsBaseRule: true, }, messages: { diff --git a/packages/eslint-plugin/src/rules/prefer-as-const.ts b/packages/eslint-plugin/src/rules/prefer-as-const.ts index 9fb619b74b5..91f43242021 100644 --- a/packages/eslint-plugin/src/rules/prefer-as-const.ts +++ b/packages/eslint-plugin/src/rules/prefer-as-const.ts @@ -12,7 +12,7 @@ export default util.createRule({ docs: { description: 'Prefer usage of `as const` over literal type', category: 'Best Practices', - recommended: false, + recommended: 'error', suggestion: true, }, fixable: 'code', diff --git a/packages/eslint-plugin/src/rules/prefer-includes.ts b/packages/eslint-plugin/src/rules/prefer-includes.ts index 5b3b1c19b87..721c53850df 100644 --- a/packages/eslint-plugin/src/rules/prefer-includes.ts +++ b/packages/eslint-plugin/src/rules/prefer-includes.ts @@ -15,7 +15,7 @@ export default createRule({ docs: { description: 'Enforce `includes` method over `indexOf` method', category: 'Best Practices', - recommended: 'error', + recommended: false, requiresTypeChecking: true, }, fixable: 'code', diff --git a/packages/eslint-plugin/src/rules/prefer-string-starts-ends-with.ts b/packages/eslint-plugin/src/rules/prefer-string-starts-ends-with.ts index 795c877a8e3..90b38f18e78 100644 --- a/packages/eslint-plugin/src/rules/prefer-string-starts-ends-with.ts +++ b/packages/eslint-plugin/src/rules/prefer-string-starts-ends-with.ts @@ -26,7 +26,7 @@ export default createRule({ description: 'Enforce the use of `String#startsWith` and `String#endsWith` instead of other equivalent methods of checking substrings', category: 'Best Practices', - recommended: 'error', + recommended: false, requiresTypeChecking: true, }, messages: { @@ -87,7 +87,6 @@ export default createRule({ evaluated != null && typeof evaluated.value === 'string' && // checks if the string is a character long - // eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with evaluated.value[0] === evaluated.value ); } diff --git a/packages/eslint-plugin/src/rules/restrict-plus-operands.ts b/packages/eslint-plugin/src/rules/restrict-plus-operands.ts index 2702009046f..0917484ea02 100644 --- a/packages/eslint-plugin/src/rules/restrict-plus-operands.ts +++ b/packages/eslint-plugin/src/rules/restrict-plus-operands.ts @@ -17,7 +17,7 @@ export default util.createRule({ description: 'When adding two variables, operands must both be of type number or of type string', category: 'Best Practices', - recommended: false, + recommended: 'error', requiresTypeChecking: true, }, messages: { diff --git a/packages/eslint-plugin/src/rules/restrict-template-expressions.ts b/packages/eslint-plugin/src/rules/restrict-template-expressions.ts index 6ba846ed598..aeda73af521 100644 --- a/packages/eslint-plugin/src/rules/restrict-template-expressions.ts +++ b/packages/eslint-plugin/src/rules/restrict-template-expressions.ts @@ -23,7 +23,7 @@ export default util.createRule({ docs: { description: 'Enforce template literal expressions to be of string type', category: 'Best Practices', - recommended: false, + recommended: 'error', requiresTypeChecking: true, }, messages: { diff --git a/packages/eslint-plugin/src/rules/type-annotation-spacing.ts b/packages/eslint-plugin/src/rules/type-annotation-spacing.ts index b33ec8fd7b4..985e008c16d 100644 --- a/packages/eslint-plugin/src/rules/type-annotation-spacing.ts +++ b/packages/eslint-plugin/src/rules/type-annotation-spacing.ts @@ -114,7 +114,7 @@ export default util.createRule({ docs: { description: 'Require consistent spacing around type annotations', category: 'Stylistic Issues', - recommended: 'error', + recommended: false, }, fixable: 'whitespace', messages: { diff --git a/packages/eslint-plugin/tests/rules/naming-convention.test.ts b/packages/eslint-plugin/tests/rules/naming-convention.test.ts index b4326c8fe75..3787dd4acdd 100644 --- a/packages/eslint-plugin/tests/rules/naming-convention.test.ts +++ b/packages/eslint-plugin/tests/rules/naming-convention.test.ts @@ -67,7 +67,6 @@ const formatTestNames: Readonly a[0].localeCompare(b[0]), @@ -122,8 +116,9 @@ function reducer( * Helper function writes configuration. */ function writeConfig(config: LinterConfig, filePath: string): void { - const configStr = format(JSON.stringify(config), { - parser: 'json', + const code = `export = ${JSON.stringify(config)};`; + const configStr = format(code, { + parser: 'typescript', ...prettierConfig, }); fs.writeFileSync(filePath, configStr); @@ -136,25 +131,25 @@ const baseConfig: LinterConfig = { }, plugins: ['@typescript-eslint'], }; -writeConfig(baseConfig, path.resolve(__dirname, '../src/configs/base.json')); +writeConfig(baseConfig, path.resolve(__dirname, '../src/configs/base.ts')); console.log(); console.log( - '------------------------------------------------ all.json ------------------------------------------------', + '------------------------------------------------ all.ts ------------------------------------------------', ); const allConfig: LinterConfig = { - extends: './configs/base.json', + extends: EXTENDS, rules: ruleEntries.reduce( (config, entry) => reducer(config, entry, { errorLevel: 'error', filterDeprecated: true }), {}, ), }; -writeConfig(allConfig, path.resolve(__dirname, '../src/configs/all.json')); +writeConfig(allConfig, path.resolve(__dirname, '../src/configs/all.ts')); console.log(); console.log( - '------------------------------ recommended.json (should not require program) ------------------------------', + '------------------------------ recommended.ts (should not require program) ------------------------------', ); const recommendedRules = ruleEntries .filter(entry => !!entry[1].meta.docs?.recommended) @@ -166,21 +161,18 @@ const recommendedRules = ruleEntries }), {}, ); -BASE_RULES_THAT_ARE_RECOMMENDED.forEach(ruleName => { - recommendedRules[ruleName] = 'error'; -}); const recommendedConfig: LinterConfig = { - extends: './configs/base.json', + extends: EXTENDS, rules: recommendedRules, }; writeConfig( recommendedConfig, - path.resolve(__dirname, '../src/configs/recommended.json'), + path.resolve(__dirname, '../src/configs/recommended.ts'), ); console.log(); console.log( - '--------------------------------- recommended-requiring-type-checking.json ---------------------------------', + '--------------------------------- recommended-requiring-type-checking.ts ---------------------------------', ); const recommendedRulesRequiringProgram = ruleEntries .filter(entry => !!entry[1].meta.docs?.recommended) @@ -192,17 +184,14 @@ const recommendedRulesRequiringProgram = ruleEntries }), {}, ); -BASE_RULES_THAT_ARE_RECOMMENDED.forEach(ruleName => { - recommendedRulesRequiringProgram[ruleName] = 'error'; -}); const recommendedRequiringTypeCheckingConfig: LinterConfig = { - extends: './configs/base.json', + extends: EXTENDS, rules: recommendedRulesRequiringProgram, }; writeConfig( recommendedRequiringTypeCheckingConfig, path.resolve( __dirname, - '../src/configs/recommended-requiring-type-checking.json', + '../src/configs/recommended-requiring-type-checking.ts', ), ); diff --git a/tools/generate-contributors.ts b/tools/generate-contributors.ts index c0f84c712a7..4c3c2b0a36d 100644 --- a/tools/generate-contributors.ts +++ b/tools/generate-contributors.ts @@ -91,7 +91,7 @@ async function main(): Promise { return { login: usr.login, name: usr.name || usr.login, - avatar_url: usr.avatar_url, // eslint-disable-line @typescript-eslint/camelcase + avatar_url: usr.avatar_url, profile: usr.html_url, contributions: [], };