@w5s/eslint-config 1.0.0-alpha.2 → 1.0.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@w5s/eslint-config",
3
- "version": "1.0.0-alpha.2",
3
+ "version": "1.0.0-alpha.3",
4
4
  "description": "ESLint configuration presets",
5
5
  "keywords": [
6
6
  "eslint",
@@ -45,6 +45,7 @@
45
45
  "@babel/plugin-syntax-jsx": "^7.0.0",
46
46
  "@typescript-eslint/eslint-plugin": "^5.0.0",
47
47
  "@typescript-eslint/parser": "^5.0.0",
48
+ "eslint-config-airbnb-base": "^15.0.0",
48
49
  "eslint-config-prettier": "^8.0.0",
49
50
  "eslint-plugin-functional": "^4.2.0",
50
51
  "eslint-plugin-import": "^2.25.0",
@@ -76,5 +77,5 @@
76
77
  "publishConfig": {
77
78
  "access": "public"
78
79
  },
79
- "gitHead": "1fd5f03e6f071785cc5be4f9a57430485cf9d6fc"
80
+ "gitHead": "9935d3a478d08c3c6c02f467f65c623a16749753"
80
81
  }
package/rules/_rule.js CHANGED
@@ -7,8 +7,71 @@ const warn = 'warn';
7
7
  /** @type {'off'} */
8
8
  const off = 'off';
9
9
 
10
+ /**
11
+ * @typedef {{
12
+ * env?: Record<string, boolean>,
13
+ * extends?: string[]|string,
14
+ * plugins?: string[]|string,
15
+ * rules?: Record<string, unknown>,
16
+ * settings?: Record<string, unknown>,
17
+ * }} ESLintConfigInit
18
+ */
19
+ /**
20
+ * @typedef {{
21
+ * env: Record<string, boolean>,
22
+ * extends: string[],
23
+ * plugins: string[],
24
+ * rules: Record<string, unknown>,
25
+ * settings: Record<string, unknown>,
26
+ * }} ESLintConfig
27
+ */
28
+
29
+ /**
30
+ * @template T
31
+ * @type {(value: T[]|T|undefined) => T[]} */
32
+ function toArray(value) {
33
+ if (value == null) {
34
+ return [];
35
+ }
36
+ if (Array.isArray(value)) {
37
+ return value;
38
+ }
39
+ return [value];
40
+ }
41
+
42
+ /**
43
+ * @template T
44
+ * @type {(left: T[]|T|undefined, right:T[]|T|undefined) => T[]}
45
+ */
46
+ function concatArray(left, right) {
47
+ return toArray(left).concat(toArray(right));
48
+ }
49
+
50
+ /** @type {(...configs: ESLintConfigInit[]) => ESLintConfig} */
51
+ function concatESConfig(...configs) {
52
+ return configs.reduce(
53
+ (/** @type {ESLintConfig} */ returnValue, /** @type {ESLintConfigInit} */ config) =>
54
+ Object.assign({}, returnValue, config, {
55
+ env: Object.assign({}, returnValue.env, config.env),
56
+ extends: concatArray(returnValue.extends, config.extends),
57
+ plugins: concatArray(returnValue.plugins, config.plugins),
58
+ rules: Object.assign({}, returnValue.rules, config.rules),
59
+ settings: Object.assign({}, returnValue.settings, config.settings),
60
+ }),
61
+ {
62
+ env: {},
63
+ extends: [],
64
+ plugins: [],
65
+ rules: {},
66
+ settings: {},
67
+ }
68
+ );
69
+ }
70
+
10
71
  module.exports = {
72
+ concatESConfig,
11
73
  error,
74
+ // eslint-disable-next-line no-unused-vars
12
75
  fixme: (/** @type {'off'|'warn'|'error'} */ _status) => off,
13
76
  off,
14
77
  warn,
package/rules/base.js CHANGED
@@ -1,476 +1,28 @@
1
- const { off, warn, error } = require('./_rule');
1
+ const { concatESConfig, off } = require('./_rule');
2
2
 
3
- module.exports = {
4
- env: {
5
- es6: true,
6
- },
7
- extends: [require.resolve('./node')], // TODO: remove that extends and provide a standalone configuration
8
- plugins: [],
9
- rules: {
10
- 'accessor-pairs': error,
11
- 'array-bracket-newline': off,
12
- 'array-bracket-spacing': [error, 'never'],
13
- 'array-callback-return': error,
14
- 'array-element-newline': off,
15
- 'arrow-body-style': [
16
- 'error',
17
- 'as-needed',
18
- {
19
- requireReturnForObjectLiteral: false,
20
- },
21
- ],
22
- 'arrow-parens': [error, 'always'],
23
- 'arrow-spacing': [error, { after: true, before: true }],
24
- 'block-scoped-var': error,
25
- 'block-spacing': [error, 'always'],
26
- 'brace-style': [error, '1tbs', { allowSingleLine: false }],
27
- camelcase: off,
28
- 'capitalized-comments': off,
29
- 'class-methods-use-this': off,
30
- 'comma-dangle': [error, 'always-multiline'],
31
- 'comma-spacing': [error, { after: true, before: false }],
32
- 'comma-style': [error, 'last'],
33
- complexity: [error, 20],
34
- 'computed-property-spacing': [error, 'never'],
35
- 'consistent-return': error,
36
- 'consistent-this': [error, 'self'],
37
- 'constructor-super': error,
38
- curly: error,
39
- 'default-case': [error, { commentPattern: '^no default$' }], // require default case in switch statements or ignore by adding `//no default`
40
- 'dot-location': [error, 'property'],
41
- 'dot-notation': error,
42
- 'eol-last': error,
43
- eqeqeq: [error, 'smart'],
44
- 'for-direction': error,
45
- 'func-call-spacing': [error, 'never'],
46
- 'func-name-matching': error,
47
- 'func-names': off,
48
- 'func-style': off,
49
- 'function-paren-newline': [error, 'consistent'],
50
- 'generator-star-spacing': [error, { after: false, before: true }],
51
- 'getter-return': [error, { allowImplicit: true }],
52
- 'guard-for-in': error,
53
- 'id-length': [error, { exceptions: ['t', '$', '_', 'x', 'y', 'z'], max: 50, min: 2, properties: 'never' }],
54
- 'id-match': off,
55
- 'implicit-arrow-linebreak': [error, 'beside'],
56
- indent: [error, 2],
57
- 'init-declarations': off,
58
- 'jsx-quotes': [error, 'prefer-double'],
59
- 'key-spacing': [
60
- error,
61
- {
62
- afterColon: true,
63
- beforeColon: false,
64
- },
65
- ],
66
- 'keyword-spacing': [
67
- error,
68
- {
69
- after: true,
70
- before: true,
71
- },
72
- ],
73
- 'line-comment-position': 0,
74
- 'linebreak-style': [error, 'unix'],
75
- 'lines-around-comment': [
76
- error,
77
- {
78
- allowArrayEnd: true,
79
- allowArrayStart: true,
80
- allowBlockEnd: true,
81
- allowBlockStart: true,
82
- allowObjectEnd: true,
83
- allowObjectStart: true,
84
- beforeBlockComment: true,
85
- beforeLineComment: true,
86
- },
87
- ],
88
- 'lines-around-directive': [error, 'always'],
89
- 'lines-between-class-members': [error, 'always', { exceptAfterSingleLine: true }],
90
- 'max-len': [
91
- warn,
92
- {
93
- code: 160,
94
- },
95
- ],
96
- 'max-nested-callbacks': [warn, { max: 5 }],
97
- 'max-statements-per-line': [
98
- error,
99
- {
100
- max: 1,
101
- },
102
- ],
103
- 'multiline-comment-style': off,
104
- 'multiline-ternary': off,
105
- 'new-cap': [
106
- off,
107
- {
108
- capIsNew: false,
109
- newIsCap: true,
110
- },
111
- ],
112
- 'new-parens': error,
113
- 'newline-after-var': off,
114
- 'newline-before-return': error,
115
- 'newline-per-chained-call': off,
116
- 'no-alert': error,
117
- 'no-array-constructor': error,
118
- 'no-async-promise-executor': error,
119
- 'no-await-in-loop': error,
120
- 'no-caller': error,
121
- 'no-case-declarations': error,
122
- 'no-catch-shadow': error,
123
- 'no-class-assign': error,
124
- 'no-compare-neg-zero': error,
125
- 'no-cond-assign': error,
126
- 'no-confusing-arrow': error,
127
- 'no-console': error,
128
- 'no-const-assign': error,
129
- 'no-constant-condition': warn,
130
- 'no-continue': off,
131
- 'no-control-regex': error,
132
- 'no-debugger': error,
133
- 'no-delete-var': error,
134
- 'no-div-regex': error,
135
- 'no-dupe-args': error,
136
- 'no-dupe-class-members': error,
137
- 'no-dupe-else-if': error,
138
- 'no-dupe-keys': error,
139
- 'no-duplicate-case': error,
140
- 'no-duplicate-imports': off,
141
- 'no-else-return': [error, { allowElseIf: false }],
142
- 'no-empty': error,
143
- 'no-empty-character-class': error,
144
- 'no-empty-function': [error, { allow: ['arrowFunctions', 'functions', 'methods'] }],
145
- 'no-empty-pattern': error,
146
- 'no-eq-null': off,
147
- 'no-eval': error,
148
- 'no-ex-assign': error,
149
- 'no-extend-native': error,
150
- 'no-extra-bind': error,
151
- 'no-extra-boolean-cast': error,
152
- 'no-extra-parens': error,
153
- 'no-extra-semi': error,
154
- 'no-fallthrough': error,
155
- 'no-floating-decimal': error,
156
- 'no-func-assign': error,
157
- 'no-global-assign': error,
158
- 'no-implicit-coercion': error,
159
- 'no-implicit-globals': off,
160
- 'no-implied-eval': error,
161
- 'no-import-assign': error,
162
- 'no-inline-comments': off,
163
- 'no-inner-declarations': error,
164
- 'no-invalid-regexp': error,
165
- 'no-invalid-this': off,
166
- 'no-irregular-whitespace': error,
167
- 'no-iterator': error,
168
- 'no-label-var': error,
169
- 'no-labels': error,
170
- 'no-lone-blocks': error,
171
- 'no-lonely-if': error,
172
- 'no-loop-func': error,
173
- 'no-loss-of-precision': error,
174
- 'no-magic-numbers': off,
175
- 'no-misleading-character-class': error,
176
- 'no-mixed-spaces-and-tabs': error,
177
- 'no-multi-spaces': [
178
- error,
179
- {
180
- ignoreEOLComments: false,
181
- },
182
- ],
183
- 'no-multi-str': error,
184
- 'no-multiple-empty-lines': [
185
- error,
186
- {
187
- max: 1,
188
- maxBOF: 0,
189
- maxEOF: 1,
190
- },
191
- ],
192
- 'no-native-reassign': error,
193
- 'no-negated-condition': off,
194
- 'no-negated-in-lhs': error,
195
- 'no-nested-ternary': off,
196
- 'no-new': error,
197
- 'no-new-func': error,
198
- 'no-new-object': error,
199
- 'no-new-require': error,
200
- 'no-new-symbol': error,
201
- 'no-new-wrappers': error,
202
- 'no-obj-calls': error,
203
- 'no-octal': error,
204
- 'no-octal-escape': error,
205
- 'no-param-reassign': [
206
- error,
207
- {
208
- props: false,
209
- },
210
- ],
211
- 'no-plusplus': error,
212
- 'no-promise-executor-return': error,
213
- 'no-proto': error,
214
- 'no-prototype-builtins': error,
215
- 'no-redeclare': [
216
- error,
217
- {
218
- builtinGlobals: true,
219
- },
220
- ],
221
- 'no-regex-spaces': error,
222
- 'no-restricted-globals': off,
223
- 'no-restricted-properties': [
224
- error,
225
- {
226
- message: 'arguments.callee is deprecated',
227
- object: 'arguments',
228
- property: 'callee',
229
- },
230
- {
231
- message: 'Please use Number.isFinite instead',
232
- object: 'global',
233
- property: 'isFinite',
234
- },
235
- {
236
- message: 'Please use Number.isFinite instead',
237
- object: 'self',
238
- property: 'isFinite',
239
- },
240
- {
241
- message: 'Please use Number.isFinite instead',
242
- object: 'window',
243
- property: 'isFinite',
244
- },
245
- {
246
- message: 'Please use Number.isNaN instead',
247
- object: 'global',
248
- property: 'isNaN',
249
- },
250
- {
251
- message: 'Please use Number.isNaN instead',
252
- object: 'self',
253
- property: 'isNaN',
254
- },
255
- {
256
- message: 'Please use Number.isNaN instead',
257
- object: 'window',
258
- property: 'isNaN',
259
- },
260
- {
261
- message: 'Please use Object.defineProperty instead.',
262
- property: '__defineGetter__',
263
- },
264
- {
265
- message: 'Please use Object.defineProperty instead.',
266
- property: '__defineSetter__',
267
- },
268
- {
269
- message: 'Use the exponentiation operator (**) instead.',
270
- object: 'Math',
271
- property: 'pow',
272
- },
273
- ],
274
- 'no-restricted-syntax': [
275
- error,
276
- {
277
- message:
278
- 'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.',
279
- selector: 'ForInStatement',
280
- },
281
- {
282
- message: 'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
283
- selector: 'LabeledStatement',
284
- },
285
- {
286
- message: '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
287
- selector: 'WithStatement',
288
- },
289
- ],
290
- 'no-return-assign': error,
291
- 'no-return-await': error,
292
- 'no-script-url': error,
293
- 'no-self-assign': error,
294
- 'no-self-compare': error,
295
- 'no-sequences': error,
296
- 'no-setter-return': error,
297
- 'no-shadow': [
298
- error,
299
- {
300
- builtinGlobals: false,
301
- hoist: 'all',
302
- },
303
- ],
304
- 'no-shadow-restricted-names': error,
305
- 'no-spaced-func': error,
306
- 'no-sparse-arrays': error,
307
- 'no-sync': off,
308
- 'no-tabs': error,
309
- 'no-template-curly-in-string': error,
310
- 'no-ternary': off,
311
- 'no-this-before-super': error,
312
- 'no-throw-literal': error,
313
- 'no-trailing-spaces': error,
314
- 'no-undef': error,
315
- 'no-undef-init': error,
316
- 'no-undefined': off,
317
- 'no-underscore-dangle': off,
318
- 'no-unexpected-multiline': error,
319
- 'no-unmodified-loop-condition': error,
320
- 'no-unneeded-ternary': off, // error,
321
- 'no-unreachable': error,
322
- 'no-unreachable-loop': error,
323
- 'no-unsafe-finally': error,
324
- 'no-unsafe-negation': error,
325
- 'no-unsafe-optional-chaining': [error, { disallowArithmeticOperators: true }],
326
- 'no-unused-expressions': [
327
- error,
328
- {
329
- allowShortCircuit: false,
330
- allowTaggedTemplates: true,
331
- allowTernary: false,
332
- },
333
- ],
334
- 'no-unused-vars': [
335
- error,
336
- {
337
- args: 'none',
338
- ignoreRestSiblings: true,
339
- vars: 'all',
340
- },
341
- ],
342
- 'no-use-before-define': [
343
- error,
344
- {
345
- classes: false,
346
- functions: false,
347
- variables: false,
348
- },
349
- ],
350
- 'no-useless-backreference': error,
351
- 'no-useless-call': error,
352
- 'no-useless-catch': error,
353
- 'no-useless-computed-key': error,
354
- 'no-useless-concat': error,
355
- 'no-useless-constructor': error,
356
- 'no-useless-escape': error,
357
- 'no-useless-rename': [
358
- error,
359
- {
360
- ignoreDestructuring: false,
361
- ignoreExport: false,
362
- ignoreImport: false,
363
- },
364
- ],
365
- 'no-useless-return': error,
366
- 'no-var': error,
367
- 'no-void': error,
368
- 'no-warning-comments': [
369
- off,
370
- {
371
- location: 'start',
372
- terms: ['todo', '@todo'],
373
- },
374
- ],
375
- 'no-whitespace-before-property': error,
376
- 'no-with': error,
377
- 'nonblock-statement-body-position': [error, 'below'],
378
- 'object-curly-spacing': [off, 'never'],
379
- 'object-property-newline': [
380
- error,
381
- {
382
- allowMultiplePropertiesPerLine: false,
383
- },
384
- ],
385
- 'object-shorthand': [error, 'always'],
386
- 'one-var': [error, 'never'],
387
- 'one-var-declaration-per-line': error,
388
- 'operator-assignment': [error, 'always'],
389
- 'operator-linebreak': [error, 'after'],
390
- 'padded-blocks': [error, 'never'],
391
- 'padding-line-between-statements': off,
392
- 'prefer-arrow-callback': [
393
- error,
394
- {
395
- allowNamedFunctions: false,
396
- allowUnboundThis: true,
397
- },
398
- ],
399
- 'prefer-const': error,
400
- 'prefer-destructuring': off,
401
- 'prefer-named-capture-group': off,
402
- 'prefer-numeric-literals': error,
403
- 'prefer-promise-reject-errors': error,
404
- 'prefer-reflect': off,
405
- 'prefer-rest-params': error,
406
- 'prefer-spread': error,
407
- 'prefer-template': error,
408
- 'quote-props': [error, 'as-needed'],
409
- quotes: [error, 'single'],
410
- radix: error,
411
- 'require-await': off, // https://github.com/airbnb/javascript/issues/2013
412
- 'require-jsdoc': off,
413
- 'require-yield': error,
414
- semi: [error, 'always'],
415
- 'semi-spacing': [
416
- error,
417
- {
418
- after: true,
419
- before: false,
420
- },
421
- ],
422
- 'semi-style': [error, 'last'],
423
- 'sort-keys': off /* [
424
- error,
425
- 'asc',
426
- {
427
- caseSensitive: false,
428
- natural: true
429
- }
430
- ], */,
431
- 'sort-vars': error,
432
- 'space-before-blocks': [error, 'always'],
433
- 'space-before-function-paren': [error, 'always'],
434
- 'space-in-parens': [error, 'never'],
435
- 'space-infix-ops': error,
436
- 'space-unary-ops': [
437
- error,
438
- {
439
- nonwords: false,
440
- words: true,
441
- },
442
- ],
443
- 'spaced-comment': [
444
- error,
445
- 'always',
446
- {
447
- block: {
448
- balanced: true,
449
- exceptions: ['*'],
450
- markers: ['*package', '!', ',', ':', '::', 'flow-include'],
451
- },
452
- line: {
453
- markers: ['*package', '!', '/', ',', '='],
454
- },
455
- },
456
- ],
457
- strict: [error, 'never'],
458
- 'switch-colon-spacing': [
459
- error,
460
- {
461
- after: true,
462
- before: false,
463
- },
464
- ],
465
- 'symbol-description': error,
466
- 'template-tag-spacing': [error, 'never'],
467
- 'unicode-bom': [error, 'never'],
468
- 'use-isnan': error,
469
- 'valid-jsdoc': off,
470
- 'valid-typeof': [error, { requireStringLiterals: true }],
471
- 'vars-on-top': error,
472
- 'wrap-iife': [error, 'inside'],
473
- 'wrap-regex': off,
474
- yoda: off,
475
- },
476
- };
3
+ module.exports = concatESConfig(
4
+ // @ts-ignore
5
+ require('eslint-config-airbnb-base/rules/best-practices'),
6
+ // @ts-ignore
7
+ require('eslint-config-airbnb-base/rules/errors'),
8
+ // @ts-ignore
9
+ require('eslint-config-airbnb-base/rules/es6'),
10
+ // we use our own import configuration
11
+ // require('eslint-config-airbnb-base/rules/imports'),
12
+ // @ts-ignore
13
+ require('eslint-config-airbnb-base/rules/node'),
14
+ // @ts-ignore
15
+ require('eslint-config-airbnb-base/rules/strict'),
16
+ // @ts-ignore
17
+ require('eslint-config-airbnb-base/rules/style'),
18
+ // @ts-ignore
19
+ require('eslint-config-airbnb-base/rules/variables'),
20
+
21
+ // overrides
22
+ {
23
+ rules: {
24
+ // Often useful in jsx
25
+ 'no-nested-ternary': off,
26
+ },
27
+ }
28
+ );
@@ -1,5 +1,8 @@
1
1
  const { fixme, off, warn, error } = require('./_rule');
2
- const { rules: baseRules } = require('./base');
2
+ const { rules: _baseRules } = require('./base');
3
+
4
+ // Fix : TS pluging seems to modify the rules
5
+ const baseRules = JSON.parse(JSON.stringify(_baseRules));
3
6
 
4
7
  const duplicateTSC = off; // = "off because tsc already checks that"
5
8
 
package/rules/node.js DELETED
@@ -1,21 +0,0 @@
1
- const { off, error } = require('./_rule');
2
-
3
- // @see https://eslint.org/blog/2020/02/whats-coming-in-eslint-7.0.0#deprecating-node-js-commonjs-specific-rules
4
- module.exports = {
5
- env: {
6
- node: true,
7
- },
8
- rules: {
9
- 'callback-return': off,
10
- 'global-require': error,
11
- 'handle-callback-err': off,
12
- 'no-buffer-constructor': error,
13
- 'no-mixed-requires': [off, false],
14
- 'no-new-require': error,
15
- 'no-path-concat': error,
16
- 'no-process-env': off,
17
- 'no-process-exit': off,
18
- 'no-restricted-modules': off,
19
- 'no-sync': off,
20
- },
21
- };