|
| 1 | +import js from '@eslint/js' |
| 2 | +import tseslint from 'typescript-eslint' |
| 3 | +import unicorn from 'eslint-plugin-unicorn' |
| 4 | +import nodePlugin from 'eslint-plugin-n' |
| 5 | +import globals from 'globals' |
| 6 | + |
| 7 | +const customRules = { |
| 8 | + 'no-useless-constructor': 'warn', |
| 9 | + 'prefer-object-spread': 'warn', |
| 10 | + 'no-template-curly-in-string': 'off', |
| 11 | + 'newline-before-return': 'off', |
| 12 | + 'padding-line-between-statements': 'off', |
| 13 | + 'quote-props': ['error', 'consistent'], |
| 14 | + 'capitalized-comments': 'off', |
| 15 | + 'arrow-body-style': 'off', |
| 16 | + 'comma-dangle': 'off', |
| 17 | + 'complexity': 'off', |
| 18 | + 'max-depth': 'off', |
| 19 | + 'object-shorthand': 'off', |
| 20 | + 'operator-linebreak': 'off', |
| 21 | + 'object-curly-spacing': 'off', |
| 22 | + 'unicorn/prevent-abbreviations': 'off', |
| 23 | + 'unicorn/empty-brace-spaces': 'off', |
| 24 | + 'unicorn/no-this-assignment': 'off', |
| 25 | + 'unicorn/prefer-ternary': 'off', |
| 26 | + 'unicorn/no-array-for-each': 'warn', |
| 27 | + 'unicorn/prefer-logical-operator-over-ternary': 'off', |
| 28 | + 'unicorn/prefer-module': 'off', |
| 29 | + 'unicorn/prefer-node-protocol': 'off', |
| 30 | + 'unicorn/prefer-spread': 'off', |
| 31 | + 'unicorn/switch-case-braces': 'off', |
| 32 | + 'unicorn/no-null': 'off', |
| 33 | + 'unicorn/text-encoding-identifier-case': 'off', |
| 34 | + 'unicorn/no-instanceof-builtins': 'off', |
| 35 | + 'unicorn/prefer-at': 'off', |
| 36 | + 'unicorn/prefer-switch': 'off', |
| 37 | + 'unicorn/no-immediate-mutation': 'off', |
| 38 | + 'unicorn/no-useless-undefined': 'off', |
| 39 | + 'unicorn/consistent-existence-index-check': 'off', |
| 40 | + 'unicorn/consistent-compound-words': 'off', |
| 41 | + 'unicorn/prefer-split-limit': 'off' |
| 42 | +} |
| 43 | + |
| 44 | +const styleRules = { |
| 45 | + indent: ['error', 'tab', {SwitchCase: 1}], |
| 46 | + semi: ['error', 'never'], |
| 47 | + quotes: ['error', 'single', {avoidEscape: true}], |
| 48 | + 'no-unexpected-multiline': 'error' |
| 49 | +} |
| 50 | + |
| 51 | +const tsCustomRules = { |
| 52 | + '@typescript-eslint/consistent-indexed-object-style': 'off', |
| 53 | + '@typescript-eslint/consistent-type-definitions': 'off', |
| 54 | + '@typescript-eslint/consistent-type-imports': 'off', |
| 55 | + '@typescript-eslint/naming-convention': 'off', |
| 56 | + '@typescript-eslint/no-explicit-any': 'off' |
| 57 | +} |
| 58 | + |
| 59 | +export default tseslint.config( |
| 60 | + { |
| 61 | + ignores: [ |
| 62 | + 'coverage/**', |
| 63 | + 'docs/**', |
| 64 | + 'docsrc/**', |
| 65 | + 'scripts/**', |
| 66 | + 'node_modules/**' |
| 67 | + ] |
| 68 | + }, |
| 69 | + js.configs.recommended, |
| 70 | + unicorn.configs.recommended, |
| 71 | + { |
| 72 | + files: ['**/*.js'], |
| 73 | + ...nodePlugin.configs['flat/recommended-script'], |
| 74 | + languageOptions: { |
| 75 | + sourceType: 'commonjs', |
| 76 | + globals: { |
| 77 | + ...globals.node |
| 78 | + } |
| 79 | + }, |
| 80 | + rules: { |
| 81 | + ...nodePlugin.configs['flat/recommended-script'].rules, |
| 82 | + ...styleRules, |
| 83 | + ...customRules, |
| 84 | + 'n/file-extension-in-import': 'off', |
| 85 | + 'n/prefer-global/process': 'off', |
| 86 | + // Allow `_`-prefixed identifiers as intentional throwaways (e.g. `_ => {}`). |
| 87 | + 'no-unused-vars': ['error', { |
| 88 | + argsIgnorePattern: '^_', |
| 89 | + varsIgnorePattern: '^_', |
| 90 | + caughtErrorsIgnorePattern: '^_' |
| 91 | + }] |
| 92 | + } |
| 93 | + }, |
| 94 | + { |
| 95 | + files: ['**/*.ts'], |
| 96 | + extends: [tseslint.configs.recommended], |
| 97 | + rules: { |
| 98 | + ...styleRules, |
| 99 | + ...customRules, |
| 100 | + ...tsCustomRules |
| 101 | + } |
| 102 | + }, |
| 103 | + { |
| 104 | + files: ['test/**/*.{js,ts}', 'config/jest.setup.js'], |
| 105 | + languageOptions: { |
| 106 | + globals: { |
| 107 | + ...globals.jest |
| 108 | + } |
| 109 | + } |
| 110 | + } |
| 111 | +) |
0 commit comments