-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
113 lines (108 loc) · 3.27 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// eslint-disable-next-line @typescript-eslint/no-var-requires
const readPkgUp = require('read-pkg-up')
let hasPrettier = false
let hasJest = false
let hasJestDom = false
let hasTestingLibrary = false
let hasEmotion = false
let hasReact = false
try {
const { packageJson } = readPkgUp.sync({ normalize: true })
const allDeps = Object.keys({
...packageJson.peerDependencies,
...packageJson.devDependencies,
...packageJson.dependencies
})
hasReact = allDeps.includes('react') || allDeps.includes('react-dom')
hasPrettier = allDeps.includes('prettier')
hasJest = allDeps.includes('jest')
hasJestDom = allDeps.includes('@testing-library/jest-dom')
hasTestingLibrary =
allDeps.includes('@testing-library/react') ||
allDeps.includes('@testing-library/react-hooks')
hasEmotion =
allDeps.includes('@emotion/react') ||
allDeps.includes('@emotion/styled') ||
allDeps.includes('@emotion/css')
} catch (error) {
// ignore error
}
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2021,
sourceType: 'module',
ecmaFeatures: { jsx: hasReact }
},
plugins: [
'@typescript-eslint',
'promise',
hasJest && 'jest',
hasReact && 'react-hooks',
hasJestDom && 'jest-dom',
hasTestingLibrary && 'testing-library',
hasEmotion && '@emotion',
hasPrettier && 'prettier'
].filter(Boolean),
extends: [
'airbnb-base',
'plugin:@typescript-eslint/recommended',
'plugin:promise/recommended',
'plugin:compat/recommended',
hasJest && 'plugin:jest/recommended',
hasJest && 'plugin:jest/style',
hasReact && './rules/react',
hasJestDom && 'plugin:jest-dom/recommended',
hasTestingLibrary && 'plugin:testing-library/react',
hasPrettier && 'prettier'
].filter(Boolean),
settings: {
'import/resolver': {
typescript: {}
}
},
env: {
browser: true,
node: true,
es6: true,
...(hasJest && { 'jest/globals': true })
},
rules: {
'compat/compat': 'off',
'no-use-before-define': 'off',
'no-shadow': 'off',
'import/extensions': 'off',
'import/no-extraneous-dependencies': 'off',
'@typescript-eslint/no-use-before-define': 'error',
'@typescript-eslint/no-shadow': 'error',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-explicit-any': 'off',
...(hasReact
? {
'react/jsx-props-no-spreading': 'off',
'react/jsx-filename-extension': [
'error',
{
extensions: ['.js', 'jsx', '.ts', '.tsx']
}
],
// Enforce Rules of Hooks
// https://github.com/facebook/react/blob/c11015ff4f610ac2924d1fc6d569a17657a404fd/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js
'react-hooks/rules-of-hooks': 'error',
// Verify the list of the dependencies for Hooks like useEffect and similar
// https://github.com/facebook/react/blob/1204c789776cb01fbaf3e9f032e7e2ba85a44137/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js
'react-hooks/exhaustive-deps': 'error'
}
: null),
...(hasEmotion
? {
'@emotion/pkg-renaming': 'error'
}
: null),
...(hasPrettier
? {
'prettier/prettier': ['error']
}
: null)
}
}