-
-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy path.eslintrc.js
229 lines (223 loc) · 9.19 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
/** JavaScript Versions
* 5 is minimum -> Last IE11
* 6 = 2015 -> Node >8.10, iOS12+
* 7 = 2016 -> FF78+,
* 8 = 2017 -> Node 10.9+
* 9 = 2018 -> Node 12.11+
* 10 = 2019 -> Node 12.20 LTS
* 11 = 2020 -> Node 14 LTS
* 12 = 2021 -> Node 16
*/
/** Node.js supports (https://node.green/):
* v07 - async/await
* v09 - tagged template literals with invalid escape sequences, RegExp lookbehind assertions
* v10 - optional catch binding (no need for err param on catch), BigInt, import.meta,
* RegExp Unicode property escape sequences \p{...},
* trimStart/trimEnd, async iteration, Promise.prototype.finally,
* RegExp named capture groups
* v11 - Array.prototype.{flat,flatMap}, Symbol.prototype.description
* v12 - Promise.allSettled, globalThis, numeric separators, Object.fromEntries
* v13 - import (modules), dynamic import(), export
* v14 - optional chaining, Nullish Coalescing operators, String.prototype.matchAll,
* Intl.DisplayNames, Intl.DateTimeFormat, (Experimental: Async Local Storage, Top-Level Await, Diagnostic report),
* WeakReferences, private class methods
* v15 - logical assignment operators, String.prototype.replaceAll, Promise.any, AggregateError, AbortController,
* (Experimental Promisified setTimeout/setImmediate)
* v16 - Promisified setTimeout/setImmediate, RegExp match indices. npm v7 (peer deps now installed again).
* fs.rmdir no longer supports recursive (use new fs.rm)
* v17 - OpenSSL 3 (incl QUIC), Readline Promise API
* v18 - (Experimental: Fetch API, Web Streams API, Test Runner), HTTP Timeouts, findLast/findLastIndex array methods,
* Improvements to the Intl.Locale API [calendars, collations, hourCycles, numberingSystems, timeZones, textInfo, weekInfo],
* Intl.supportedValuesOf function
* v19 - (Experimental: node --watch), HTTP(S)/1.1 KeepAlive by default, Stable WebCrypto API, Intl.NumberFormat
*/
module.exports = {
root: true,
env: {
browser: false,
commonjs: true,
es2022: true,
jquery: false,
node: true,
'shared-node-browser': false,
},
globals: {
Set: true, // Not sure why eslint doesn't recognise this as it is part of node.js since v0.12
RED: true,
},
parserOptions: {
// Only ESLint 6.2.0 and later support ES2020. Node.js v12+ supports some things only ratified in 2020
// ecmaVersion: 2022,
sourceType: 'script'
},
plugins: [
'html', // Check scripts in HTML. https://www.npmjs.com/package/eslint-plugin-html
'es', // Help avoid js that is too new. https://eslint-plugin-es.mysticatea.dev/
'jsdoc', // JSDoc. https://www.npmjs.com/package/eslint-plugin-jsdoc
'promise', // Better promises. https://www.npmjs.com/package/eslint-plugin-promise
'sonarjs', // Detect bugs and suspicious patterns. https://github.com/SonarSource/eslint-plugin-sonarjs
// 'prettier', // https://www.npmjs.com/package/eslint-plugin-prettier
// 'eslint-plugin-n', // loads itself from extends, no need to manually load
],
extends: [
'standard', // Also loads the n plugin
// 'eslint:recommended',
'plugin:es/no-new-in-esnext',
'plugin:jsdoc/recommended',
'plugin:promise/recommended',
// 'plugin:sonarjs/recommended-legacy', // NB: Needs changing for eslint v9. https://www.npmjs.com/package/eslint-plugin-sonarjs#usage
// 'plugin:prettier/recommended',
// The n plugin reads the min. node.js version from package.json and error's any ES features not available in that version.
'plugin:n/recommended',
],
overrides: [
{ // Override for Node-RED Editor js & html files
env: {
browser: true,
es2019: true,
es2022: false,
jquery: true,
node: false,
},
files: [
'resources/*.js',
'nodes/**/*.html',
'src/editor/**/*.{js,html}',
],
parserOptions: {
sourceType: 'script',
},
rules: {
// remove once min engines moves to node.js v14+
'es/no-optional-chaining': 'error',
'es/no-dynamic-import': 'error',
'es/no-nullish-coalescing-operators': 'error',
}
},
{ // Override for front-end & docs std js & html files
env: {
browser: true,
es2019: true,
es2022: false,
jquery: false,
node: false,
},
files: [
'front-end/**/*.js',
'front-end/**/*.html',
'docs/**/*.js',
'docs/**/*.html',
],
excludedFiles: [
'*.{esm.js,esm.min.js}',
],
parserOptions: {
sourceType: 'script',
},
rules: {
// remove once min engines moves to node.js v14+
'es/no-optional-chaining': 'error',
'es/no-dynamic-import': 'error',
'es/no-nullish-coalescing-operators': 'error',
}
},
{ // Override for front-end esm js & html files
env: {
browser: true,
es2019: false,
es2022: true,
jquery: false,
node: false,
},
files: [
'front-end/**/*.esm.js',
'front-end/**/*.esm.min.js',
],
excludedFiles: [
'*.{esm.js,esm.min.js}',
],
parserOptions: {
sourceType: 'module',
},
rules: {
// remove once min engines moves to node.js v14+
'es/no-optional-chaining': 'error',
'es/no-dynamic-import': 'error',
'es/no-nullish-coalescing-operators': 'error',
}
},
{ // Override for src esm js files
env: {
browser: true,
es2019: false,
es2022: true,
jquery: false,
node: false,
},
files: [
'src/components/*.js',
'src/front-end-module/*.js',
],
parserOptions: {
sourceType: 'module',
},
},
{ // Override for .eslintrc.js/cjs files
env: {
browser: false,
commonjs: true,
es2022: true,
jquery: false,
node: true,
},
files: [
'.eslintrc.{js,cjs}',
],
parserOptions: {
sourceType: 'script',
}
},
{ // Override for ESM files
files: ['*.module.js', '*.mod.js', '*.mjs'],
parserOptions: {
sourceType: 'module',
},
},
],
rules: {
'n/no-process-exit': 'error',
// remove once min engines moves to node.js v14+
// 'es/no-optional-chaining': 'error',
// 'es/no-dynamic-import': 'error',
// 'es/no-nullish-coalescing-operators': 'error',
// remove once min engines moves to node.js v15+
'es/no-logical-assignment-operators': 'error',
'es/no-promise-any': 'error',
'es/no-numeric-separators': 'error',
// Tidy up some jsdoc oddities
'jsdoc/multiline-blocks': 0,
'jsdoc/newline-after-description': 0,
'jsdoc/no-multi-asterisks': 0,
'jsdoc/tag-lines': 0,
'jsdoc/valid-types': 0, // Rubbish, fails on common type configs
'jsdoc/no-undefined-types': 0, // ['error'|'warn', {'definedTypes':['Promise']}],
// Try to keep code complexity in functions to a minimum
'sonarjs/cognitive-complexity': ['error', 60], // default is 15! Need to try and improve this :-)
'sonarjs/no-duplicate-string': ['warn', { 'threshold': 5 }], // default is 3
'sonarjs/no-commented-code': 0,
// Make Standard less annoying
'brace-style': 'off', // You should only use one-true-brace style but sometimes we want to compress things a bit.
'comma-dangle': 'off', // Lack of dangles wastes soo much time correcting lists
'dot-notation': 'off', // Turn off to allow for tslint's brain-dead treatment of expando objects in JS
'indent': ['error', 4, { 'SwitchCase': 1 }], // Standard wants 2, I like 4
'space-before-function-paren': 'off', // No, don't need space between fn and arg!
'no-multi-spaces': 'off', // Readability is more important than size (reduce size using uglify)
'object-shorthand': ['error', 'consistent'],
'padded-blocks': 'off', // Sometimes you just need some space! See above.
'space-in-parens': 'off', // Sometimes you just need some space!
'spaced-comment': ['error', 'always', {
'markers': ['html', '#region', '#endregion']
}],
'quote-props': 'off', // Sometimes it is necessary and then much nicer to be able to quote things that don't need it.
}
}