|
1 | | -module.exports = { |
2 | | - env: { |
3 | | - node: true, |
4 | | - browser: true, |
5 | | - es6: true, |
6 | | - }, |
7 | | - parser: '@typescript-eslint/parser', |
8 | | - extends: [ |
| 1 | +import fs from 'fs' |
| 2 | +import path from 'path' |
| 3 | + |
| 4 | +const IS_TS_PROJECT = fs.existsSync( |
| 5 | + path.join(process.cwd() || '.', './tsconfig.json') |
| 6 | +) |
| 7 | + |
| 8 | +const parser = IS_TS_PROJECT |
| 9 | + ? '@typescript-eslint/parser' |
| 10 | + : '@babel/eslint-parser' |
| 11 | + |
| 12 | +const _extends = (() => { |
| 13 | + return [ |
9 | 14 | 'eslint:recommended', |
| 15 | + IS_TS_PROJECT ? 'plugin:@typescript-eslint/recommended' : null, |
10 | 16 | 'plugin:import/errors', |
11 | 17 | 'plugin:import/warnings', |
12 | 18 | 'plugin:import/typescript', |
13 | | - 'plugin:@typescript-eslint/recommended', |
14 | 19 | 'plugin:jsx-a11y/recommended', |
15 | 20 | 'plugin:react/recommended', |
16 | 21 | 'plugin:react-hooks/recommended', |
17 | 22 | 'plugin:prettier/recommended', |
| 23 | + ].filter(el => el && typeof el === 'string') |
| 24 | +})() |
| 25 | + |
| 26 | +const rules = { |
| 27 | + 'simple-import-sort/imports': 1, |
| 28 | + 'simple-import-sort/exports': 1, |
| 29 | + 'sort-imports': 0, |
| 30 | + 'import/order': 0, |
| 31 | + 'react/jsx-sort-props': [ |
| 32 | + 2, |
| 33 | + { |
| 34 | + callbacksLast: true, |
| 35 | + shorthandFirst: true, |
| 36 | + shorthandLast: false, |
| 37 | + ignoreCase: false, |
| 38 | + noSortAlphabetically: false, |
| 39 | + reservedFirst: true, |
| 40 | + }, |
18 | 41 | ], |
19 | | - plugins: ['simple-import-sort'], |
20 | | - rules: { |
21 | | - 'simple-import-sort/imports': 1, |
22 | | - 'simple-import-sort/exports': 1, |
23 | | - 'sort-imports': 0, |
24 | | - 'import/order': 0, |
25 | | - '@typescript-eslint/no-var-requires': 0, |
26 | | - '@typescript-eslint/no-non-null-assertion': 0, |
27 | | - '@typescript-eslint/no-use-before-define': 2, |
28 | | - '@typescript-eslint/explicit-module-boundary-types': 0, |
29 | | - '@typescript-eslint/consistent-type-imports': [ |
30 | | - 2, |
31 | | - { |
32 | | - prefer: 'type-imports', |
33 | | - disallowTypeAnnotations: true, |
34 | | - }, |
35 | | - ], |
36 | | - 'react/jsx-sort-props': [ |
37 | | - 2, |
38 | | - { |
39 | | - callbacksLast: true, |
40 | | - shorthandFirst: true, |
41 | | - shorthandLast: false, |
42 | | - ignoreCase: false, |
43 | | - noSortAlphabetically: false, |
44 | | - reservedFirst: true, |
45 | | - }, |
46 | | - ], |
| 42 | + ...(IS_TS_PROJECT |
| 43 | + ? { |
| 44 | + '@typescript-eslint/no-var-requires': 0, |
| 45 | + '@typescript-eslint/no-non-null-assertion': 0, |
| 46 | + '@typescript-eslint/no-use-before-define': 2, |
| 47 | + '@typescript-eslint/explicit-module-boundary-types': 0, |
| 48 | + '@typescript-eslint/consistent-type-imports': [ |
| 49 | + 2, |
| 50 | + { |
| 51 | + prefer: 'type-imports', |
| 52 | + disallowTypeAnnotations: true, |
| 53 | + }, |
| 54 | + ], |
| 55 | + } |
| 56 | + : {}), |
| 57 | +} |
| 58 | + |
| 59 | +module.exports = { |
| 60 | + env: { |
| 61 | + node: true, |
| 62 | + browser: true, |
| 63 | + es6: true, |
47 | 64 | }, |
| 65 | + parser, |
| 66 | + extends: _extends, |
| 67 | + plugins: ['simple-import-sort'], |
| 68 | + rules, |
48 | 69 | } |
0 commit comments