|
| 1 | +import base, { createConfig } from '@metamask/eslint-config'; |
| 2 | +import nodejs from '@metamask/eslint-config-nodejs'; |
| 3 | +import jest from '@metamask/eslint-config-jest'; |
| 4 | +import typescript from '@metamask/eslint-config-typescript'; |
| 5 | + |
| 6 | +const config = createConfig( |
| 7 | + { |
| 8 | + ignores: [ |
| 9 | + 'yarn.lock', |
| 10 | + '**/**.map', |
| 11 | + '**/**.tsbuildinfo', |
| 12 | + '**/*.json', |
| 13 | + '**/*.md', |
| 14 | + '**/LICENSE', |
| 15 | + '**/*.sh', |
| 16 | + '**/.DS_Store', |
| 17 | + '**/dist/**', |
| 18 | + '**/docs/**', |
| 19 | + '**/coverage/**', |
| 20 | + 'merged-packages/**', |
| 21 | + '.yarn/**', |
| 22 | + 'scripts/create-package/package-template/**', |
| 23 | + ], |
| 24 | + }, |
| 25 | + ...base, |
| 26 | + { |
| 27 | + rules: { |
| 28 | + // Left disabled because various properties throughough this repo are snake_case because the |
| 29 | + // names come from external sources or must comply with standards |
| 30 | + // e.g. `txreceipt_status`, `signTypedData_v4`, `token_id` |
| 31 | + camelcase: 'off', |
| 32 | + 'id-length': 'off', |
| 33 | + |
| 34 | + // TODO: re-enble most of these rules |
| 35 | + '@typescript-eslint/naming-convention': 'off', |
| 36 | + 'function-paren-newline': 'off', |
| 37 | + 'id-denylist': 'off', |
| 38 | + 'implicit-arrow-linebreak': 'off', |
| 39 | + 'import/no-anonymous-default-export': 'off', |
| 40 | + 'import/no-unassigned-import': 'off', |
| 41 | + 'lines-around-comment': 'off', |
| 42 | + 'n/no-sync': 'off', |
| 43 | + 'no-async-promise-executor': 'off', |
| 44 | + 'no-case-declarations': 'off', |
| 45 | + 'no-invalid-this': 'off', |
| 46 | + 'no-negated-condition': 'off', |
| 47 | + 'no-new': 'off', |
| 48 | + 'no-param-reassign': 'off', |
| 49 | + 'no-restricted-syntax': 'off', |
| 50 | + radix: 'off', |
| 51 | + 'require-atomic-updates': 'off', |
| 52 | + 'jsdoc/match-description': [ |
| 53 | + 'off', |
| 54 | + { matchDescription: '^[A-Z`\\d_][\\s\\S]*[.?!`>)}]$' }, |
| 55 | + ], |
| 56 | + }, |
| 57 | + settings: { |
| 58 | + jsdoc: { |
| 59 | + mode: 'typescript', |
| 60 | + }, |
| 61 | + }, |
| 62 | + }, |
| 63 | + { |
| 64 | + files: [ |
| 65 | + '**/jest.config.js', |
| 66 | + '**/jest.environment.js', |
| 67 | + '**/tests/**/*.{ts,js}', |
| 68 | + '*.js', |
| 69 | + '*.test.{ts,js}', |
| 70 | + 'scripts/*.ts', |
| 71 | + 'scripts/create-package/*.ts', |
| 72 | + 'yarn.config.cjs', |
| 73 | + ], |
| 74 | + extends: [nodejs], |
| 75 | + }, |
| 76 | + { |
| 77 | + files: ['*.test.{ts,js}', '**/tests/**/*.{ts,js}'], |
| 78 | + extends: [jest], |
| 79 | + }, |
| 80 | + { |
| 81 | + // These files are test helpers, not tests. We still use the Jest ESLint |
| 82 | + // config here to ensure that ESLint expects a test-like environment, but |
| 83 | + // various rules meant just to apply to tests have been disabled. |
| 84 | + files: ['**/tests/**/*.{ts,js}', '!*.test.{ts,js}'], |
| 85 | + rules: { |
| 86 | + 'jest/no-export': 'off', |
| 87 | + 'jest/require-top-level-describe': 'off', |
| 88 | + 'jest/no-if': 'off', |
| 89 | + }, |
| 90 | + }, |
| 91 | + { |
| 92 | + files: ['*.js', '*.cjs'], |
| 93 | + parserOptions: { |
| 94 | + sourceType: 'script', |
| 95 | + ecmaVersion: '2020', |
| 96 | + }, |
| 97 | + }, |
| 98 | + { |
| 99 | + files: ['*.ts'], |
| 100 | + extends: [typescript], |
| 101 | + parserOptions: { |
| 102 | + tsconfigRootDir: import.meta.dirname, |
| 103 | + project: ['./tsconfig.packages.json'], |
| 104 | + }, |
| 105 | + rules: { |
| 106 | + // Enable rules that are disabled in `@metamask/eslint-config-typescript` |
| 107 | + '@typescript-eslint/no-explicit-any': 'error', |
| 108 | + |
| 109 | + // TODO: auto-fix breaks stuff |
| 110 | + '@typescript-eslint/promise-function-async': 'off', |
| 111 | + |
| 112 | + // TODO: re-enable most of these rules |
| 113 | + '@typescript-eslint/no-unnecessary-type-assertion': 'off', |
| 114 | + '@typescript-eslint/unbound-method': 'off', |
| 115 | + '@typescript-eslint/prefer-enum-initializers': 'off', |
| 116 | + '@typescript-eslint/prefer-nullish-coalescing': 'off', |
| 117 | + '@typescript-eslint/prefer-optional-chain': 'off', |
| 118 | + '@typescript-eslint/prefer-reduce-type-parameter': 'off', |
| 119 | + 'no-restricted-syntax': 'off', |
| 120 | + 'no-restricted-globals': 'off', |
| 121 | + }, |
| 122 | + }, |
| 123 | + { |
| 124 | + files: ['tests/setupAfterEnv/matchers.ts'], |
| 125 | + parserOptions: { |
| 126 | + sourceType: 'script', |
| 127 | + }, |
| 128 | + }, |
| 129 | + { |
| 130 | + files: ['*.d.ts'], |
| 131 | + rules: { |
| 132 | + '@typescript-eslint/naming-convention': 'warn', |
| 133 | + 'import/unambiguous': 'off', |
| 134 | + }, |
| 135 | + }, |
| 136 | + { |
| 137 | + files: ['scripts/*.ts'], |
| 138 | + rules: { |
| 139 | + // All scripts will have shebangs. |
| 140 | + 'n/shebang': 'off', |
| 141 | + }, |
| 142 | + }, |
| 143 | + { |
| 144 | + files: ['**/jest.environment.js'], |
| 145 | + rules: { |
| 146 | + // These files run under Node, and thus `require(...)` is expected. |
| 147 | + 'n/global-require': 'off', |
| 148 | + }, |
| 149 | + }, |
| 150 | +); |
| 151 | + |
| 152 | +export default config; |
0 commit comments