|
| 1 | +module.exports = { |
| 2 | + extends: [ |
| 3 | + 'prettier', |
| 4 | + '@remix-run/eslint-config', |
| 5 | + 'plugin:import/recommended', |
| 6 | + 'plugin:@typescript-eslint/recommended', |
| 7 | + 'plugin:import/typescript', |
| 8 | + ], |
| 9 | + parser: '@typescript-eslint/parser', |
| 10 | + plugins: ['import', 'unused-imports', 'simple-import-sort', '@typescript-eslint'], |
| 11 | + |
| 12 | + parserOptions: { |
| 13 | + ecmaVersion: 'latest', |
| 14 | + sourceType: 'module', |
| 15 | + project: true, |
| 16 | + tsconfigRootDir: __dirname, |
| 17 | + }, |
| 18 | + settings: { |
| 19 | + 'import/parsers': { |
| 20 | + '@typescript-eslint/parser': ['.ts', '.tsx'], |
| 21 | + }, |
| 22 | + 'import/resolver': { |
| 23 | + typescript: { |
| 24 | + project: ['tsconfig.json'], |
| 25 | + }, |
| 26 | + node: { |
| 27 | + project: ['tsconfig.json'], |
| 28 | + }, |
| 29 | + }, |
| 30 | + }, |
| 31 | + |
| 32 | + rules: { |
| 33 | + /** No absolute imports */ |
| 34 | + 'import/no-absolute-path': 'error', |
| 35 | + |
| 36 | + /** Ensures all imports appear before other statements */ |
| 37 | + 'import/first': ['error'], |
| 38 | + |
| 39 | + /** Ensures there’s an empty line between imports and other statements */ |
| 40 | + 'import/newline-after-import': ['warn', { count: 1 }], |
| 41 | + |
| 42 | + /** Sorts imports automatically */ |
| 43 | + 'simple-import-sort/imports': 'warn', |
| 44 | + |
| 45 | + /** Ensures no unused imports are present, and only _ prefixed variables can be unused */ |
| 46 | + 'no-unused-vars': 'off', |
| 47 | + 'unused-imports/no-unused-vars': [ |
| 48 | + 'warn', |
| 49 | + { |
| 50 | + vars: 'all', |
| 51 | + varsIgnorePattern: '^_', |
| 52 | + args: 'after-used', |
| 53 | + argsIgnorePattern: '^_', |
| 54 | + }, |
| 55 | + ], |
| 56 | + 'unused-imports/no-unused-imports': 'error', |
| 57 | + '@typescript-eslint/no-misused-promises': 'off', |
| 58 | + |
| 59 | + 'no-restricted-syntax': [ |
| 60 | + 'warn', |
| 61 | + { |
| 62 | + selector: 'TSEnumDeclaration', |
| 63 | + message: 'Don’t declare enums! Use string literal unions instead, they’re safer and more ergonomic.', |
| 64 | + }, |
| 65 | + ], |
| 66 | + |
| 67 | + 'no-restricted-imports': [ |
| 68 | + 'error', |
| 69 | + { |
| 70 | + paths: [ |
| 71 | + { |
| 72 | + name: 'react-router-dom', |
| 73 | + importNames: ['defer'], |
| 74 | + message: "Please import defer from '~/domains/routing/routing.utils' instead.", |
| 75 | + }, |
| 76 | + { |
| 77 | + name: 'react-router-dom', |
| 78 | + importNames: ['useLoaderData'], |
| 79 | + message: "Please import useLoaderData from '~/domains/routing/routing.utils' instead.", |
| 80 | + }, |
| 81 | + { |
| 82 | + name: 'react-router-dom', |
| 83 | + importNames: ['useActionData'], |
| 84 | + message: "Please import useActionData from '~/domains/routing/routing.utils' instead.", |
| 85 | + }, |
| 86 | + ], |
| 87 | + }, |
| 88 | + ], |
| 89 | + |
| 90 | + '@typescript-eslint/no-unnecessary-condition': 'warn', |
| 91 | + '@typescript-eslint/no-unnecessary-type-arguments': 'warn', |
| 92 | + '@typescript-eslint/prefer-for-of': 'warn', |
| 93 | + '@typescript-eslint/prefer-function-type': 'warn', |
| 94 | + |
| 95 | + /** Prefer types over interfaces */ |
| 96 | + '@typescript-eslint/consistent-type-definitions': ['warn', 'type'], |
| 97 | + |
| 98 | + '@typescript-eslint/no-confusing-non-null-assertion': 'error', |
| 99 | + |
| 100 | + /** Standardises arrays. Simple arrays use brackets, complex arrays uses generic syntax |
| 101 | + * @example - ❌ `const foo: Array<string> = [];` |
| 102 | + * @example - ✅ `const foo: string[] = [];` |
| 103 | + * @example - ❌ `const foo: ReturnType<typeof bar>[] = [];` |
| 104 | + * @example - ✅ `const foo: Array<ReturnType<typeof bar>> = [];` |
| 105 | + */ |
| 106 | + '@typescript-eslint/array-type': ['warn'], |
| 107 | + |
| 108 | + /** Enforces generics on the cunstructor, not as type annotation. |
| 109 | + * @example - ❌ `const foo: Foo<string> = new Foo();` |
| 110 | + * @example - ✅ `const foo = new Foo<string>();` |
| 111 | + */ |
| 112 | + '@typescript-eslint/consistent-generic-constructors': ['warn', 'constructor'], |
| 113 | + |
| 114 | + /** Prefer Record<X,Y> over {[key: X]: Y} syntax */ |
| 115 | + '@typescript-eslint/consistent-indexed-object-style': ['warn', 'record'], |
| 116 | + |
| 117 | + /** Already handled by unused-imports */ |
| 118 | + '@typescript-eslint/no-unused-vars': 'off', |
| 119 | + |
| 120 | + /** React uses that a lot */ |
| 121 | + '@typescript-eslint/unbound-method': 'off', |
| 122 | + |
| 123 | + '@typescript-eslint/ban-ts-comment': [ |
| 124 | + 'error', |
| 125 | + { |
| 126 | + 'ts-expect-error': 'allow-with-description', |
| 127 | + 'ts-ignore': true, |
| 128 | + 'ts-nocheck': true, |
| 129 | + 'ts-check': false, |
| 130 | + minimumDescriptionLength: 5, |
| 131 | + }, |
| 132 | + ], |
| 133 | + }, |
| 134 | +}; |
0 commit comments