-
Notifications
You must be signed in to change notification settings - Fork 72
/
eslint.config.mjs
276 lines (275 loc) · 7.22 KB
/
eslint.config.mjs
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
import eslint from '@eslint/js';
import comments from '@eslint-community/eslint-plugin-eslint-comments/configs';
import jsdoc from 'eslint-plugin-jsdoc';
import noSecrets from 'eslint-plugin-no-secrets';
import prettier from 'eslint-plugin-prettier';
import security from 'eslint-plugin-security';
import simpleImportSort from 'eslint-plugin-simple-import-sort';
import sortClassMembers from 'eslint-plugin-sort-class-members';
import unicorn from 'eslint-plugin-unicorn';
import globals from 'globals';
import tseslint from 'typescript-eslint';
export default [
{ languageOptions: { globals: { ...globals.browser, ...globals.node } } },
{
ignores: [
'**/node_modules/*',
'dist/**',
'action/**',
'bin/**',
'**/build/*',
'.storybook/**',
'storybook-static/**',
'storybook-out/**',
'coverage/**',
'subdir/**',
],
},
// eslint core + overrides
eslint.configs.recommended,
{
rules: {
// check cyclomatic complexity
complexity: ['error', 10],
// use strict equality checks when reasonable
eqeqeq: ['error', 'smart'],
// require switch cases to have a default
'default-case': ['error'],
// max nesting depth
'max-depth': ['error', 4],
// max lines per file
'max-lines': ['error', 500],
// max statements per function
'max-statements': ['error', 30],
// no dialog creating methods (alert, confirm, prompt)
'no-alert': 'error',
// prefer function declarations over variable expressions
'func-style': ['error', 'declaration', { allowArrowFunctions: true }],
},
},
// lint comments
comments.recommended,
{
files: ['**/*.js', '**/*.ts', '**/*.jsx', '**/*.tsx'],
rules: {
'@eslint-community/eslint-comments/disable-enable-pair': ['error', { allowWholeFile: true }],
},
},
// lint typescript
...tseslint.configs.strict,
...tseslint.configs.stylistic,
{
files: ['**/*.ts', '**/*.tsx'],
languageOptions: {
parserOptions: {
project: true,
tsConfigRootDir: import.meta.dirname,
},
},
rules: {
// TODO: make this an error when we have time to deal with it
'@typescript-eslint/no-explicit-any': 'off',
// '@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-floating-promises': 'error',
},
},
{
files: ['**/*.test.ts'],
languageOptions: {
parserOptions: {
project: true,
tsConfigRootDir: import.meta.dirname,
},
},
rules: {
'@typescript-eslint/no-floating-promises': 'off',
},
},
// allow underscore variables to be unused
{
rules: {
'@typescript-eslint/no-unused-vars': [
'error',
{
args: 'all',
argsIgnorePattern: '^_',
caughtErrors: 'all',
caughtErrorsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
varsIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],
'@typescript-eslint/no-empty-function': ['error', { allow: ['arrowFunctions'] }],
},
},
// additional lints from unicorn
unicorn.configs['flat/recommended'],
{
rules: {
'unicorn/filename-case': [
'error',
{
case: 'camelCase',
ignore: [
// Allow capitalization in initialisms
String.raw`^.*DNS.*\.[jt]s$`,
String.raw`^.*CSF.*\.[jt]s$`,
String.raw`^.*TTY.*\.[jt]s$`,
String.raw`^.*CI.*\.[jt]s$`,
String.raw`^.*E2E.*\.[jt]s$`,
],
},
],
// Chromatic uses err as our catch convention.
// This is baked into pino transforms as well.
'unicorn/prevent-abbreviations': [
'error',
{
allowList: {
err: true,
props: true,
ctx: true,
str: true,
args: true,
docsUrl: true,
fn: true,
pkg: true,
},
ignore: [/.*e2e.*/, /\w+[Dd]ocs\w*/],
},
],
'unicorn/catch-error-name': [
'error',
{
ignore: ['err'],
},
],
'unicorn/switch-case-braces': 'off',
'unicorn/no-process-exit': 'off',
'unicorn/prefer-node-protocol': 'off', // This will error our Webpack build
},
},
// prefer TS to complain when we miss an arg vs. sending an intentional undefined
{
files: ['**/*.ts'],
rules: {
'unicorn/no-useless-undefined': 'off',
},
},
{
files: ['node-src/ui/**'],
rules: {
'unicorn/no-anonymous-default-export': 'off',
},
},
// security related lints
security.configs.recommended,
{
files: ['**/*.js', '**/*.ts'],
rules: {
'security/detect-non-literal-fs-filename': 'off',
'security/detect-object-injection': 'off',
'security/detect-unsafe-regex': 'off',
},
},
{
files: ['**/*.js', '**/*.ts'],
plugins: {
'no-secrets': noSecrets,
},
rules: {
'no-secrets/no-secrets': [
'error',
{ ignoreContent: '^(https://www.chromatic.com/|/var/folders/)*' },
],
},
},
// run prettier and expose problems as linting errors
// NOTE: This does slow down eslint (about 25% slower)
// If this becomes problematic, we can discuss removing it
{
plugins: {
prettier: prettier,
},
rules: {
...prettier.configs.recommended.rules,
},
},
// lint jsdoc
{
files: ['**/*.js', '**/*.ts'],
plugins: {
jsdoc,
},
rules: {
...jsdoc.configs['flat/recommended-typescript'].rules,
'jsdoc/require-jsdoc': [
'error',
{
publicOnly: true,
require: { ClassDeclaration: true, FunctionDeclaration: true },
enableFixer: false,
},
],
'jsdoc/require-returns': ['warn', { enableFixer: true }],
'jsdoc/sort-tags': [
'error',
{
tagSequence: [{ tags: ['param'] }, { tags: ['returns'] }],
},
],
'jsdoc/tag-lines': ['error', 'any', { startLines: 1 }],
},
},
// sort your imports
{
plugins: {
'simple-import-sort': simpleImportSort,
},
rules: {
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
// disable built-in import/order rule
'import/order': 'off',
},
},
// sort class members
{
plugins: { 'sort-class-members': sortClassMembers },
rules: {
'sort-class-members/sort-class-members': [
2,
{
order: [
'[static-properties]',
'[static-methods]',
'[properties]',
'[conventional-private-properties]',
'constructor',
'[methods]',
],
accessorPairPositioning: 'getThenSet',
},
],
},
},
// exceptions for files stuck in CJS for now
{
files: ['**/*.cjs'],
rules: {
// 'unicorn/prefer-module': 'off',
'@typescript-eslint/no-var-requires': 'off',
},
},
// exceptions for test files and support
{
files: ['**/*.test.*'],
rules: {
'no-secrets/no-secrets': 'warn',
'max-lines': 'warn',
'jsdoc/require-jsdoc': 'off',
'unicorn/no-null': 'off', // GraphQL returns `null` when there is no value
},
},
];