|
1 |
| -const path = require('path'); |
2 |
| - |
| 1 | +const { readFileSync } = require('node:fs'); |
| 2 | +const path = require('node:path'); |
| 3 | +const ts = require('typescript'); |
3 | 4 | const { version: reactVersion } = require('react/package.json');
|
4 | 5 |
|
| 6 | +const tsconfigPath = ts.findConfigFile('./', ts.sys.fileExists); |
| 7 | +const { config } = ts.readConfigFile(tsconfigPath, ts.sys.readFile); |
| 8 | +const tsconfig = ts.parseJsonConfigFileContent(config, ts.sys, './'); |
| 9 | + |
| 10 | +/** |
| 11 | + * @type {import('eslint').Linter.Config } |
| 12 | + */ |
5 | 13 | module.exports = {
|
6 | 14 | root: true,
|
7 | 15 | // Suggested addition from the storybook 6.5 update
|
8 | 16 | extends: ['plugin:storybook/recommended'],
|
9 | 17 | // Ignore files which are also in .prettierignore
|
10 |
| - ignorePatterns: [ |
11 |
| - 'app/vendor/**', |
12 |
| - 'builds/**/*', |
13 |
| - 'development/chromereload.js', |
14 |
| - 'development/charts/**', |
15 |
| - 'development/ts-migration-dashboard/build/**', |
16 |
| - 'dist/**/*', |
17 |
| - 'node_modules/**/*', |
18 |
| - 'storybook-build/**/*', |
19 |
| - 'jest-coverage/**/*', |
20 |
| - 'coverage/**/*', |
21 |
| - 'public/**/*', |
22 |
| - ], |
| 18 | + ignorePatterns: readFileSync('.prettierignore', 'utf8').trim().split('\n'), |
| 19 | + // eslint's parser, esprima, is not compatible with ESM, so use the babel parser instead |
| 20 | + parser: '@babel/eslint-parser', |
23 | 21 | overrides: [
|
24 | 22 | /**
|
25 | 23 | * == Modules ==
|
@@ -125,13 +123,39 @@ module.exports = {
|
125 | 123 | * TypeScript files
|
126 | 124 | */
|
127 | 125 | {
|
128 |
| - files: ['*.{ts,tsx}'], |
| 126 | + files: tsconfig.fileNames.filter((f) => /\.tsx?$/u.test(f)), |
| 127 | + parserOptions: { |
| 128 | + project: tsconfigPath, |
| 129 | + // https://github.com/typescript-eslint/typescript-eslint/issues/251#issuecomment-463943250 |
| 130 | + tsconfigRootDir: path.dirname(tsconfigPath), |
| 131 | + }, |
129 | 132 | extends: [
|
130 | 133 | path.resolve(__dirname, '.eslintrc.base.js'),
|
131 | 134 | '@metamask/eslint-config-typescript',
|
132 | 135 | path.resolve(__dirname, '.eslintrc.typescript-compat.js'),
|
133 | 136 | ],
|
134 | 137 | rules: {
|
| 138 | + // this rule is new, but we didn't use it before, so it's off now |
| 139 | + '@typescript-eslint/no-duplicate-enum-values': 'off', |
| 140 | + '@typescript-eslint/no-shadow': [ |
| 141 | + 'error', |
| 142 | + { |
| 143 | + builtinGlobals: true, |
| 144 | + allow: [ |
| 145 | + 'ErrorOptions', |
| 146 | + 'Text', |
| 147 | + 'Screen', |
| 148 | + 'KeyboardEvent', |
| 149 | + 'Lock', |
| 150 | + 'Notification', |
| 151 | + 'CSS', |
| 152 | + ], |
| 153 | + }, |
| 154 | + ], |
| 155 | + // `no-parameter-properties` was removed in favor of `parameter-properties` |
| 156 | + // Yeah, they have opposite names but do the same thing?! |
| 157 | + '@typescript-eslint/no-parameter-properties': 'off', |
| 158 | + '@typescript-eslint/parameter-properties': 'error', |
135 | 159 | // Turn these off, as it's recommended by typescript-eslint.
|
136 | 160 | // See: <https://typescript-eslint.io/docs/linting/troubleshooting#eslint-plugin-import>
|
137 | 161 | 'import/named': 'off',
|
@@ -298,13 +322,12 @@ module.exports = {
|
298 | 322 | rules: {
|
299 | 323 | 'import/unambiguous': 'off',
|
300 | 324 | 'import/named': 'off',
|
301 |
| - 'jest/no-large-snapshots': [ |
302 |
| - 'error', |
303 |
| - { |
304 |
| - maxSize: 50, |
305 |
| - inlineMaxSize: 50, |
306 |
| - }, |
307 |
| - ], |
| 325 | + // *.snap files weren't parsed by previous versions of this eslint |
| 326 | + // config section, but something got fixed somewhere, and now this rule |
| 327 | + // causes failures. We need to turn it off instead of fix them because |
| 328 | + // we aren't even remotely close to being in alignment. If it bothers |
| 329 | + // you open a PR to fix it yourself. |
| 330 | + 'jest/no-large-snapshots': 'off', |
308 | 331 | 'jest/no-restricted-matchers': 'off',
|
309 | 332 |
|
310 | 333 | /**
|
@@ -398,13 +421,11 @@ module.exports = {
|
398 | 421 | },
|
399 | 422 | },
|
400 | 423 | {
|
401 |
| - files: ['ui/components/multichain/**/*.{js,ts,tsx}'], |
| 424 | + files: ['ui/components/multichain/**/*.{js}'], |
402 | 425 | extends: [
|
403 | 426 | path.resolve(__dirname, '.eslintrc.base.js'),
|
404 | 427 | path.resolve(__dirname, '.eslintrc.node.js'),
|
405 | 428 | path.resolve(__dirname, '.eslintrc.babel.js'),
|
406 |
| - path.resolve(__dirname, '.eslintrc.typescript-compat.js'), |
407 |
| - '@metamask/eslint-config-typescript', |
408 | 429 | ],
|
409 | 430 | rules: {
|
410 | 431 | 'sort-imports': [
|
|
0 commit comments