-
Notifications
You must be signed in to change notification settings - Fork 1
/
.eslintrc.js
317 lines (274 loc) · 7.7 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
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
//
// ROOT ESLint Configuration
//
/* eslint-env node */
// @see https://eslint.org/docs/latest/use/configure/language-options#specifying-parser-options
const parserOptions = {
ecmaFeatures: {
impliedStrict: true,
},
ecmaVersion: 'latest', // probably overridden by `env.esXXXX` setting (docs are unclear)
sourceType: 'module', // ESM
};
// for use with https://typescript-eslint.io/users/configs#projects-with-type-checking
// @see https://typescript-eslint.io/getting-started/typed-linting
const typedParserOptions = {
...parserOptions,
project: true,
tsconfigRootDir: __dirname,
};
// @see https://eslint.org/docs/latest/use/configure/language-options#specifying-environments
const env = {
es2024: true, // automatically sets `parserOptions.ecmaVersion` parser option to 15
node: true,
};
const browserEnv = {
...env,
browser: true,
node: false,
};
// for all JavaScript files
const jsExtends = [
'eslint:recommended',
// @see https://typescript-eslint.io/troubleshooting/formatting#suggested-usage---prettier
'prettier', // ALWAYS LAST: disable style rules that conflict with prettier
];
// for all TypeScript files
const tsExtends = [
'eslint:recommended',
// @see https://typescript-eslint.io/users/configs#projects-with-type-checking
'plugin:@typescript-eslint/recommended-type-checked',
// @see https://typescript-eslint.io/troubleshooting/formatting#suggested-usage---prettier
'prettier', // ALWAYS LAST: disable style rules that conflict with prettier
];
// for .vue files
const vueExtends = [
'eslint:recommended',
// @see https://eslint.vuejs.org/
'plugin:vue/vue3-recommended',
// @see https://typescript-eslint.io/troubleshooting/formatting#suggested-usage---prettier
'prettier', // ALWAYS LAST: disable style rules that conflict with prettier
];
// for all JS files
const jsRules = {
//
// Rules: pull-in ESLint's recommended set, then tweak as necessary
// @see http://eslint.org/docs/rules/<rule-name>
//
//// possible errors
'no-regex-spaces': 'off',
'no-await-in-loop': 'error',
'no-async-promise-executor': 'error',
'no-misleading-character-class': 'error',
'no-unsafe-optional-chaining': 'error',
//// best practices
curly: 'error',
'default-case': 'error',
eqeqeq: 'error',
'guard-for-in': 'error',
'no-alert': 'error',
'no-caller': 'error',
'no-console': 'error',
'no-else-return': 'error',
'no-eq-null': 'error',
'no-eval': 'error',
'no-lone-blocks': 'error',
'no-loop-func': 'error',
'no-multi-spaces': 'error',
'no-new': 'off', // OFF to allow `myFunction(new RegExp('foo'))`, for example
'no-new-func': 'error', // disallow `new Function(...)` to declare a new function
'no-new-wrappers': 'error', // disallow `new Number/String/Boolean()`
'no-throw-literal': 'error',
'no-warning-comments': [
'error',
{
terms: ['DEBUG', 'FIXME', 'HACK'],
location: 'start',
},
],
//// strict mode
strict: ['error', 'function'],
//// variables
'no-catch-shadow': 'error',
'no-shadow': 'error',
'no-unused-vars': [
'error',
{
args: 'none',
caughtErrors: 'none',
vars: 'local', // allow unused globals because they're often AppsScript hooks/triggers like `onOpen`
},
],
'no-use-before-define': 'error',
//// stylistic issues
// NONE: Prettier will take care of these by reformatting the code on commit,
// save a few exceptions.
// Prettier will format using single quotes per .prettierrc.js settings, but
// will not require single quotes instead of backticks/template strings
// when interpolation isn't used, so this rule will catch those cases
quotes: [
'error',
'single',
{
avoidEscape: true,
allowTemplateLiterals: false,
},
],
//// ECMAScript 6 (non-stylistic issues only)
'no-duplicate-imports': ['error', { includeExports: true }],
'no-useless-constructor': 'error',
'no-var': 'error',
'prefer-arrow-callback': 'off',
'prefer-const': 'error',
};
// for TypeScript modules
const tsRules = {};
// for modules with typed Vue code
const vueRules = {
//// ESLint Vue plugin
'vue/html-self-closing': [
'error',
{
html: {
void: 'always',
normal: 'always',
component: 'always',
},
svg: 'always',
math: 'always',
},
],
'vue/attributes-order': 'off',
};
module.exports = {
root: true,
overrides: [
// project JavaScript files (tooling, etc.)
{
files: ['**/*.js'],
excludedFiles: ['src/**/*.*'],
extends: jsExtends,
parserOptions: {
...parserOptions,
sourceType: 'script', // CJS
},
env,
rules: {
...jsRules,
'no-console': 'off',
},
},
{
files: ['**/*.mjs'],
excludedFiles: ['src/**/*.*'],
extends: jsExtends,
parserOptions,
env,
rules: {
...jsRules,
'no-console': 'off',
},
},
// project TypeScript files (tooling, etc.)
{
files: ['**/*.ts'],
excludedFiles: ['src/**/*.*'],
extends: tsExtends,
parserOptions: {
...typedParserOptions,
sourceType: 'script', // CJS
},
env,
rules: {
...jsRules,
...tsRules,
'no-console': 'off',
},
},
{
files: ['**/*.mts'],
excludedFiles: ['src/**/*.*'],
extends: tsExtends,
parserOptions: typedParserOptions,
env,
rules: {
...jsRules,
...tsRules,
'no-console': 'off',
},
},
// TypeScript source files
{
files: ['src/**/*.ts'],
excludedFiles: ['src/demos/**'],
// @see https://typescript-eslint.io/packages/eslint-plugin/
plugins: ['@typescript-eslint'],
extends: tsExtends,
parser: '@typescript-eslint/parser',
parserOptions: typedParserOptions,
env: browserEnv,
rules: {
...jsRules,
...tsRules,
},
},
// TypeScript node demo files
{
files: ['src/demos/**/*.{ts,mts}'],
// @see https://typescript-eslint.io/packages/eslint-plugin/
plugins: ['@typescript-eslint'],
extends: tsExtends,
parser: '@typescript-eslint/parser',
parserOptions: typedParserOptions,
env,
rules: {
...jsRules,
...tsRules,
},
},
// TypeScript test files
{
// match any file with a suffix of .test, or .spec; and with .ts
// extension; and just test.<ext> or spec.<ext>; as long as the file is inside
// a __test__ directory at any depth within the base path
files: ['src/**/__tests__/**/?(*.)+(spec|test).ts'],
// @see https://typescript-eslint.io/packages/eslint-plugin/
plugins: ['@typescript-eslint'],
extends: tsExtends,
parser: '@typescript-eslint/parser',
parserOptions: typedParserOptions,
env, // expected to be NodeJS for now
rules: {
...jsRules,
...tsRules,
},
},
// JavaScript source files (docs are untyped because typescript-eslint plugin appears
// to have a bug where it doesn't recognize that .vue files are included in the tsconfig.json
// even when they are (if they were, that is)
// @see https://stackoverflow.com/questions/64051706/eslint-doesnt-believe-that-ive-included-vue-files-in-my-tsconfig
{
files: ['src/**/*.js'],
extends: jsExtends,
parserOptions,
env: browserEnv,
rules: {
...jsRules,
},
},
// Vue source files
// @see https://eslint.vuejs.org/user-guide
{
files: ['src/**/*.vue'],
extends: vueExtends,
parser: 'vue-eslint-parser',
parserOptions,
env: browserEnv,
rules: {
...jsRules,
...tsRules,
...vueRules,
},
},
],
};