-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path.eslintrc.js
187 lines (168 loc) · 4.82 KB
/
.eslintrc.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
const rules = {
'no-warning-comments': [
'error',
{
terms: ['DEBUG', 'FIXME', 'HACK'],
location: 'start',
},
],
quotes: [
'error',
'single',
{
avoidEscape: true,
allowTemplateLiterals: false,
},
],
'no-console': 'error',
'no-unsafe-optional-chaining': 'error',
'no-catch-shadow': 'error',
'no-shadow': 'error',
'no-unused-vars': [
'error',
{
args: 'none',
caughtErrors: 'none',
},
],
'no-use-before-define': 'error',
'lines-between-class-members': 'error',
//// jest plugin
'jest/no-disabled-tests': 'error',
'jest/no-focused-tests': 'error',
'jest/no-identical-title': 'error',
'jest/valid-expect': 'error',
'jest/valid-title': 'error',
//// jest-dom plugin
// this rule is buggy, and doesn't seem to work well with the Testing Library's queries
'jest-dom/prefer-in-document': 'off',
//// testing-library plugin
// this prevents expect(document.querySelector('foo')), which is useful because not
// all elements can be found using RTL queries (sticking to RTL queries probably
// means less fragile tests, but then there are things we wouldn't be able to
// test like whether something renders in Light mode or Dark mode as expected)
'testing-library/no-node-access': 'off',
// we use custom queries, which don't get added to `screen` (that's a miss in RTL, IMO),
// which means we _must_ destructure the result from `render()` in order to get to
// our custom queries
'testing-library/prefer-screen-queries': 'off',
// not much value in this one, and it's not sophisticated enough to detect all usage
// scenarios so we get false-positives
'testing-library/await-async-utils': 'off',
//// react plugin
// we're using the new JSX transform that doesn't require 'react' import
'react/jsx-uses-react': 'off',
'react/react-in-jsx-scope': 'off',
};
const parserOptions = {
ecmaVersion: 2020, // ES11
sourceType: 'module',
};
const env = {
node: true,
browser: true,
es2020: true, // enable new ES6-ES11 globals
};
const globals = {
DEV_ENV: 'readonly',
TEST_ENV: 'readonly',
ENTITY_CACHE_VERSION: 'readonly',
fetchMock: 'readonly', // from 'jest-fetch-mock' package
};
const baseExtends = [
'eslint:recommended',
'prettier', // always AFTER eslint:recommended
'plugin:jest-dom/recommended',
'plugin:testing-library/react',
];
const plugins = ['jest'];
module.exports = {
overrides: [
{
// JavaScript files
files: ['**/*.js', '**/*.mjs'],
extends: [
...baseExtends,
'plugin:react/recommended',
'plugin:react-hooks/recommended',
],
parser: '@babel/eslint-parser',
parserOptions: {
...parserOptions,
ecmaFeatures: {
impliedStrict: true,
jsx: true,
},
},
globals,
env,
plugins,
rules: {
...rules,
//// React Plugin
// referring to another component's `.propTypes` is dangerous because that
// property doesn't exist in production builds as an optimization
// (this rule isn't enabled in 'plugin:react/recommended')
'react/forbid-foreign-prop-types': 'error',
//// React-Hooks Plugin
'react-hooks/exhaustive-deps': 'error', // default is 'warn', we prefer errors (warnings just get ignored)
},
settings: {
//// React Plugin
// a version needs to be specified, here it's set to detect (default value)
react: {
version: 'detect',
},
},
},
{
// TypeScript files
files: ['**/*.ts*'],
parser: '@typescript-eslint/parser',
parserOptions,
extends: [
...baseExtends,
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
],
globals,
env,
plugins,
rules: {
...rules,
'no-use-before-define': 'off', // ESLint finds false-positives with React imports in TSX files
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-empty-interface': 'off',
},
},
{
// test files
files: ['**/__tests__/**/?(*.)+(spec|test).[jt]s?(x)'],
env: {
...env,
'jest/globals': true,
},
rules: {
...rules,
'react/prop-types': 'off',
},
},
{
// mock files
files: ['__mocks__/**/*.[jt]s?(x)'],
env: {
...env,
'jest/globals': true,
},
rules: {
...rules,
'react/prop-types': 'off',
},
},
],
};