forked from noobaa/noobaa-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eslintrc.js
359 lines (259 loc) · 13.3 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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
/* Copyright (C) 2016 NooBaa */
'use strict';
const CURRENT_YEAR = new Date().getFullYear();
module.exports = {
// prevent from looking up other config files in containing folders
root: true,
// Our environment is node.js
env: {
node: true,
es2022: true,
},
// See https://eslint.org/docs/latest/user-guide/configuring/language-options#specifying-environments
parserOptions: {
ecmaVersion: 13, // es2022
},
plugins: [
// eslint-plugin-header validates copyright header
'header'
],
// RULES METHODOLOGY:
// -----------------
// we turn ON all of eslint rules by extending eslint:all
// we selectively override the rules we want to remove or change.
// See http://eslint.org/docs/user-guide/configuring#using-eslintall
extends: 'eslint:all',
rules: {
//////////////////////////////////////////////////////////////////////
// //
// TODO FIX //
// //
// Probably best to fix these once we get to it //
// //
//////////////////////////////////////////////////////////////////////
'require-atomic-updates': 'off',
//////////////////////////////////////////////////////////////////////
// //
// ERROR //
// //
// The default is error, so these are just for passing options //
// //
//////////////////////////////////////////////////////////////////////
// verify every file contains our copyright header
'header/header': ['error', 'block', [{
template: ` Copyright (C) ${CURRENT_YEAR} NooBaa `,
pattern: " Copyright \\(C\\) 20\\d{2} NooBaa ",
}]],
// arrow function styling is not a real error but should be consistent
'arrow-parens': ['error', 'as-needed'],
// See: https://eslint.org/docs/latest/rules/brace-style
'brace-style': ['error', '1tbs', { allowSingleLine: true }],
// maximum number of code paths in a function
// TODO eslint complexity should be reduced to ~10 instead of 35
'complexity': ['error', 35],
// must use self=this and not any other alternatives
'consistent-this': ['error', 'self'],
// allow missing curly braces only for one liners such as if (cond) return;
'curly': ['error', 'multi-line'],
// when splitting "obj.property" to 2 lines the dot should stick to the property
'dot-location': ['error', 'property'],
// match generator-star-spacing to the beautifier preference
'generator-star-spacing': 'off',
// max depth of blocks in a function
// TODO eslint max-depth of blocks should be reduced to ~3 instead of 5
'max-depth': ['error', 5],
// max classed per file
'max-classes-per-file': 'off',
// max file length is 300 by default, we accept longer files
'max-lines': ['error', 2000],
// max lines per function, default is 50
'max-lines-per-function': ['error', 400],
// prefer small number of params to functions, otherwise send object
// TODO eslint max-params per function should be reduced to ~4 instead of 7
'max-params': ['error', 7],
// max statements in function
// TODO eslint max-statements per function should be reduced to ~40 instead of 60
'max-statements': ['error', 60],
'newline-per-chained-call': ['error', { ignoreChainWithDepth: 4 }],
// don't assign inside a condition, separate the lines for clarity
'no-cond-assign': ['error', 'always'],
'no-confusing-arrow': ['error', { allowParens: true }],
// empty lines are mostly harmless
'no-multiple-empty-lines': ['error', { max: 20 }],
// don't allow the code to leave unused variables, this prevents typos in many cases
'no-unused-vars': ['error', { vars: 'all', args: 'none' }],
// don't use assignments inside return statements, use separate statements.
'no-return-assign': ['error', 'always'],
'no-trailing-spaces': ['error', { ignoreComments: true }],
// do not allow code using variables before they are defined and initialized,
// but ok for functions since function decelerations are loaded before the code runs
'no-use-before-define': ['error', 'nofunc'],
// break lines after operators, not before
'operator-linebreak': ['error', 'after'],
// we prefer single var statement per variable
'one-var': ['error', 'never'],
'space-before-function-paren': ['error', {
'anonymous': 'never',
'named': 'never',
'asyncArrow': 'always'
}],
'function-call-argument-newline': 'off',
'space-unary-ops': ['error', {
words: true,
nonwords: false,
overrides: {
typeof: false,
},
}],
// max line length is 80 by default, allow some slack
// TODO eslint max-len for code lines should be error and reduced to ~100 instead of 140
'max-len': ['error', {
code: 140,
tabWidth: 4,
ignoreComments: true,
ignoreUrls: true,
ignoreStrings: true,
ignoreRegExpLiterals: true,
ignoreTemplateLiterals: true,
}],
// warn on using ++ operator, should replace with +=1
// to avoid shenanigans of the value returned before/after the action
'no-plusplus': ['error', { allowForLoopAfterthoughts: true }],
'arrow-body-style': ['error', 'as-needed'],
// prefer to use function deceleration (function foo() {})
// instead of expression (foo = function() {})
'func-style': ['error', 'declaration', { allowArrowFunctions: true }],
"prefer-const": ["error", {
"destructuring": "all",
"ignoreReadBeforeAssign": false
}],
//////////////////////////////////////////////////////////////////////
// //
// WARN //
// //
// These should be a temporary state, as warnings are futile. //
// We should eventually decide to change either to error or off. //
// //
//////////////////////////////////////////////////////////////////////
//Hooraay!!! No Warnings
//////////////////////////////////////////////////////////////////////
// //
// OFF //
// //
// We decided that these rules are too anal for our taste //
// //
//////////////////////////////////////////////////////////////////////
// not forcing how arrays should have new-line breaks
'array-element-newline': 'off',
'array-bracket-newline': 'off',
'array-bracket-spacing': 'off',
// camelcase is a religion. we were born differently.
'camelcase': 'off',
// Example: /=$/ is not like /\=$/ which the eslint expects
// This is not a relevant rule, we added it after the signature_utils query parsing errors
'no-div-regex': 'off',
//not forcing u. as part of a unicode regexp handling
'require-unicode-regexp': 'off',
'capitalized-comments': 'off',
// not enforcing all class methods to use 'this'
'class-methods-use-this': 'off',
// dangling commas are great for arrays and object properties
'comma-dangle': 'off',
// consistent return does not allow to write promises code very easily
// because in many cases there are conditions to running a promise,
// and otherwise the expected behavior is to simply continue.
'consistent-return': 'off',
// allowing anonymous functions, used a lot for promises
'func-names': 'off',
// not forcing a consistent policy on line breaks inside func parentheses
'function-paren-newline': 'off',
// allow short variable names like '_' or 'P' etc. use with care.
'id-length': 'off',
'implicit-arrow-linebreak': ['off', 'beside'],
// indent of 4 spaces would be good to enforce, but it doesn't work well for promise chains
// so hope no-mixed-spaces-and-tabs will be good enough
'indent': ['off', 4],
// not forcing initialization of variables
'init-declarations': 'off',
// directive means 'use strict', we don't enforce lines around
'lines-around-directive': 'off',
'lines-around-comment': 'off',
'lines-between-class-members': 'off',
// we don't enforce comments to above/after the line, both work ok
'line-comment-position': 'off',
// ternary operator is better split to 3 lines for readability
// TODO eslint multiline-ternary should be error
'multiline-ternary': 'off',
// use any comment style, just write comments
'multiline-comment-style': 'off',
// newlines to separate vars and return are not productive
'newline-after-var': 'off',
'newline-before-return': 'off',
// using console in node.js is cool
'no-console': 'off',
// continue in loops is better off avoided for readability
// prefer to use a function with returns and call from the loop
// TODO eslint no-continue should be warn/error
'no-continue': 'off',
// avoid redundant 'else' when using return statements in all cases
'no-else-return': 'off',
'no-extra-parens': ['off', 'all', { nestedBinaryExpressions: false }],
// short comments in-line are not great but sometimes make a lot of sense
'no-inline-comments': 'off',
// we live for magic numbers
'no-magic-numbers': 'off',
// prefer to avoid reassigning to function params and use a new variable
'no-param-reassign': 'off',
// using process features on nodejs is expected
'no-process-exit': 'off',
'no-process-env': 'off',
// allow usage of sync functions like fs.readFileSync() etc.
'no-sync': 'off',
// allowing (x ? y : z) it's a discouraged form but everyone are used to it
'no-ternary': 'off',
// using undefined on nodejs is safe. you cannot override it. you can try. it won't work.
'no-undefined': 'off',
// we do allow _name or name_ as identifiers
'no-underscore-dangle': 'off',
// turn off todo/fixme comments - will grep it to a different report
'no-warning-comments': 'off',
// the rule object-property-newline is better than object-curly-newline
'object-property-newline': 'off',
'object-curly-newline': 'off',
'object-curly-spacing': 'off',
// prefer using x={a,b} over x={a:a, b:b} but too much to fix
'object-shorthand': 'off',
// ignore stylish padding code blocks with newlines
'padded-blocks': 'off',
// prefer using arrow functions for callbacks, but too much to fix
'prefer-arrow-callback': 'off',
// prefer using arrow functions for callbacks, but too much to fix
'prefer-named-capture-group': 'off',
// we prefer using destructuring, but too much to fix
'prefer-destructuring': 'off',
'prefer-spread': 'off',
'prefer-reflect': 'off',
'prefer-rest-params': 'off',
// prefer using string template over string concatenation, but too much to fix
'prefer-template': 'off',
// prefer using single quotes, but too much to fix
'quotes': ['off', 'single'],
'quote-props': 'off',
'require-jsdoc': 'off',
'spaced-comment': 'off',
'sort-keys': 'off',
// don't verify the structure of jsdoc comments. let them be for now.
'valid-jsdoc': ['off', { requireReturn: false }],
// accept var deceleration in mid function, since we already check used before defined
'vars-on-top': 'off',
// Allow await in the body of loops.
'no-await-in-loop': 'off',
// Allow async function without await, for `return P.map(...)`
'require-await': 'off',
'no-promise-executor-return': 'off',
//Allow spacing between template tags and their literals
'template-tag-spacing': 'off',
// we prefer not to adopt the logical assignment operators from ES2020
'logical-assignment-operators': 'off'
}
};