From 32868b4c5771040def8767c503326c0d51426597 Mon Sep 17 00:00:00 2001 From: Preco Plusb Date: Sat, 2 Mar 2024 03:02:18 +0900 Subject: [PATCH] feat: update config --- index.js | 2 +- package.json | 2 +- react.js | 2 +- readme.md | 2 +- rules/base/layout-formatting.js | 141 +++++++++++++ rules/base/possible-problems.js | 79 +++++++ rules/base/suggestions.js | 195 ++++++++++++++++++ rules/base/{ => to-discard}/best-practices.js | 0 rules/base/{ => to-discard}/ecmascript-6.js | 0 .../base/{ => to-discard}/possible-errors.js | 2 +- rules/base/{ => to-discard}/strict-mode.js | 0 .../base/{ => to-discard}/stylistic-issues.js | 0 rules/base/{ => to-discard}/variables.js | 1 + rules/react.js | 9 +- rules/typescript.js | 49 ++--- rules/with-es5.js | 8 +- rules/with-no-restricted.js | 2 +- rules/with-sort-imports.js | 4 +- typescript-react.js | 2 +- typescript.js | 2 +- 20 files changed, 464 insertions(+), 38 deletions(-) create mode 100644 rules/base/layout-formatting.js create mode 100644 rules/base/possible-problems.js create mode 100644 rules/base/suggestions.js rename rules/base/{ => to-discard}/best-practices.js (100%) rename rules/base/{ => to-discard}/ecmascript-6.js (100%) rename rules/base/{ => to-discard}/possible-errors.js (97%) rename rules/base/{ => to-discard}/strict-mode.js (100%) rename rules/base/{ => to-discard}/stylistic-issues.js (100%) rename rules/base/{ => to-discard}/variables.js (95%) diff --git a/index.js b/index.js index 31a0d3b..560dd57 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,7 @@ module.exports = { es6: true, }, parserOptions: { - ecmaVersion: 2019, + ecmaVersion: 'latest', sourceType: 'module', }, extends: [ diff --git a/package.json b/package.json index bb9d065..3ed5e8c 100644 --- a/package.json +++ b/package.json @@ -77,7 +77,7 @@ "node": true }, "parserOptions": { - "ecmaVersion": 2019, + "ecmaVersion": "latest", "sourceType": "script" } } diff --git a/react.js b/react.js index 8375665..e2f38cd 100644 --- a/react.js +++ b/react.js @@ -5,7 +5,7 @@ module.exports = { es6: true, }, parserOptions: { - ecmaVersion: 2019, + ecmaVersion: 'latest', sourceType: 'module', }, extends: [ diff --git a/readme.md b/readme.md index 59eb2c1..82fc894 100644 --- a/readme.md +++ b/readme.md @@ -107,7 +107,7 @@ For example: "node": true }, "parserOptions": { - "ecmaVersion": 2019, + "ecmaVersion": "latest", "sourceType": "module" }, "extends": [ diff --git a/rules/base/layout-formatting.js b/rules/base/layout-formatting.js new file mode 100644 index 0000000..a4601e8 --- /dev/null +++ b/rules/base/layout-formatting.js @@ -0,0 +1,141 @@ +'use strict'; + +// DEPRECATED except unicode-bom and line-comment-position + +// https://eslint.org/blog/2023/10/deprecating-formatting-rules/ + +/** + * Layout & Formatting + * https://eslint.org/docs/latest/rules/#layout--formatting + */ +module.exports = { + rules: { + 'no-extra-parens': ['error', 'all', { + conditionalAssign: false, + returnAssign: false, + nestedBinaryExpressions: false, + ignoreJSX: 'all', + enforceForArrowConditionals: false, + enforceForSequenceExpressions: false, + enforceForNewInMemberExpressions: false, + enforceForFunctionPrototypeMethods: false, + }], + 'dot-location': ['error', 'property'], + 'no-multi-spaces': 'error', + // The `functionPrototypeMethods` option is enabled because using such + // expression without any assignment will end up in a syntax error as it may + // seem as a function declaration. + 'wrap-iife': ['error', 'inside', { functionPrototypeMethods: true }], + 'array-bracket-newline': ['error', 'consistent'], + 'array-bracket-spacing': 'error', + 'array-element-newline': ['error', 'consistent'], + 'block-spacing': 'error', + 'brace-style': ['error', '1tbs', { allowSingleLine: true }], + 'comma-dangle': ['error', 'always-multiline'], + 'comma-spacing': 'error', + 'comma-style': ['error', 'last', { + exceptions: { + ArrayExpression: false, + ArrayPattern: false, + ArrowFunctionExpression: false, + CallExpression: false, + FunctionDeclaration: false, + FunctionExpression: false, + ImportDeclaration: false, + ObjectExpression: false, + ObjectPattern: false, + VariableDeclaration: false, + NewExpression: false, + }, + }], + 'computed-property-spacing': 'error', + 'eol-last': 'error', + 'func-call-spacing': 'error', + 'function-call-argument-newline': ['error', 'consistent'], + // FIXME: Disabled due to the issue where it triggers false-positive in + // multiline generic functions in TypeScript. + // https://github.com/typescript-eslint/typescript-eslint/issues/942 + 'function-paren-newline': 'off', + // We encourage you to use long-form style function body when writing a + // function that contains long content which may be formed in multiline or + // break down into statements. doing so, you can manage the line length of + // code easily, resulting more readable code. + // use `() => { return LONG_CONTENT; }` instead of `() => LONG_CONTENT` + // or `() => ()` in JSX + 'implicit-arrow-linebreak': 'error', + 'indent': ['error', 2, { SwitchCase: 1 }], + 'jsx-quotes': 'off', + 'key-spacing': 'error', + 'keyword-spacing': 'error', + 'line-comment-position': 'off', + 'linebreak-style': 'error', + 'lines-around-comment': 'off', + // For long strings, you can use multiline string concatenation + // as `no-useless-concat` rule allows it. if you need string interpolation, + // you can use it in conjunction with template literals: + // 'very-long-class-name ' + + // 'another-long-class-name ' + `modifier-${x}` + 'lines-between-class-members': ['error', 'always', { exceptAfterSingleLine: true }], + 'max-len': ['warn', { + code: 100, + tabWidth: 2, + ignoreComments: true, + ignoreUrls: true, + ignoreStrings: true, + ignoreTemplateLiterals: true, + ignoreRegExpLiterals: true, + }], + 'max-statements-per-line': 'off', + 'multiline-ternary': ['error', 'always-multiline'], + // FIXME: + // disabled due to the issue where it causes some conflict with + // the fixer of `@typescript-eslint/comma-dangle` rule + // { a: new Date } -> { a: new Date,() } + 'new-parens': 'off', + 'newline-per-chained-call': 'off', + // Since we enforce separate variable declarations via `one-var` rule + // and `key-spacing rule for aligning properties with arbitrary spaces, it's + // safe to not include `smart-tabs` option. + 'no-mixed-spaces-and-tabs': 'error', + // leading and trailing empty lines may be trimmed by text editor + 'no-multiple-empty-lines': 'error', + 'no-tabs': 'error', + // leading and trailing spaces may be trimmed by text editor + 'no-trailing-spaces': 'warn', + 'no-whitespace-before-property': 'error', + // since our `curly` rule doesn't allow any nonblock-statement, we can + // safely disable this rule. + 'nonblock-statement-body-position': 'off', + // this rule doesn't really help placing braces in the right position. + // also, you often need to express object merging with spread syntax like this: + // const next = { ...existing, + // extra: 'foo', + // }; + 'object-curly-newline': 'off', + 'object-curly-spacing': ['error', 'always'], + 'object-property-newline': ['error', { allowAllPropertiesOnSameLine: true }], + 'operator-linebreak': 'error', + 'padded-blocks': ['error', 'never', { allowSingleLineBlocks: true }], + 'padding-line-between-statements': 'off', + // allowing double quotes for some edge cases, but always prefer single quotes + 'quotes': ['error', 'single', { avoidEscape: true, allowTemplateLiterals: true }], + 'semi': 'error', + 'semi-spacing': 'error', + 'semi-style': 'error', + 'switch-colon-spacing': 'error', + 'space-before-blocks': 'error', + 'space-before-function-paren': ['error', { anonymous: 'always', named: 'never', asyncArrow: 'always' }], + 'space-in-parens': 'error', + 'space-infix-ops': 'error', + 'space-unary-ops': 'error', + 'template-tag-spacing': 'error', + 'unicode-bom': 'error', + 'wrap-regex': 'off', + 'arrow-parens': 'error', + 'arrow-spacing': 'error', + 'generator-star-spacing': ['error', { before: false, after: true }], + 'rest-spread-spacing': 'error', + 'template-curly-spacing': 'error', + 'yield-star-spacing': 'error', + }, +}; diff --git a/rules/base/possible-problems.js b/rules/base/possible-problems.js new file mode 100644 index 0000000..8d5f654 --- /dev/null +++ b/rules/base/possible-problems.js @@ -0,0 +1,79 @@ +'use strict'; + +/** + * Possible Problems + * https://eslint.org/docs/latest/rules/#possible-problems + */ +module.exports = { + rules: { + 'array-callback-return': 'error', + 'constructor-super': 'error', + 'for-direction': 'error', + 'getter-return': 'error', + 'no-async-promise-executor': 'error', + // You may need to use `await` in loops for various purposes such as + // indefinite iteration, retrying (e.g., exponential backoff), throttling, + // and running a series of workflow jobs sequentially. + 'no-await-in-loop': 'off', + 'no-class-assign': 'error', + 'no-compare-neg-zero': 'error', + 'no-cond-assign': 'error', + 'no-const-assign': 'error', + 'no-constant-binary-expression': 'error', + // Use `for (;;) {}` for infinite loop + 'no-constant-condition': 'warn', + 'no-constructor-return': 'error', + 'no-control-regex': 'error', + 'no-debugger': 'error', + 'no-dupe-args': 'error', + 'no-dupe-class-members': 'error', + 'no-dupe-else-if': 'error', + 'no-dupe-keys': 'error', + 'no-duplicate-case': 'error', + 'no-duplicate-imports': 'off', + 'no-empty-character-class': 'error', + 'no-empty-pattern': 'error', + 'no-ex-assign': 'error', + 'no-fallthrough': 'error', + 'no-func-assign': 'error', + 'no-import-assign': 'error', + 'no-inner-declarations': 'error', + 'no-invalid-regexp': 'error', + 'no-irregular-whitespace': 'error', + 'no-loss-of-precision': 'warn', + 'no-misleading-character-class': 'error', + 'no-new-native-nonconstructor': 'error', + 'no-new-symbol': 'error', + 'no-obj-calls': 'error', + // This rule is disabled for situations where you may encounter edge cases while using `setTimeout()`, such as: + // await new Promise((resolve) => setTimeout(resolve, 300)); + 'no-promise-executor-return': 'off', + 'no-prototype-builtins': 'error', + 'no-self-assign': 'error', + 'no-self-compare': 'error', + 'no-setter-return': 'error', + 'no-sparse-arrays': 'error', + 'no-template-curly-in-string': 'error', + 'no-this-before-super': 'error', + 'no-undef': 'error', + 'no-unexpected-multiline': 'error', + 'no-unmodified-loop-condition': 'error', + 'no-unreachable-loop': 'error', + 'no-unreachable': 'error', + 'no-unsafe-finally': 'error', + 'no-unsafe-negation': 'error', + 'no-unsafe-optional-chaining': 'error', + 'no-unused-private-class-members': 'error', + 'no-unused-vars': ['error', { + argsIgnorePattern: '^_', + destructuredArrayIgnorePattern: '^_', + ignoreRestSiblings: true, + }], + 'no-use-before-define': ['error', { functions: false, variables: false }], + 'no-useless-backreference': 'error', + // FIXME: Enable once this issue is resolved: https://github.com/eslint/eslint/issues/11899 + 'require-atomic-updates': 'off', + 'use-isnan': 'error', + 'valid-typeof': ['error', { requireStringLiterals: true }], + }, +}; diff --git a/rules/base/suggestions.js b/rules/base/suggestions.js new file mode 100644 index 0000000..414d370 --- /dev/null +++ b/rules/base/suggestions.js @@ -0,0 +1,195 @@ +'use strict'; + +/** + * Suggestions + * https://eslint.org/docs/latest/rules/#suggestions + */ +module.exports = { + rules: { + 'accessor-pairs': 'off', + 'arrow-body-style': 'off', + 'block-scoped-var': 'error', + // If you need to use non-camelCase globals, surround them with `eslint-disable` comments. + 'camelcase': ['error', { properties: 'never' }], + 'capitalized-comments': 'off', + 'class-methods-use-this': 'off', + 'complexity': 'off', + // FIXME: Disabled due to the potential for false positives when used alongside TypeScript. + // See: https://github.com/typescript-eslint/typescript-eslint/issues/1277 + 'consistent-return': 'off', + 'consistent-this': 'off', + 'curly': 'error', + 'default-case': 'error', + 'default-case-last': 'error', + 'default-param-last': 'error', + 'dot-notation': 'off', + 'eqeqeq': ['error', 'always', { null: 'ignore' }], + 'func-name-matching': 'off', + 'func-names': ['warn', 'as-needed'], + // Prefer function declaration by default; use arrow functions for any other cases. + 'func-style': ['error', 'declaration', { allowArrowFunctions: true }], + 'grouped-accessor-pairs': 'error', + 'guard-for-in': 'off', + 'id-denylist': 'off', + 'id-length': 'off', + 'id-match': 'off', + 'init-declarations': 'off', + // FIXME: check + 'logical-assignment-operators': 'off', + 'max-classes-per-file': 'off', + 'max-depth': 'off', + 'max-lines': 'off', + 'max-lines-per-function': 'off', + 'max-nested-callbacks': 'off', + 'max-params': 'off', + 'max-statements': 'off', + 'multiline-comment-style': 'off', + 'new-cap': 'off', + 'no-alert': 'warn', + 'no-array-constructor': 'error', + 'no-bitwise': 'off', + 'no-caller': 'error', + 'no-case-declarations': 'error', + // FIXME: DEPRECATED + 'no-confusing-arrow': 'off', + 'no-console': ['warn', { allow: ['warn', 'error'] }], + 'no-continue': 'off', + 'no-delete-var': 'error', + 'no-div-regex': 'off', + 'no-else-return': 'off', + 'no-empty': 'error', + 'no-empty-function': 'error', + // FIXME: check + 'no-empty-static-block': 'off', + 'no-eq-null': 'off', + 'no-eval': 'error', + 'no-extend-native': 'error', + 'no-extra-bind': 'error', + 'no-extra-boolean-cast': 'error', + 'no-extra-label': 'error', + // FIXME: DEPRECATED + 'no-extra-semi': 'error', + // FIXME: DEPRECATED + 'no-floating-decimal': 'error', + 'no-global-assign': 'error', + 'no-implicit-coercion': 'error', + 'no-implicit-globals': 'off', + 'no-implied-eval': 'error', + 'no-inline-comments': 'off', + 'no-invalid-this': 'off', + 'no-iterator': 'error', + 'no-label-var': 'error', + 'no-labels': 'error', + 'no-lone-blocks': 'error', + 'no-lonely-if': 'off', + 'no-loop-func': 'error', + 'no-magic-numbers': 'off', + // FIXME: DEPRECATED + 'no-mixed-operators': 'off', + 'no-multi-assign': ['error', { ignoreNonDeclaration: true }], + 'no-multi-str': 'error', + 'no-negated-condition': 'off', + 'no-nested-ternary': 'error', + 'no-new': 'error', + 'no-new-func': 'error', + 'no-new-object': 'error', + 'no-new-wrappers': 'error', + 'no-nonoctal-decimal-escape': 'error', + 'no-octal': 'error', + 'no-octal-escape': 'error', + 'no-param-reassign': ['error', { props: false }], + 'no-plusplus': 'off', + 'no-proto': 'error', + 'no-redeclare': 'error', + 'no-regex-spaces': 'error', + 'no-restricted-exports': 'off', + // Can be enabled by `with-no-restricted` configuration + 'no-restricted-globals': 'off', + 'no-restricted-imports': 'off', + 'no-restricted-properties': 'off', + 'no-restricted-syntax': 'off', + 'no-return-assign': 'error', + 'no-return-await': 'warn', + 'no-script-url': 'off', + 'no-sequences': 'error', + 'no-shadow': 'off', + 'no-shadow-restricted-names': 'error', + 'no-ternary': 'off', + 'no-throw-literal': 'error', + 'no-undef-init': 'error', + 'no-undefined': 'off', + 'no-underscore-dangle': 'off', + // Prefer expressions like `a || b` over `a ? a : b` + 'no-unneeded-ternary': ['error', { defaultAssignment: false }], + // FIXME: This rule may cause false positives when using optional chaining. + // However, if you are using TypeScript with `typescript-eslint`, it will + // support it regardless. + // See: https://github.com/facebook/create-react-app/issues/8107 + 'no-unused-expressions': ['error', { allowTaggedTemplates: true }], + 'no-unused-labels': 'error', + 'no-useless-call': 'off', + 'no-useless-catch': 'error', + 'no-useless-computed-key': 'error', + 'no-useless-concat': 'error', + 'no-useless-constructor': 'error', + 'no-useless-escape': 'error', + 'no-useless-rename': 'error', + 'no-useless-return': 'off', + 'no-var': 'error', + 'no-void': 'error', + 'no-warning-comments': 'off', + 'no-with': 'error', + 'object-shorthand': 'error', + 'one-var': ['error', 'never'], + // FIXME: DEPRECATED + // since our `one-var` rule doesn't allow one variable declaration for all, + // we can safely disable this rule. + 'one-var-declaration-per-line': 'off', + 'operator-assignment': 'off', + 'prefer-arrow-callback': 'error', + 'prefer-const': ['error', { destructuring: 'all', ignoreReadBeforeAssign: false }], + 'prefer-destructuring': 'off', + 'prefer-exponentiation-operator': 'off', + 'prefer-named-capture-group': 'off', + 'prefer-numeric-literals': 'error', + // FIXME: check + 'prefer-object-has-own': 'off', + 'prefer-object-spread': 'off', + 'prefer-promise-reject-errors': ['error', { allowEmptyReject: true }], + 'prefer-regex-literals': ['error', { disallowRedundantWrapping: true }], + 'prefer-rest-params': 'error', + 'prefer-spread': 'error', + 'prefer-template': 'error', + // FIXME: DEPRECATED + 'quote-props': ['warn', 'as-needed', { unnecessary: false }], + 'radix': 'error', + 'require-await': 'off', + 'require-unicode-regexp': 'off', + 'require-yield': 'error', + 'sort-imports': 'off', + 'sort-keys': 'off', + 'sort-vars': 'off', + // FIXME: DEPRECATED + 'spaced-comment': ['error', 'always', { + line: { + exceptions: ['-', '+'], + // Space for supporting sprockets directives, slash for TS /// comments. + markers: ['=', '!', '/'], + }, + block: { + exceptions: ['-', '+'], + // Space for supporting sprockets directives and flow comment types. + markers: ['=', '!', ':', '::'], + balanced: true, + }, + }], + // This rule has been intentionally turned off. With the use of modern + // ECMAScript modules or tools like Babel, environments are automatically + // assumed to be 'strict-mode' enabled. Therefore, there is no need to + // enforce the strict mode flag in every entry of the code. + 'strict': 'off', + 'symbol-description': 'off', + 'vars-on-top': 'off', + 'yoda': 'error', + }, +}; diff --git a/rules/base/best-practices.js b/rules/base/to-discard/best-practices.js similarity index 100% rename from rules/base/best-practices.js rename to rules/base/to-discard/best-practices.js diff --git a/rules/base/ecmascript-6.js b/rules/base/to-discard/ecmascript-6.js similarity index 100% rename from rules/base/ecmascript-6.js rename to rules/base/to-discard/ecmascript-6.js diff --git a/rules/base/possible-errors.js b/rules/base/to-discard/possible-errors.js similarity index 97% rename from rules/base/possible-errors.js rename to rules/base/to-discard/possible-errors.js index fcd3427..94264dd 100644 --- a/rules/base/possible-errors.js +++ b/rules/base/to-discard/possible-errors.js @@ -15,7 +15,7 @@ module.exports = { 'no-await-in-loop': 'off', 'no-compare-neg-zero': 'error', 'no-cond-assign': 'error', - 'no-console': 'warn', + 'no-console': ['warn', { allow: ['warn', 'error'] }], // use `for (;;) {}` for infinite loop // https://stackoverflow.com/questions/2611246/is-for-faster-than-while-true-if-not-why-do-people-use-it 'no-constant-condition': 'warn', diff --git a/rules/base/strict-mode.js b/rules/base/to-discard/strict-mode.js similarity index 100% rename from rules/base/strict-mode.js rename to rules/base/to-discard/strict-mode.js diff --git a/rules/base/stylistic-issues.js b/rules/base/to-discard/stylistic-issues.js similarity index 100% rename from rules/base/stylistic-issues.js rename to rules/base/to-discard/stylistic-issues.js diff --git a/rules/base/variables.js b/rules/base/to-discard/variables.js similarity index 95% rename from rules/base/variables.js rename to rules/base/to-discard/variables.js index feba4dc..c9ff1f6 100644 --- a/rules/base/variables.js +++ b/rules/base/to-discard/variables.js @@ -17,6 +17,7 @@ module.exports = { 'no-undef-init': 'error', 'no-undefined': 'off', 'no-unused-vars': ['error', { + argsIgnorePattern: '^_', destructuredArrayIgnorePattern: '^_', ignoreRestSiblings: true, }], diff --git a/rules/react.js b/rules/react.js index d9db631..3bcba31 100644 --- a/rules/react.js +++ b/rules/react.js @@ -10,6 +10,11 @@ module.exports = { jsx: true, }, }, + settings: { + react: { + version: 'detect', + }, + }, rules: { // Enable original eslint rules 'jsx-quotes': 'error', @@ -47,12 +52,12 @@ module.exports = { 'react/no-string-refs': 'error', 'react/no-this-in-sfc': 'error', 'react/no-unescaped-entities': 'error', - 'react/no-unknown-property': 'error', + 'react/no-unknown-property': ['error', { ignore: ['css'] }], 'react/no-unused-prop-types': 'error', 'react/no-will-update-set-state': 'error', 'react/prefer-es6-class': 'error', 'react/prefer-stateless-function': 'error', - 'react/prop-types': 'error', + 'react/prop-types': 'off', 'react/react-in-jsx-scope': 'error', 'react/require-default-props': ['error', { forbidDefaultForRequired: true }], 'react/require-optimization': 'off', diff --git a/rules/typescript.js b/rules/typescript.js index a5f6075..9270006 100644 --- a/rules/typescript.js +++ b/rules/typescript.js @@ -7,11 +7,11 @@ module.exports = { parser: '@typescript-eslint/parser', plugins: ['@typescript-eslint'], parserOptions: { - ecmaVersion: 2019, + ecmaVersion: 'latest', sourceType: 'module', }, rules: { - // typescript rules + // Core rules '@typescript-eslint/adjacent-overload-signatures': 'error', '@typescript-eslint/array-type': 'error', '@typescript-eslint/await-thenable': 'off', @@ -23,7 +23,7 @@ module.exports = { '@typescript-eslint/consistent-type-assertions': 'error', '@typescript-eslint/consistent-type-definitions': 'error', '@typescript-eslint/consistent-type-exports': 'off', - // certain libraries make use of type information in their use cases: + // Certain libraries make use of type information in their use cases: // https://github.com/typescript-eslint/typescript-eslint/issues/2559#issuecomment-692780580 '@typescript-eslint/consistent-type-imports': 'off', '@typescript-eslint/explicit-function-return-type': ['error', { @@ -46,16 +46,14 @@ module.exports = { '@typescript-eslint/no-confusing-non-null-assertion': 'off', '@typescript-eslint/no-confusing-void-expression': 'off', '@typescript-eslint/no-dynamic-delete': 'off', - '@typescript-eslint/no-empty-interface': ['error', { - allowSingleExtends: true, - }], + '@typescript-eslint/no-empty-interface': 'off', '@typescript-eslint/no-explicit-any': 'warn', '@typescript-eslint/no-extra-non-null-assertion': 'error', '@typescript-eslint/no-extraneous-class': 'off', '@typescript-eslint/no-floating-promises': 'off', '@typescript-eslint/no-for-in-array': 'off', '@typescript-eslint/no-inferrable-types': 'off', - // disabled since it does not allow to make use of `void` in generic params + // Disabled since it does not allow to make use of `void` in generic params '@typescript-eslint/no-invalid-void-type': 'off', '@typescript-eslint/no-meaningless-void-operator': 'off', '@typescript-eslint/no-misused-new': 'error', @@ -70,16 +68,16 @@ module.exports = { '@typescript-eslint/no-require-imports': 'off', '@typescript-eslint/no-this-alias': 'off', '@typescript-eslint/no-type-alias': 'off', - // this requires the `strictNullChecks` option so may be problematic + // This requires the `strictNullChecks` option so may be problematic '@typescript-eslint/no-unnecessary-boolean-literal-compare': 'off', // TODO: enable? '@typescript-eslint/no-unnecessary-condition': 'off', - // we enforce not to use `namespaces` by the `@typescript-eslint/no-namespace` rule + // We enforce not to use `namespaces` by the `@typescript-eslint/no-namespace` rule '@typescript-eslint/no-unnecessary-qualifier': 'off', '@typescript-eslint/no-unnecessary-type-arguments': 'off', '@typescript-eslint/no-unnecessary-type-assertion': 'off', '@typescript-eslint/no-unnecessary-type-constraint': 'off', - // the `strict` option will cover those cases, so + // The `strict` option will cover those cases, so // `@typescript-eslint/no-unsafe-*` rules are not necessary. '@typescript-eslint/no-unsafe-argument': 'off', '@typescript-eslint/no-unsafe-assignment': 'off', @@ -87,7 +85,7 @@ module.exports = { '@typescript-eslint/no-unsafe-member-access': 'off', '@typescript-eslint/no-unsafe-return': 'off', '@typescript-eslint/no-var-requires': 'off', - // disabled as the rule requires type information + // Disabled as the rule requires type information '@typescript-eslint/non-nullable-type-assertion-style': 'off', '@typescript-eslint/prefer-as-const': 'error', '@typescript-eslint/prefer-enum-initializers': 'off', @@ -111,18 +109,18 @@ module.exports = { '@typescript-eslint/restrict-template-expressions': 'off', '@typescript-eslint/sort-type-union-intersection-members': 'off', '@typescript-eslint/strict-boolean-expressions': 'off', - // this will not work as expected since the `default-case` rule will always + // This will not work as expected since the `default-case` rule will always // require you to add `default` case anyway. '@typescript-eslint/switch-exhaustiveness-check': 'off', '@typescript-eslint/triple-slash-reference': 'off', '@typescript-eslint/type-annotation-spacing': 'error', - '@typescript-eslint/typedef': ['error', { - parameter: true, - }], + // TypeScript will better do the job of inferring types than this rule. + // Disabling the rule as the official document suggests: https://typescript-eslint.io/rules/typedef + '@typescript-eslint/typedef': 'off', '@typescript-eslint/unbound-method': 'off', '@typescript-eslint/unified-signatures': 'error', - // extension rules + // Override rules 'brace-style': 'off', '@typescript-eslint/brace-style': ['error', '1tbs', { allowSingleLine: true, @@ -137,8 +135,8 @@ module.exports = { '@typescript-eslint/dot-notation': 'off', 'func-call-spacing': 'off', '@typescript-eslint/func-call-spacing': 'error', - // for ongoing issues: https://github.com/typescript-eslint/typescript-eslint/issues/1824 - // related links: + // For unresolved issues: https://github.com/typescript-eslint/typescript-eslint/issues/1824 + // Related links: // - https://stackoverflow.com/questions/59851672/eslint-indent-and-ignorenodes-trouble-getting-ast-selectors-to-work-correctl/59852368#59852368 // - https://astexplorer.net/ 'indent': 'off', @@ -175,7 +173,7 @@ module.exports = { }], 'no-extra-semi': 'off', '@typescript-eslint/no-extra-semi': 'error', - // disabled as the rule requires type information + // Disabled as the rule requires type information // 'no-implied-eval': 'off', '@typescript-eslint/no-implied-eval': 'off', 'no-invalid-this': 'off', @@ -190,12 +188,12 @@ module.exports = { '@typescript-eslint/no-redeclare': 'error', 'no-restricted-imports': 'off', '@typescript-eslint/no-restricted-imports': 'off', - // even if the default `ignoreTypeValueShadow` option is enabled, + // Even if the default `ignoreTypeValueShadow` option is enabled, // `@typescript-eslint/no-redeclare` rule above will prevent naming a type // the same as a variable. 'no-shadow': 'off', '@typescript-eslint/no-shadow': 'error', - // disabled as the rule requires type information + // Disabled as the rule requires type information // 'no-throw-literal': 'off', '@typescript-eslint/no-throw-literal': 'off', 'no-unused-expressions': 'off', @@ -206,14 +204,19 @@ module.exports = { // disabled due to the issue where it causes false-positive when recursive // type references in generics involved. 'no-unused-vars': 'off', - '@typescript-eslint/no-unused-vars': 'error', + '@typescript-eslint/no-unused-vars': ['error', { + destructuredArrayIgnorePattern: '^_', + ignoreRestSiblings: true, + }], 'no-use-before-define': 'off', '@typescript-eslint/no-use-before-define': ['error', { functions: false, variables: false, }], 'no-useless-constructor': 'off', - '@typescript-eslint/no-useless-constructor': 'error', + // FIXME: Disabled due to an issue with the rule. + // https://github.com/typescript-eslint/typescript-eslint/issues/420 + '@typescript-eslint/no-useless-constructor': 'off', 'object-curly-spacing': 'off', '@typescript-eslint/object-curly-spacing': ['error', 'always'], 'padding-line-between-statements': 'off', diff --git a/rules/with-es5.js b/rules/with-es5.js index 9241189..92f66ac 100644 --- a/rules/with-es5.js +++ b/rules/with-es5.js @@ -1,22 +1,24 @@ 'use strict'; /** - * with ECMAScript 5 rules + * With ECMAScript 5 rules */ module.exports = { env: { + // For backward compatibility. es6: false, + es2023: false, }, parserOptions: { ecmaVersion: 5, sourceType: 'script', }, rules: { - // disable all conflicting rules + // Disable all conflicting rules. 'no-var': 'off', 'prefer-numeric-literals': 'off', - // enable strict mode + // Enable strict mode as we cannot assure the strict mode is enabled for non-ESM sources. 'strict': 'error', }, }; diff --git a/rules/with-no-restricted.js b/rules/with-no-restricted.js index dffc286..fa520f8 100644 --- a/rules/with-no-restricted.js +++ b/rules/with-no-restricted.js @@ -16,7 +16,7 @@ const restrictedGlobals = [ ].concat(confusingBrowserGlobals); /** - * with `no-restricted-*` rules + * With `no-restricted-*` rules */ module.exports = { rules: { diff --git a/rules/with-sort-imports.js b/rules/with-sort-imports.js index 88f0de1..b8dfbf1 100644 --- a/rules/with-sort-imports.js +++ b/rules/with-sort-imports.js @@ -1,11 +1,11 @@ 'use strict'; /** - * with simple import rules + * With simple import rules */ module.exports = { parserOptions: { - ecmaVersion: 2019, + ecmaVersion: 'latest', sourceType: 'module', }, rules: { diff --git a/typescript-react.js b/typescript-react.js index f15a6a5..d67a69f 100644 --- a/typescript-react.js +++ b/typescript-react.js @@ -5,7 +5,7 @@ module.exports = { es6: true, }, parserOptions: { - ecmaVersion: 2019, + ecmaVersion: 'latest', sourceType: 'module', }, extends: [ diff --git a/typescript.js b/typescript.js index 102cf53..14ef9d7 100644 --- a/typescript.js +++ b/typescript.js @@ -5,7 +5,7 @@ module.exports = { es6: true, }, parserOptions: { - ecmaVersion: 2019, + ecmaVersion: 'latest', sourceType: 'module', }, extends: [