-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eslintrc.js
243 lines (211 loc) · 7.29 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
module.exports = {
env: {
browser: true,
es2021: true,
},
parser: '@typescript-eslint/parser',
settings: {
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx', '.d.ts'],
},
'import/extensions': ['.js', '.mjs', '.jsx', '.ts', '.tsx', '.d.ts'],
'import/external-module-folders': ['node_modules', 'node_modules/@types'],
},
globals: {
React: 'writable',
},
plugins: ['unused-imports', '@typescript-eslint/eslint-plugin', 'react'],
extends: [
'airbnb/hooks',
'airbnb',
'airbnb-typescript',
'prettier', // Deactivates all rules that overlap with Prettier
'prettier/react', // Same as above, just for React
],
rules: {
// React is never imported when using Next.js
'react/react-in-jsx-scope': 'off',
// Use the rule, but don't complain about theme-ui cx prop
'react/no-unknown-property': ['error', { ignore: ['sx'] }],
// Slow @typescript version - https://typescript-eslint.io/rules/no-implied-eval/
'no-implied-eval': 'error',
'@typescript-eslint/no-implied-eval': 'off',
// Slow @typescript version - https://typescript-eslint.io/rules/no-throw-literal/
'no-throw-literal': 'warn',
'@typescript-eslint/no-throw-literal': 'off',
// Slow @typescript version - https://typescript-eslint.io/rules/return-await/
'no-return-await': 'error',
'@typescript-eslint/return-await': 'off',
// Slow @typescript version – https://typescript-eslint.io/rules/dot-notation/
'dot-notation': 'error',
'@typescript-eslint/dot-notation': 'off',
// We don't want to enforce everything to be default exports
'import/prefer-default-export': 'off',
// We know, but we use it when we need it
'@typescript-eslint/ban-ts-comment': 'warn',
// Switching back and forth between implicit and explicit returns
// can cause messy commits, as all the content inside gets indented.
'arrow-body-style': 'off',
// We use regular javascript syntax for defaults
'react/require-default-props': 'off',
// Sometimes spreading is helpful
'react/jsx-props-no-spreading': 'off',
// Prevent react console errors
'react/jsx-key': 'error',
// Sometimes, in rare cases, destructuring makes less sense
'react/destructuring-assignment': 'off',
// Not important enough to fail a CI job
'react/jsx-no-useless-fragment': 'off',
// Doesn't make sense for Typescript since we're already checking types
'react/prop-types': 'off',
// Allow react functions to defined both as functions and const.
// Might be beneficial to clamp down harder in the future, though.
'react/function-component-definition': 'off',
// Would like to keep this fully enabled, but tanstack/react-table
// heavily uses this technique to customize table
'react/no-unstable-nested-components': ['error', { allowAsProps: true }],
// Combine airbnb and next configuration of this rule
'jsx-a11y/alt-text': [
'error',
{
elements: ['img', 'object', 'area', 'input[type="image"]'],
img: ['Image'],
object: [],
area: [],
'input[type="image"]': [],
},
],
// Already turned on, but we need to override it to add custom components
'jsx-a11y/label-has-associated-control': [
'error',
{
labelComponents: [],
labelAttributes: [],
controlComponents: ['Input'],
depth: 25,
},
],
// Useful rule, but isn't able to detect that as="button" means we fullfill the requirements!
'jsx-a11y/anchor-is-valid': 'off',
// Copied from airbnb-typescript
'react/jsx-filename-extension': ['error', { extensions: ['.jsx', '.tsx'] }],
'react-hooks/exhaustive-deps': 'error',
// Consistency is king
'import/order': [
'error',
{
alphabetize: {
order: 'asc',
},
'newlines-between': 'always',
pathGroups: [
{
pattern: '@konfidens/**',
group: 'external',
position: 'after',
},
],
groups: [
'builtin',
'external',
'internal',
'parent',
'sibling',
'index',
],
pathGroupsExcludedImportTypes: ['@konfidens/**'],
},
],
// Ban types that regularly causes problems
'@typescript-eslint/ban-types': [
'error',
{
types: {
String: {
message: 'Use string instead',
fixWith: 'string',
},
'{}': {
message:
'{} allows a function to be called with any argument.\n' +
' - Consider removing the typing entirely.\n' +
' - If you explicitly want any Record, use Record<string, unknown>.\n' +
' - If you explicitly want an empty object, use Record<never, never>.\n' +
' - If you want to allow anything (discouraged), use unknown.',
fixWith: '',
},
'React.FC': {
message:
'You do not need to type the return type of a React component. React.FC is discouraged. See https://github.com/facebook/create-react-app/pull/8177',
},
FC: {
message:
'You do not need to type the return type of a React component. React.FC is discouraged. See https://github.com/facebook/create-react-app/pull/8177',
},
},
},
],
// Use before define often makes more readable files
// Is disabled for most cases.
'@typescript-eslint/no-use-before-define': [
'error',
{
functions: false,
classes: false,
variables: false,
typedefs: false,
},
],
// We like short circuiting and ternaries. 😈
// Even though rule is set to error, the options
// will turn most triggers off.
'@typescript-eslint/no-unused-expressions': [
'error',
{
allowShortCircuit: true,
allowTernary: true,
allowTaggedTemplates: true,
enforceForJSX: false,
},
],
// We usually don't use classes except when we have to wrt. third party libs.
// In those cases, we usually don't get to choose how to make our classes.
'class-methods-use-this': 'off',
// This allows us to have no empty lines between two class attributes.
// Rule is automatically fixed with --fix
'@typescript-eslint/lines-between-class-members': [
'error',
'always',
{ exceptAfterSingleLine: true },
],
// Sometimes, in rare cases, destructuring makes less sense
'prefer-destructuring': 'off',
// Do not allow unused variables – a common cause of bugs. Use plugin.
// Variables named _ will still be ignored.
'@typescript-eslint/no-unused-vars': 'off',
'unused-imports/no-unused-imports': 'error',
'unused-imports/no-unused-vars': [
'error',
{
ignoreRestSiblings: true,
vars: 'all',
varsIgnorePattern: '^_',
args: 'after-used',
argsIgnorePattern: '^_',
},
],
'no-console': 'error',
'no-param-reassign': [
'error',
{
props: true,
ignorePropertyModificationsFor: [
'acc', // .reduce accumulators
'e', // dom event
],
},
],
// Conflicts with Prettier
'@typescript-eslint/indent': 'off',
},
};