forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eslintrc.js
368 lines (359 loc) · 11.8 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
360
361
362
363
364
365
366
367
368
'use strict';
/* eslint-env node */
const Module = require('module');
const path = require('path');
const NodePlugin = require('./tools/node_modules/eslint-plugin-node-core');
NodePlugin.RULES_DIR = path.resolve(__dirname, 'tools', 'eslint-rules');
// The Module._findPath() monkeypatching is to make it so that ESLint will work
// if invoked by a globally-installed ESLint or ESLint installed elsewhere
// rather than the one we ship. This makes it possible for IDEs to lint files
// with our rules while people edit them.
const ModuleFindPath = Module._findPath;
const hacks = [
'eslint-plugin-node-core',
'eslint-plugin-jsdoc',
'eslint-plugin-markdown',
'@babel/eslint-parser',
'@babel/plugin-syntax-import-attributes',
'@stylistic/eslint-plugin-js',
];
Module._findPath = (request, paths, isMain) => {
const r = ModuleFindPath(request, paths, isMain);
if (!r && hacks.includes(request)) {
try {
return require.resolve(`./tools/node_modules/${request}`);
} catch {
return require.resolve(
`./tools/node_modules/eslint/node_modules/${request}`);
}
}
return r;
};
module.exports = {
root: true,
env: {
es2022: true,
},
extends: ['eslint:recommended', 'plugin:jsdoc/recommended'],
plugins: ['jsdoc', 'markdown', 'node-core', '@stylistic/js'],
parser: '@babel/eslint-parser',
parserOptions: {
babelOptions: {
plugins: [
Module._findPath('@babel/plugin-syntax-import-attributes'),
],
},
requireConfigFile: false,
sourceType: 'script',
},
overrides: [
{
files: [
'*.mjs',
'test/es-module/test-esm-example-loader.js',
'test/es-module/test-esm-type-flag.js',
'test/es-module/test-esm-type-flag-alias.js',
],
parserOptions: { sourceType: 'module' },
},
{
files: ['**/*.md'],
processor: 'markdown/markdown',
},
{
files: ['**/*.md/*.cjs', '**/*.md/*.js'],
parserOptions: {
sourceType: 'script',
ecmaFeatures: { impliedStrict: true },
},
rules: { strict: 'off' },
},
{
files: [
'**/*.md/*.mjs',
'doc/api/esm.md/*.js',
'doc/api/packages.md/*.js',
],
parserOptions: { sourceType: 'module' },
rules: { 'no-restricted-globals': [
'error',
{
name: '__filename',
message: 'Use import.meta.url instead',
},
{
name: '__dirname',
message: 'Not available in ESM',
},
{
name: 'exports',
message: 'Not available in ESM',
},
{
name: 'module',
message: 'Not available in ESM',
},
{
name: 'require',
message: 'Use import instead',
},
{
name: 'Buffer',
message: 'Import Buffer instead of using the global',
},
{
name: 'process',
message: 'Import process instead of using the global',
},
] },
},
{
files: [
'lib/internal/modules/**/*.js',
],
rules: {
'curly': 'error',
},
},
{
files: [
'lib/internal/test_runner/**/*.js',
],
rules: {
'node-core/set-proto-to-null-in-object': 'error',
},
},
],
rules: {
// ESLint built-in rules
// https://eslint.org/docs/rules/
'accessor-pairs': 'error',
'array-callback-return': 'error',
'block-scoped-var': 'error',
'capitalized-comments': ['error', 'always', {
line: {
// Ignore all lines that have less characters than 20 and all lines that
// start with something that looks like a variable name or code.
ignorePattern: '.{0,20}$|[a-z]+ ?[0-9A-Z_.(/=:[#-]|std|http|ssh|ftp',
ignoreInlineComments: true,
ignoreConsecutiveComments: true,
},
block: {
ignorePattern: '.*',
},
}],
'default-case-last': 'error',
'dot-notation': 'error',
'eqeqeq': ['error', 'smart'],
'func-name-matching': 'error',
'func-style': ['error', 'declaration', { allowArrowFunctions: true }],
'no-constant-condition': ['error', { checkLoops: false }],
'no-constructor-return': 'error',
'no-duplicate-imports': 'error',
'no-else-return': 'error',
'no-lonely-if': 'error',
'no-mixed-requires': 'error',
'no-new-require': 'error',
'no-path-concat': 'error',
'no-proto': 'error',
'no-redeclare': ['error', { 'builtinGlobals': false }],
'no-restricted-modules': ['error', 'sys'],
'no-restricted-properties': [
'error',
{
object: 'assert',
property: 'deepEqual',
message: 'Use `assert.deepStrictEqual()`.',
},
{
object: 'assert',
property: 'notDeepEqual',
message: 'Use `assert.notDeepStrictEqual()`.',
},
{
object: 'assert',
property: 'equal',
message: 'Use `assert.strictEqual()` rather than `assert.equal()`.',
},
{
object: 'assert',
property: 'notEqual',
message: 'Use `assert.notStrictEqual()` rather than `assert.notEqual()`.',
},
{
property: '__defineGetter__',
message: '__defineGetter__ is deprecated.',
},
{
property: '__defineSetter__',
message: '__defineSetter__ is deprecated.',
},
],
// If this list is modified, please copy changes that should apply to ./lib
// as well to lib/.eslintrc.yaml.
'no-restricted-syntax': [
'error',
{
selector: "CallExpression[callee.name='setTimeout'][arguments.length<2]",
message: '`setTimeout()` must be invoked with at least two arguments.',
},
{
selector: "CallExpression[callee.name='setInterval'][arguments.length<2]",
message: '`setInterval()` must be invoked with at least two arguments.',
},
{
selector: 'ThrowStatement > CallExpression[callee.name=/Error$/]',
message: 'Use `new` keyword when throwing an `Error`.',
},
{
selector: "CallExpression[callee.name='isNaN']",
message: 'Use Number.isNaN() instead of the global isNaN() function.',
},
{
// TODO(@panva): move this to no-restricted-properties
// when https://github.com/eslint/eslint/issues/16412 is fixed
selector: "Identifier[name='webcrypto']",
message: 'Use `globalThis.crypto`.',
},
],
'no-self-compare': 'error',
'no-template-curly-in-string': 'error',
'no-throw-literal': 'error',
'no-undef': ['error', { typeof: true }],
'no-undef-init': 'error',
'no-unused-expressions': ['error', { allowShortCircuit: true }],
'no-unused-vars': ['error', { args: 'none', caughtErrors: 'all' }],
'no-use-before-define': ['error', {
classes: true,
functions: false,
variables: false,
}],
'no-useless-call': 'error',
'no-useless-concat': 'error',
'no-useless-constructor': 'error',
'no-useless-return': 'error',
'no-var': 'error',
'no-void': 'error',
'one-var': ['error', { initialized: 'never' }],
'prefer-const': ['error', { ignoreReadBeforeAssign: true }],
'prefer-object-has-own': 'error',
'strict': ['error', 'global'],
'symbol-description': 'error',
'unicode-bom': 'error',
'valid-typeof': ['error', { requireStringLiterals: true }],
// ESLint recommended rules that we disable
'no-inner-declarations': 'off',
// JSDoc recommended rules that we disable
'jsdoc/require-jsdoc': 'off',
'jsdoc/require-param-description': 'off',
'jsdoc/newline-after-description': 'off',
'jsdoc/require-returns-description': 'off',
'jsdoc/valid-types': 'off',
'jsdoc/no-defaults': 'off',
'jsdoc/no-undefined-types': 'off',
'jsdoc/require-param': 'off',
'jsdoc/check-tag-names': 'off',
'jsdoc/require-returns': 'off',
// Stylistic rules
'@stylistic/js/arrow-parens': 'error',
'@stylistic/js/arrow-spacing': 'error',
'@stylistic/js/block-spacing': 'error',
'@stylistic/js/brace-style': ['error', '1tbs', { allowSingleLine: true }],
'@stylistic/js/comma-dangle': ['error', 'always-multiline'],
'@stylistic/js/comma-spacing': 'error',
'@stylistic/js/comma-style': 'error',
'@stylistic/js/computed-property-spacing': 'error',
'@stylistic/js/dot-location': ['error', 'property'],
'@stylistic/js/eol-last': 'error',
'@stylistic/js/func-call-spacing': 'error',
'@stylistic/js/indent': ['error', 2, {
ArrayExpression: 'first',
CallExpression: { arguments: 'first' },
FunctionDeclaration: { parameters: 'first' },
FunctionExpression: { parameters: 'first' },
MemberExpression: 'off',
ObjectExpression: 'first',
SwitchCase: 1,
}],
'@stylistic/js/key-spacing': 'error',
'@stylistic/js/keyword-spacing': 'error',
'@stylistic/js/linebreak-style': 'error',
'@stylistic/js/max-len': ['error', {
code: 120,
ignorePattern: '^// Flags:',
ignoreRegExpLiterals: true,
ignoreTemplateLiterals: true,
ignoreUrls: true,
tabWidth: 2,
}],
'@stylistic/js/new-parens': 'error',
'@stylistic/js/no-confusing-arrow': 'error',
'@stylistic/js/no-extra-parens': ['error', 'functions'],
'@stylistic/js/no-multi-spaces': ['error', { ignoreEOLComments: true }],
'@stylistic/js/no-multiple-empty-lines': ['error', { max: 2, maxEOF: 0, maxBOF: 0 }],
'@stylistic/js/no-tabs': 'error',
'@stylistic/js/no-trailing-spaces': 'error',
'@stylistic/js/no-whitespace-before-property': 'error',
'@stylistic/js/object-curly-newline': 'error',
'@stylistic/js/object-curly-spacing': ['error', 'always'],
'@stylistic/js/one-var-declaration-per-line': 'error',
'@stylistic/js/operator-linebreak': ['error', 'after'],
'@stylistic/js/padding-line-between-statements': [
'error',
{ blankLine: 'always', prev: 'function', next: 'function' },
],
'@stylistic/js/quotes': ['error', 'single', { avoidEscape: true }],
'@stylistic/js/quote-props': ['error', 'consistent'],
'@stylistic/js/rest-spread-spacing': 'error',
'@stylistic/js/semi': 'error',
'@stylistic/js/semi-spacing': 'error',
'@stylistic/js/space-before-blocks': ['error', 'always'],
'@stylistic/js/space-before-function-paren': ['error', {
anonymous: 'never',
named: 'never',
asyncArrow: 'always',
}],
'@stylistic/js/space-in-parens': 'error',
'@stylistic/js/space-infix-ops': 'error',
'@stylistic/js/space-unary-ops': 'error',
'@stylistic/js/spaced-comment': ['error', 'always', {
'block': { 'balanced': true },
'exceptions': ['-'],
}],
'@stylistic/js/template-curly-spacing': 'error',
// Custom rules from eslint-plugin-node-core
'node-core/no-unescaped-regexp-dot': 'error',
'node-core/no-duplicate-requires': 'error',
'node-core/prefer-proto': 'error',
},
globals: {
ByteLengthQueuingStrategy: 'readable',
CompressionStream: 'readable',
CountQueuingStrategy: 'readable',
CustomEvent: 'readable',
crypto: 'readable',
Crypto: 'readable',
CryptoKey: 'readable',
DecompressionStream: 'readable',
fetch: 'readable',
FormData: 'readable',
navigator: 'readable',
ReadableStream: 'readable',
ReadableStreamDefaultReader: 'readable',
ReadableStreamBYOBReader: 'readable',
ReadableStreamBYOBRequest: 'readable',
ReadableByteStreamController: 'readable',
ReadableStreamDefaultController: 'readable',
Response: 'readable',
TextDecoderStream: 'readable',
TextEncoderStream: 'readable',
TransformStream: 'readable',
TransformStreamDefaultController: 'readable',
ShadowRealm: 'readable',
SubtleCrypto: 'readable',
WritableStream: 'readable',
WritableStreamDefaultWriter: 'readable',
WritableStreamDefaultController: 'readable',
WebSocket: 'readable',
},
};