@bhsd/code-standard 1.2.0 → 1.3.1

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.
Files changed (3) hide show
  1. package/eslint.mjs +1120 -0
  2. package/eslintrc.cjs +1 -1
  3. package/package.json +21 -13
package/eslint.mjs ADDED
@@ -0,0 +1,1120 @@
1
+ import js from '@eslint/js';
2
+ import stylistic from '@stylistic/eslint-plugin';
3
+ import promise from 'eslint-plugin-promise';
4
+ import regexp from 'eslint-plugin-regexp';
5
+ import unicorn from 'eslint-plugin-unicorn';
6
+ import jsdoc from 'eslint-plugin-jsdoc';
7
+ import eslintComments from 'eslint-plugin-eslint-comments';
8
+ import jsonc from 'eslint-plugin-jsonc';
9
+ import typescriptEslint from '@typescript-eslint/eslint-plugin';
10
+ import n from 'eslint-plugin-n';
11
+ import esX from 'eslint-plugin-es-x';
12
+ import globals from 'globals';
13
+
14
+ const tsRecommended = typescriptEslint.configs['flat/recommended-type-checked'],
15
+ files = ['**/*.ts'];
16
+ const getConfig = rules => ({
17
+ languageOptions: {
18
+ globals: globals.browser,
19
+ },
20
+ plugins: {'es-x': esX},
21
+ settings: {
22
+ 'es-x': {
23
+ aggressive: true,
24
+ },
25
+ },
26
+ rules,
27
+ });
28
+ export const ignores = {
29
+ ignores: [
30
+ '**/dist/',
31
+ '**/build/',
32
+ ],
33
+ },
34
+ general = [
35
+ js.configs.recommended,
36
+ promise.configs['flat/recommended'],
37
+ regexp.configs['flat/recommended'],
38
+ {
39
+ languageOptions: {
40
+ ecmaVersion: 'latest',
41
+ },
42
+ rules: {
43
+ 'array-callback-return': 2,
44
+ 'no-cond-assign': [
45
+ 2,
46
+ 'always',
47
+ ],
48
+ 'no-constant-binary-expression': 2,
49
+ 'no-constructor-return': 2,
50
+ 'no-fallthrough': 2,
51
+ 'no-inner-declarations': [
52
+ 2,
53
+ 'both',
54
+ ],
55
+ 'no-irregular-whitespace': [
56
+ 2,
57
+ {
58
+ skipStrings: false,
59
+ },
60
+ ],
61
+ 'no-promise-executor-return': 2,
62
+ 'no-self-compare': 2,
63
+ 'no-template-curly-in-string': 2,
64
+ 'no-unassigned-vars': 2,
65
+ 'no-undef': [
66
+ 2,
67
+ {
68
+ typeof: true,
69
+ },
70
+ ],
71
+ 'no-unmodified-loop-condition': 2,
72
+ 'no-unreachable-loop': 2,
73
+ 'no-unsafe-negation': [
74
+ 2,
75
+ {
76
+ enforceForOrderingRelations: true,
77
+ },
78
+ ],
79
+ 'no-unsafe-optional-chaining': [
80
+ 2,
81
+ {
82
+ disallowArithmeticOperators: true,
83
+ },
84
+ ],
85
+ 'no-unused-private-class-members': 2,
86
+ 'no-unused-vars': [
87
+ 2,
88
+ {
89
+ args: 'all',
90
+ argsIgnorePattern: '^_+$',
91
+ caughtErrors: 'all',
92
+ ignoreRestSiblings: true,
93
+ },
94
+ ],
95
+ 'no-use-before-define': [
96
+ 2,
97
+ {
98
+ functions: false,
99
+ variables: false,
100
+ },
101
+ ],
102
+ 'no-useless-assignment': 2,
103
+ 'require-atomic-updates': [
104
+ 2,
105
+ {
106
+ allowProperties: true,
107
+ },
108
+ ],
109
+ 'use-isnan': [
110
+ 2,
111
+ {
112
+ enforceForIndexOf: true,
113
+ },
114
+ ],
115
+ 'valid-typeof': [
116
+ 2,
117
+ {
118
+ requireStringLiterals: true,
119
+ },
120
+ ],
121
+ 'accessor-pairs': 2,
122
+ 'arrow-body-style': 2,
123
+ 'block-scoped-var': 2,
124
+ camelcase: 2,
125
+ 'class-methods-use-this': 2,
126
+ 'consistent-return': 2,
127
+ curly: 2,
128
+ 'default-case': 2,
129
+ 'default-case-last': 2,
130
+ 'default-param-last': 2,
131
+ 'dot-notation': 2,
132
+ eqeqeq: 2,
133
+ 'func-name-matching': [
134
+ 2,
135
+ {
136
+ considerPropertyDescriptor: true,
137
+ },
138
+ ],
139
+ 'func-names': [
140
+ 2,
141
+ 'never',
142
+ ],
143
+ 'func-style': 2,
144
+ 'grouped-accessor-pairs': [
145
+ 2,
146
+ 'getBeforeSet',
147
+ ],
148
+ 'guard-for-in': 2,
149
+ 'logical-assignment-operators': [
150
+ 2,
151
+ 'always',
152
+ {
153
+ enforceForIfStatements: true,
154
+ },
155
+ ],
156
+ 'new-cap': 2,
157
+ 'no-alert': 2,
158
+ 'no-array-constructor': 2,
159
+ 'no-bitwise': 2,
160
+ 'no-caller': 2,
161
+ 'no-else-return': 2,
162
+ 'no-empty': [
163
+ 2,
164
+ {
165
+ allowEmptyCatch: true,
166
+ },
167
+ ],
168
+ 'no-empty-function': [
169
+ 2,
170
+ {
171
+ allow: ['arrowFunctions'],
172
+ },
173
+ ],
174
+ 'no-empty-static-block': 2,
175
+ 'no-eval': 2,
176
+ 'no-extend-native': 2,
177
+ 'no-extra-bind': 2,
178
+ 'no-extra-boolean-cast': [
179
+ 2,
180
+ {
181
+ enforceForLogicalOperands: true,
182
+ },
183
+ ],
184
+ 'no-implicit-coercion': 2,
185
+ 'no-implicit-globals': 2,
186
+ 'no-implied-eval': 2,
187
+ 'no-invalid-this': [
188
+ 2,
189
+ {
190
+ capIsConstructor: false,
191
+ },
192
+ ],
193
+ 'no-lone-blocks': 2,
194
+ 'no-lonely-if': 2,
195
+ 'no-loop-func': 2,
196
+ 'no-multi-assign': 2,
197
+ 'no-multi-str': 2,
198
+ 'no-nested-ternary': 2,
199
+ 'no-new': 2,
200
+ 'no-new-func': 2,
201
+ 'no-new-object': 2,
202
+ 'no-new-wrappers': 2,
203
+ 'no-octal-escape': 2,
204
+ 'no-param-reassign': 2,
205
+ 'no-return-assign': [
206
+ 2,
207
+ 'always',
208
+ ],
209
+ 'no-return-await': 2,
210
+ 'no-script-url': 2,
211
+ 'no-sequences': [
212
+ 2,
213
+ {
214
+ allowInParentheses: false,
215
+ },
216
+ ],
217
+ 'no-shadow': [
218
+ 2,
219
+ {
220
+ builtinGlobals: true,
221
+ },
222
+ ],
223
+ 'no-throw-literal': 2,
224
+ 'no-undef-init': 2,
225
+ 'no-underscore-dangle': [
226
+ 2,
227
+ {
228
+ allow: [
229
+ '_',
230
+ '__',
231
+ ],
232
+ enforceInMethodNames: true,
233
+ enforceInClassFields: true,
234
+ allowInArrayDestructuring: false,
235
+ allowInObjectDestructuring: false,
236
+ allowFunctionParams: false,
237
+ },
238
+ ],
239
+ 'no-unneeded-ternary': [
240
+ 2,
241
+ {
242
+ defaultAssignment: false,
243
+ },
244
+ ],
245
+ 'no-unused-expressions': 2,
246
+ 'no-useless-call': 2,
247
+ 'no-useless-computed-key': [
248
+ 2,
249
+ {
250
+ enforceForClassMembers: true,
251
+ },
252
+ ],
253
+ 'no-useless-concat': 2,
254
+ 'no-useless-constructor': 2,
255
+ 'no-useless-return': 2,
256
+ 'no-var': 2,
257
+ 'no-void': [
258
+ 2,
259
+ {
260
+ allowAsStatement: true,
261
+ },
262
+ ],
263
+ 'object-shorthand': 2,
264
+ 'operator-assignment': 2,
265
+ 'prefer-arrow-callback': 2,
266
+ 'prefer-const': 2,
267
+ 'prefer-destructuring': [
268
+ 2,
269
+ {
270
+ VariableDeclarator: {
271
+ array: true,
272
+ object: true,
273
+ },
274
+ AssignmentExpression: {
275
+ array: true,
276
+ object: true,
277
+ },
278
+ },
279
+ ],
280
+ 'prefer-exponentiation-operator': 2,
281
+ 'prefer-numeric-literals': 2,
282
+ 'prefer-object-has-own': 2,
283
+ 'prefer-object-spread': 2,
284
+ 'prefer-regex-literals': [
285
+ 2,
286
+ {
287
+ disallowRedundantWrapping: true,
288
+ },
289
+ ],
290
+ 'prefer-rest-params': 2,
291
+ 'prefer-spread': 2,
292
+ 'prefer-template': 2,
293
+ radix: [
294
+ 2,
295
+ 'as-needed',
296
+ ],
297
+ 'require-await': 2,
298
+ 'require-unicode-regexp': 2,
299
+ strict: 2,
300
+ 'symbol-description': 2,
301
+ 'vars-on-top': 2,
302
+ yoda: 2,
303
+ 'promise/always-return': [
304
+ 2,
305
+ {
306
+ ignoreLastCallback: true,
307
+ },
308
+ ],
309
+ 'promise/catch-or-return': [
310
+ 2,
311
+ {
312
+ allowThen: true,
313
+ },
314
+ ],
315
+ 'promise/no-multiple-resolved': 2,
316
+ 'promise/prefer-await-to-then': 2,
317
+ 'promise/spec-only': 2,
318
+ 'regexp/no-dupe-disjunctions': [
319
+ 2,
320
+ {
321
+ report: 'interesting',
322
+ },
323
+ ],
324
+ 'regexp/no-misleading-capturing-group': [
325
+ 2,
326
+ {
327
+ reportBacktrackingEnds: false,
328
+ },
329
+ ],
330
+ 'regexp/no-super-linear-move': 2,
331
+ 'regexp/no-octal': 2,
332
+ 'regexp/no-standalone-backslash': 2,
333
+ 'regexp/no-useless-character-class': [
334
+ 2,
335
+ {
336
+ ignores: [],
337
+ },
338
+ ],
339
+ 'regexp/prefer-escape-replacement-dollar-char': 2,
340
+ 'regexp/prefer-quantifier': 2,
341
+ 'regexp/prefer-regexp-exec': 2,
342
+ 'regexp/prefer-regexp-test': 2,
343
+ 'regexp/hexadecimal-escape': 2,
344
+ 'regexp/letter-case': [
345
+ 2,
346
+ {
347
+ unicodeEscape: 'uppercase',
348
+ hexadecimalEscape: 'uppercase',
349
+ controlEscape: 'uppercase',
350
+ },
351
+ ],
352
+ 'regexp/prefer-character-class': [
353
+ 2,
354
+ {
355
+ minAlternatives: 2,
356
+ },
357
+ ],
358
+ 'regexp/prefer-lookaround': [
359
+ 2,
360
+ {
361
+ lookbehind: false,
362
+ },
363
+ ],
364
+ 'regexp/unicode-property': 2,
365
+ },
366
+ },
367
+ {
368
+ plugins: {'@stylistic': stylistic},
369
+ rules: {
370
+ '@stylistic/array-bracket-newline': [
371
+ 2,
372
+ {
373
+ multiline: true,
374
+ },
375
+ ],
376
+ '@stylistic/array-bracket-spacing': 2,
377
+ '@stylistic/array-element-newline': [
378
+ 2,
379
+ 'consistent',
380
+ ],
381
+ '@stylistic/arrow-parens': [
382
+ 2,
383
+ 'as-needed',
384
+ ],
385
+ '@stylistic/arrow-spacing': 2,
386
+ '@stylistic/block-spacing': [
387
+ 2,
388
+ 'never',
389
+ ],
390
+ '@stylistic/brace-style': 2,
391
+ '@stylistic/comma-dangle': [
392
+ 2,
393
+ 'always-multiline',
394
+ ],
395
+ '@stylistic/comma-spacing': 2,
396
+ '@stylistic/comma-style': 2,
397
+ '@stylistic/computed-property-spacing': 2,
398
+ '@stylistic/dot-location': [
399
+ 2,
400
+ 'property',
401
+ ],
402
+ '@stylistic/eol-last': 2,
403
+ '@stylistic/function-call-argument-newline': [
404
+ 2,
405
+ 'consistent',
406
+ ],
407
+ '@stylistic/function-call-spacing': 2,
408
+ '@stylistic/function-paren-newline': [
409
+ 2,
410
+ 'multiline-arguments',
411
+ ],
412
+ '@stylistic/indent': [
413
+ 2,
414
+ 'tab',
415
+ {
416
+ SwitchCase: 1,
417
+ },
418
+ ],
419
+ '@stylistic/indent-binary-ops': [
420
+ 2,
421
+ 'tab',
422
+ ],
423
+ '@stylistic/key-spacing': 2,
424
+ '@stylistic/keyword-spacing': 2,
425
+ '@stylistic/linebreak-style': 2,
426
+ '@stylistic/lines-around-comment': [
427
+ 2,
428
+ {
429
+ allowBlockStart: true,
430
+ ignorePattern: String.raw`^\* @`,
431
+ },
432
+ ],
433
+ '@stylistic/lines-between-class-members': [
434
+ 2,
435
+ 'always',
436
+ {
437
+ exceptAfterSingleLine: true,
438
+ },
439
+ ],
440
+ '@stylistic/max-len': [
441
+ 2,
442
+ {
443
+ code: 120,
444
+ ignoreRegExpLiterals: true,
445
+ },
446
+ ],
447
+ '@stylistic/multiline-comment-style': [
448
+ 2,
449
+ 'separate-lines',
450
+ ],
451
+ '@stylistic/multiline-ternary': [
452
+ 2,
453
+ 'always-multiline',
454
+ ],
455
+ '@stylistic/new-parens': 2,
456
+ '@stylistic/newline-per-chained-call': [
457
+ 2,
458
+ {
459
+ ignoreChainWithDepth: 4,
460
+ },
461
+ ],
462
+ '@stylistic/no-extra-parens': [
463
+ 2,
464
+ 'all',
465
+ {
466
+ allowParensAfterCommentPattern: '@type',
467
+ },
468
+ ],
469
+ '@stylistic/no-extra-semi': 2,
470
+ '@stylistic/no-floating-decimal': 2,
471
+ '@stylistic/no-mixed-spaces-and-tabs': 2,
472
+ '@stylistic/no-multi-spaces': [
473
+ 2,
474
+ {
475
+ exceptions: {},
476
+ },
477
+ ],
478
+ '@stylistic/no-multiple-empty-lines': [
479
+ 2,
480
+ {
481
+ max: 1,
482
+ maxBOF: 0,
483
+ },
484
+ ],
485
+ '@stylistic/no-tabs': [
486
+ 2,
487
+ {
488
+ allowIndentationTabs: true,
489
+ },
490
+ ],
491
+ '@stylistic/no-trailing-spaces': 2,
492
+ '@stylistic/no-whitespace-before-property': 2,
493
+ '@stylistic/object-curly-newline': [
494
+ 2,
495
+ {
496
+ multiline: true,
497
+ consistent: true,
498
+ },
499
+ ],
500
+ '@stylistic/object-curly-spacing': 2,
501
+ '@stylistic/object-property-newline': [
502
+ 2,
503
+ {
504
+ allowAllPropertiesOnSameLine: true,
505
+ },
506
+ ],
507
+ '@stylistic/one-var-declaration-per-line': 2,
508
+ '@stylistic/operator-linebreak': [
509
+ 2,
510
+ 'before',
511
+ {
512
+ overrides: {
513
+ '=': 'after',
514
+ },
515
+ },
516
+ ],
517
+ '@stylistic/padded-blocks': [
518
+ 2,
519
+ 'never',
520
+ ],
521
+ '@stylistic/quote-props': [
522
+ 2,
523
+ 'as-needed',
524
+ ],
525
+ '@stylistic/quotes': [
526
+ 2,
527
+ 'single',
528
+ {
529
+ allowTemplateLiterals: 'avoidEscape',
530
+ avoidEscape: true,
531
+ },
532
+ ],
533
+ '@stylistic/rest-spread-spacing': 2,
534
+ '@stylistic/semi': 2,
535
+ '@stylistic/semi-spacing': 2,
536
+ '@stylistic/semi-style': 2,
537
+ '@stylistic/space-before-blocks': 2,
538
+ '@stylistic/space-before-function-paren': [
539
+ 2,
540
+ {
541
+ anonymous: 'never',
542
+ named: 'never',
543
+ asyncArrow: 'always',
544
+ },
545
+ ],
546
+ '@stylistic/space-in-parens': 2,
547
+ '@stylistic/space-infix-ops': 2,
548
+ '@stylistic/space-unary-ops': 2,
549
+ '@stylistic/spaced-comment': 2,
550
+ '@stylistic/switch-colon-spacing': 2,
551
+ '@stylistic/template-curly-spacing': 2,
552
+ '@stylistic/wrap-iife': [
553
+ 2,
554
+ 'inside',
555
+ ],
556
+ },
557
+ },
558
+ {
559
+ plugins: {unicorn},
560
+ rules: {
561
+ 'unicorn/catch-error-name': [
562
+ 2,
563
+ {
564
+ name: 'e',
565
+ },
566
+ ],
567
+ 'unicorn/consistent-assert': 2,
568
+ 'unicorn/consistent-date-clone': 2,
569
+ 'unicorn/consistent-existence-index-check': 2,
570
+ 'unicorn/consistent-function-scoping': [
571
+ 2,
572
+ {
573
+ checkArrowFunctions: false,
574
+ },
575
+ ],
576
+ 'unicorn/empty-brace-spaces': 2,
577
+ 'unicorn/error-message': 2,
578
+ 'unicorn/explicit-length-check': 2,
579
+ 'unicorn/new-for-builtins': 2,
580
+ 'unicorn/no-abusive-eslint-disable': 2,
581
+ 'unicorn/no-accessor-recursion': 2,
582
+ 'unicorn/no-array-for-each': 2,
583
+ 'unicorn/no-array-method-this-argument': 2,
584
+ 'unicorn/no-array-reduce': 2,
585
+ 'unicorn/no-await-in-promise-methods': 2,
586
+ 'unicorn/no-immediate-mutation': 2,
587
+ 'unicorn/no-instanceof-builtins': 2,
588
+ 'unicorn/no-invalid-remove-event-listener': 2,
589
+ 'unicorn/no-lonely-if': 2,
590
+ 'unicorn/no-named-default': 2,
591
+ 'unicorn/no-negated-condition': 2,
592
+ 'unicorn/no-negation-in-equality-check': 2,
593
+ 'unicorn/no-object-as-default-parameter': 2,
594
+ 'unicorn/no-single-promise-in-promise-methods': 2,
595
+ 'unicorn/no-static-only-class': 2,
596
+ 'unicorn/no-this-assignment': 2,
597
+ 'unicorn/no-typeof-undefined': [
598
+ 2,
599
+ {
600
+ checkGlobalVariables: true,
601
+ },
602
+ ],
603
+ 'unicorn/no-unnecessary-array-flat-depth': 2,
604
+ 'unicorn/no-unnecessary-array-splice-count': 2,
605
+ 'unicorn/no-unreadable-iife': 2,
606
+ 'unicorn/no-unused-properties': 2,
607
+ 'unicorn/no-useless-collection-argument': 2,
608
+ 'unicorn/no-useless-fallback-in-spread': 2,
609
+ 'unicorn/no-useless-length-check': 2,
610
+ 'unicorn/no-useless-spread': 2,
611
+ 'unicorn/no-useless-switch-case': 2,
612
+ 'unicorn/number-literal-case': 2,
613
+ 'unicorn/numeric-separators-style': 2,
614
+ 'unicorn/prefer-array-find': 2,
615
+ 'unicorn/prefer-array-flat': 2,
616
+ 'unicorn/prefer-array-flat-map': 2,
617
+ 'unicorn/prefer-array-index-of': 2,
618
+ 'unicorn/prefer-array-some': 2,
619
+ 'unicorn/prefer-bigint-literals': 2,
620
+ 'unicorn/prefer-class-fields': 2,
621
+ 'unicorn/prefer-classlist-toggle': 2,
622
+ 'unicorn/prefer-code-point': 2,
623
+ 'unicorn/prefer-default-parameters': 2,
624
+ 'unicorn/prefer-global-this': 2,
625
+ 'unicorn/prefer-includes': 2,
626
+ 'unicorn/prefer-keyboard-event-key': 2,
627
+ 'unicorn/prefer-logical-operator-over-ternary': 2,
628
+ 'unicorn/prefer-math-min-max': 2,
629
+ 'unicorn/prefer-native-coercion-functions': 2,
630
+ 'unicorn/prefer-negative-index': 2,
631
+ 'unicorn/prefer-optional-catch-binding': 2,
632
+ 'unicorn/prefer-prototype-methods': 2,
633
+ 'unicorn/prefer-single-call': 2,
634
+ 'unicorn/prefer-spread': 2,
635
+ 'unicorn/prefer-string-raw': 2,
636
+ 'unicorn/prefer-string-starts-ends-with': 2,
637
+ 'unicorn/prefer-switch': 2,
638
+ 'unicorn/prefer-ternary': 2,
639
+ 'unicorn/require-module-attributes': 2,
640
+ 'unicorn/switch-case-braces': [
641
+ 2,
642
+ 'avoid',
643
+ ],
644
+ 'unicorn/text-encoding-identifier-case': 2,
645
+ 'unicorn/throw-new-error': 2,
646
+ },
647
+ },
648
+ {
649
+ plugins: {'eslint-comments': eslintComments},
650
+ rules: {
651
+ ...eslintComments.configs.recommended.rules,
652
+ 'eslint-comments/disable-enable-pair': [
653
+ 2,
654
+ {
655
+ allowWholeFile: true,
656
+ },
657
+ ],
658
+ },
659
+ },
660
+ ],
661
+ jsDoc = {
662
+ plugins: {jsdoc},
663
+ rules: {
664
+ 'jsdoc/check-alignment': 1,
665
+ 'jsdoc/check-indentation': [
666
+ 1,
667
+ {
668
+ excludeTags: ['description'],
669
+ },
670
+ ],
671
+ 'jsdoc/check-param-names': [
672
+ 1,
673
+ {
674
+ disableMissingParamChecks: true,
675
+ },
676
+ ],
677
+ 'jsdoc/check-tag-names': 1,
678
+ 'jsdoc/check-types': 1,
679
+ 'jsdoc/multiline-blocks': 1,
680
+ 'jsdoc/no-bad-blocks': [
681
+ 1,
682
+ {
683
+ preventAllMultiAsteriskBlocks: true,
684
+ },
685
+ ],
686
+ 'jsdoc/no-multi-asterisks': 1,
687
+ 'jsdoc/require-asterisk-prefix': 1,
688
+ 'jsdoc/require-description': [
689
+ 1,
690
+ {
691
+ exemptedBy: [
692
+ 'license',
693
+ 'type',
694
+ ],
695
+ checkConstructors: false,
696
+ checkSetters: false,
697
+ },
698
+ ],
699
+ 'jsdoc/require-hyphen-before-param-description': [
700
+ 1,
701
+ 'never',
702
+ ],
703
+ 'jsdoc/require-jsdoc': [
704
+ 1,
705
+ {
706
+ contexts: [
707
+ 'FunctionDeclaration:not(TSDeclareFunction + FunctionDeclaration)',
708
+ 'TSDeclareFunction:not(TSDeclareFunction + TSDeclareFunction)',
709
+ 'MethodDefinition:not('
710
+ + 'MethodDefinition:has(TSEmptyBodyFunctionExpression) + MethodDefinition,'
711
+ + "[kind='get'] + [kind='set'],"
712
+ + '[override=true]'
713
+ + ')',
714
+ ],
715
+ exemptEmptyConstructors: true,
716
+ checkGetters: true,
717
+ checkSetters: 'no-getter',
718
+ },
719
+ ],
720
+ 'jsdoc/require-param-description': 1,
721
+ 'jsdoc/require-param-name': 1,
722
+ 'jsdoc/require-param': [
723
+ 1,
724
+ {
725
+ checkConstructors: false,
726
+ },
727
+ ],
728
+ 'jsdoc/require-throws': 1,
729
+ },
730
+ settings: {
731
+ jsdoc: {
732
+ tagNamePreference: {
733
+ augments: 'extends',
734
+ },
735
+ ignorePrivate: true,
736
+ },
737
+ },
738
+ },
739
+ json = [
740
+ ...jsonc.configs['flat/recommended-with-json'],
741
+ {
742
+ files: ['**/*.json'],
743
+ rules: {
744
+ 'jsonc/array-bracket-newline': [
745
+ 2,
746
+ {
747
+ minItems: 1,
748
+ },
749
+ ],
750
+ 'jsonc/array-bracket-spacing': 2,
751
+ 'jsonc/array-element-newline': [
752
+ 2,
753
+ 'always',
754
+ ],
755
+ 'jsonc/comma-style': 2,
756
+ 'jsonc/indent': [
757
+ 2,
758
+ 'tab',
759
+ ],
760
+ 'jsonc/key-spacing': 2,
761
+ 'jsonc/no-irregular-whitespace': 2,
762
+ 'jsonc/no-octal-escape': 2,
763
+ 'jsonc/object-curly-newline': [
764
+ 2,
765
+ {
766
+ minProperties: 1,
767
+ },
768
+ ],
769
+ 'jsonc/object-curly-spacing': 2,
770
+ 'jsonc/object-property-newline': [
771
+ 2,
772
+ {
773
+ allowAllPropertiesOnSameLine: false,
774
+ },
775
+ ],
776
+ '@stylistic/max-len': 0,
777
+ },
778
+ },
779
+ ],
780
+ ts = [
781
+ ...tsRecommended,
782
+ {
783
+ languageOptions: {
784
+ parserOptions: {
785
+ project: './tsconfig.json',
786
+ },
787
+ },
788
+ rules: {
789
+ 'class-methods-use-this': 0,
790
+ '@typescript-eslint/class-methods-use-this': [
791
+ 2,
792
+ {
793
+ ignoreOverrideMethods: true,
794
+ },
795
+ ],
796
+ 'default-param-last': 0,
797
+ '@typescript-eslint/default-param-last': 2,
798
+ 'dot-notation': 0,
799
+ '@typescript-eslint/dot-notation': [
800
+ 2,
801
+ {
802
+ allowIndexSignaturePropertyAccess: true,
803
+ },
804
+ ],
805
+ 'no-empty-function': 0,
806
+ '@typescript-eslint/no-empty-function': [
807
+ 2,
808
+ {
809
+ allow: ['arrowFunctions'],
810
+ },
811
+ ],
812
+ 'no-invalid-this': 0,
813
+ '@typescript-eslint/no-invalid-this': [
814
+ 2,
815
+ {
816
+ capIsConstructor: false,
817
+ },
818
+ ],
819
+ 'no-loop-func': 0,
820
+ '@typescript-eslint/no-loop-func': 2,
821
+ 'no-redeclare': 0,
822
+ '@typescript-eslint/no-redeclare': 2,
823
+ 'no-shadow': 0,
824
+ '@typescript-eslint/no-shadow': [
825
+ 2,
826
+ {
827
+ builtinGlobals: true,
828
+ },
829
+ ],
830
+ 'no-use-before-define': 0,
831
+ '@typescript-eslint/no-use-before-define': [
832
+ 2,
833
+ {
834
+ functions: false,
835
+ variables: false,
836
+ },
837
+ ],
838
+ 'no-useless-constructor': 0,
839
+ '@typescript-eslint/no-useless-constructor': 2,
840
+ 'prefer-destructuring': 0,
841
+ '@typescript-eslint/prefer-destructuring': [
842
+ 2,
843
+ {
844
+ VariableDeclarator: {
845
+ array: true,
846
+ object: true,
847
+ },
848
+ AssignmentExpression: {
849
+ array: true,
850
+ object: true,
851
+ },
852
+ },
853
+ ],
854
+ 'unicorn/prefer-string-starts-ends-with': 0,
855
+ '@typescript-eslint/prefer-string-starts-ends-with': 2,
856
+ '@typescript-eslint/consistent-generic-constructors': 2,
857
+ '@typescript-eslint/consistent-indexed-object-style': 2,
858
+ '@typescript-eslint/consistent-type-assertions': 2,
859
+ '@typescript-eslint/consistent-type-definitions': 2,
860
+ '@typescript-eslint/consistent-type-exports': 2,
861
+ '@typescript-eslint/consistent-type-imports': [
862
+ 2,
863
+ {
864
+ disallowTypeAnnotations: false,
865
+ },
866
+ ],
867
+ '@typescript-eslint/explicit-function-return-type': [
868
+ 2,
869
+ {
870
+ allowIIFEs: true,
871
+ },
872
+ ],
873
+ '@typescript-eslint/method-signature-style': [
874
+ 2,
875
+ 'method',
876
+ ],
877
+ '@typescript-eslint/no-confusing-non-null-assertion': 2,
878
+ '@typescript-eslint/no-confusing-void-expression': 2,
879
+ '@typescript-eslint/no-dupe-class-members': 2,
880
+ '@typescript-eslint/no-empty-object-type': [
881
+ 2,
882
+ {
883
+ allowInterfaces: 'with-single-extends',
884
+ },
885
+ ],
886
+ '@typescript-eslint/no-explicit-any': [
887
+ 2,
888
+ {
889
+ ignoreRestArgs: true,
890
+ },
891
+ ],
892
+ '@typescript-eslint/no-floating-promises': [
893
+ 2,
894
+ {
895
+ ignoreIIFE: true,
896
+ },
897
+ ],
898
+ '@typescript-eslint/no-invalid-void-type': [
899
+ 2,
900
+ {
901
+ allowAsThisParameter: true,
902
+ },
903
+ ],
904
+ '@typescript-eslint/no-misused-spread': [
905
+ 2,
906
+ {
907
+ allow: [
908
+ {
909
+ from: 'lib',
910
+ name: 'string',
911
+ },
912
+ ],
913
+ },
914
+ ],
915
+ '@typescript-eslint/no-namespace': [
916
+ 2,
917
+ {
918
+ allowDeclarations: true,
919
+ },
920
+ ],
921
+ '@typescript-eslint/no-non-null-asserted-nullish-coalescing': 2,
922
+ '@typescript-eslint/no-require-imports': [
923
+ 2,
924
+ {
925
+ allow: [String.raw`.+\.json$`],
926
+ },
927
+ ],
928
+ '@typescript-eslint/no-this-alias': [
929
+ 2,
930
+ {
931
+ allowedNames: ['self'],
932
+ },
933
+ ],
934
+ '@typescript-eslint/no-unnecessary-boolean-literal-compare': 2,
935
+ '@typescript-eslint/no-unnecessary-condition': [
936
+ 2,
937
+ {
938
+ allowConstantLoopConditions: true,
939
+ },
940
+ ],
941
+ '@typescript-eslint/no-unnecessary-qualifier': 2,
942
+ '@typescript-eslint/no-unsafe-assignment': 0,
943
+ '@typescript-eslint/no-unsafe-call': 0,
944
+ '@typescript-eslint/no-unsafe-return': 0,
945
+ '@typescript-eslint/no-useless-empty-export': 2,
946
+ '@typescript-eslint/no-unused-vars': [
947
+ 2,
948
+ {
949
+ args: 'all',
950
+ argsIgnorePattern: '^_+$',
951
+ caughtErrors: 'all',
952
+ ignoreRestSiblings: true,
953
+ },
954
+ ],
955
+ '@typescript-eslint/no-var-requires': 0,
956
+ '@typescript-eslint/non-nullable-type-assertion-style': 2,
957
+ '@typescript-eslint/prefer-for-of': 2,
958
+ '@typescript-eslint/prefer-reduce-type-parameter': 2,
959
+ '@typescript-eslint/prefer-return-this-type': 2,
960
+ '@typescript-eslint/related-getter-setter-pairs': 2,
961
+ '@typescript-eslint/switch-exhaustiveness-check': [
962
+ 2,
963
+ {
964
+ considerDefaultExhaustiveForUnions: true,
965
+ },
966
+ ],
967
+ '@typescript-eslint/unified-signatures': 2,
968
+ 'func-style': 0,
969
+ '@stylistic/member-delimiter-style': [
970
+ 2,
971
+ {
972
+ singleline: {
973
+ delimiter: 'comma',
974
+ },
975
+ },
976
+ ],
977
+ '@stylistic/type-annotation-spacing': [
978
+ 2,
979
+ {
980
+ before: false,
981
+ after: true,
982
+ overrides: {
983
+ arrow: {
984
+ before: true,
985
+ },
986
+ },
987
+ },
988
+ ],
989
+ '@stylistic/type-generic-spacing': 2,
990
+ '@stylistic/type-named-tuple-spacing': 2,
991
+ 'jsdoc/check-types': 0,
992
+ },
993
+ },
994
+ ].map(obj => ({files, ...obj})),
995
+ node = [
996
+ n.configs['flat/recommended-script'],
997
+ {
998
+ files: [
999
+ '**/*.mjs',
1000
+ '**/*.ts',
1001
+ ],
1002
+ languageOptions: {
1003
+ sourceType: 'module',
1004
+ },
1005
+ },
1006
+ {
1007
+ rules: {
1008
+ 'n/exports-style': [
1009
+ 2,
1010
+ 'module.exports',
1011
+ ],
1012
+ 'n/no-missing-import': [
1013
+ 2,
1014
+ {
1015
+ ignoreTypeImport: true,
1016
+ },
1017
+ ],
1018
+ 'n/no-mixed-requires': 2,
1019
+ 'n/no-new-require': 2,
1020
+ 'n/no-path-concat': 2,
1021
+ 'n/no-unsupported-features/node-builtins': [
1022
+ 2,
1023
+ {
1024
+ allowExperimental: true,
1025
+ },
1026
+ ],
1027
+ },
1028
+ settings: {
1029
+ n: {
1030
+ tryExtensions: [
1031
+ '.js',
1032
+ '.json',
1033
+ '.ts',
1034
+ ],
1035
+ },
1036
+ },
1037
+ },
1038
+ ],
1039
+ browser = getConfig({
1040
+ 'prefer-object-has-own': 0,
1041
+ 'es-x/no-array-prototype-at': 2,
1042
+ 'es-x/no-array-prototype-findlast-findlastindex': 2,
1043
+ 'es-x/no-array-prototype-toreversed': 2,
1044
+ 'es-x/no-array-prototype-tosorted': 2,
1045
+ 'es-x/no-array-prototype-tospliced': 2,
1046
+ 'es-x/no-array-prototype-with': 2,
1047
+ 'es-x/no-dataview-prototype-getfloat16-setfloat16': 2,
1048
+ 'es-x/no-error-cause': 2,
1049
+ 'es-x/no-float16array': 2,
1050
+ 'es-x/no-iterator': 2,
1051
+ 'es-x/no-iterator-prototype-drop': 2,
1052
+ 'es-x/no-iterator-prototype-take': 2,
1053
+ 'es-x/no-iterator-prototype-toarray': 2,
1054
+ 'es-x/no-map-groupby': 2,
1055
+ 'es-x/no-math-f16round': 2,
1056
+ 'es-x/no-object-groupby': 2,
1057
+ 'es-x/no-object-hasown': 2,
1058
+ 'es-x/no-promise-any': 2,
1059
+ 'es-x/no-promise-try': 2,
1060
+ 'es-x/no-promise-withresolvers': 2,
1061
+ 'es-x/no-regexp-d-flag': 2,
1062
+ 'es-x/no-regexp-duplicate-named-capturing-groups': 2,
1063
+ 'es-x/no-regexp-escape': 2,
1064
+ 'es-x/no-regexp-lookbehind-assertions': 2,
1065
+ 'es-x/no-regexp-modifiers': 2,
1066
+ 'es-x/no-regexp-v-flag': 2,
1067
+ 'es-x/no-set-prototype-difference': 2,
1068
+ 'es-x/no-set-prototype-intersection': 2,
1069
+ 'es-x/no-set-prototype-isdisjointfrom': 2,
1070
+ 'es-x/no-set-prototype-issubsetof': 2,
1071
+ 'es-x/no-set-prototype-issupersetof': 2,
1072
+ 'es-x/no-set-prototype-symmetricdifference': 2,
1073
+ 'es-x/no-set-prototype-union': 2,
1074
+ 'es-x/no-string-prototype-at': 2,
1075
+ 'es-x/no-string-prototype-iswellformed': 2,
1076
+ 'es-x/no-string-prototype-replaceall': 2,
1077
+ 'es-x/no-string-prototype-towellformed': 2,
1078
+ }),
1079
+ dist = getConfig({
1080
+ ...esX.configs['flat/restrict-to-es2020'].rules,
1081
+ 'es-x/no-iterator-prototype-every': 0,
1082
+ 'es-x/no-iterator-prototype-filter': 0,
1083
+ 'es-x/no-iterator-prototype-find': 0,
1084
+ 'es-x/no-iterator-prototype-flatmap': 0,
1085
+ 'es-x/no-iterator-prototype-foreach': 0,
1086
+ 'es-x/no-iterator-prototype-map': 0,
1087
+ 'es-x/no-iterator-prototype-reduce': 0,
1088
+ 'es-x/no-iterator-prototype-some': 0,
1089
+ 'es-x/no-regexp-lookbehind-assertions': 2,
1090
+ 'es-x/no-regexp-unicode-property-escapes-2020': 2,
1091
+ });
1092
+
1093
+ /**
1094
+ * 添加ESLint配置项
1095
+ * @param {...import('eslint').Linter.Config} args ESLint配置项
1096
+ * @throws `TypeError` 不支持传入配置数组
1097
+ * @throws `RangeError` 未知的配置项类型
1098
+ */
1099
+ export const extend = (...args) => {
1100
+ if (args.some(arg => Array.isArray(arg))) {
1101
+ throw new TypeError('只支持传入单个配置对象,禁止传入配置数组!');
1102
+ }
1103
+ const moreIgnores = args.filter(({files: f, ignores: i}) => !f && i),
1104
+ moreGeneral = args.filter(({files: f, rules, plugins}) => !f && (rules || plugins)),
1105
+ moreFiles = args.filter(({files: f}) => f);
1106
+ if (moreIgnores.length + moreGeneral.length + moreFiles.length !== args.length) {
1107
+ throw new RangeError('传入的配置项只能是忽略项、通用规则项或文件规则项三种之一!');
1108
+ }
1109
+ return [
1110
+ ignores,
1111
+ ...moreIgnores,
1112
+ ...general,
1113
+ ...moreGeneral,
1114
+ ...json,
1115
+ ...ts,
1116
+ ...moreFiles,
1117
+ ];
1118
+ };
1119
+
1120
+ export default extend(jsDoc);
package/eslintrc.cjs CHANGED
@@ -689,6 +689,7 @@ module.exports = {
689
689
  parser: 'eslint-plugin-json-es',
690
690
  extends: ['plugin:eslint-plugin-json-es/recommended'],
691
691
  rules: {
692
+ strict: 0,
692
693
  '@stylistic/array-bracket-newline': [
693
694
  2,
694
695
  {
@@ -721,7 +722,6 @@ module.exports = {
721
722
  ],
722
723
  '@stylistic/quote-props': 0,
723
724
  '@stylistic/quotes': 0,
724
- strict: 0,
725
725
  'unicorn/prefer-string-raw': 0,
726
726
  'unicorn/numeric-separators-style': 0,
727
727
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bhsd/code-standard",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "homepage": "https://github.com/bhsd-harry/code-standard#readme",
5
5
  "bugs": {
6
6
  "url": "https://github.com/bhsd-harry/code-standard/issues"
@@ -8,24 +8,32 @@
8
8
  "license": "MIT",
9
9
  "author": "Bhsd",
10
10
  "files": [
11
- "*.cjs",
12
- "!.eslintrc.cjs"
11
+ "*.[cm]js",
12
+ "!eslint.config.mjs"
13
13
  ],
14
+ "main": "eslint.mjs",
14
15
  "scripts": {
15
16
  "lint:ts": "eslint --cache .",
16
17
  "lint": "npm run lint:ts"
17
18
  },
18
- "devDependencies": {
19
- "@stylistic/eslint-plugin": "^3.1.0",
20
- "@types/node": "^24.0.10",
21
- "eslint": "^8.57.1",
19
+ "dependencies": {
20
+ "@eslint/js": "^8.57.1",
21
+ "@stylistic/eslint-plugin": "^5.5.0",
22
+ "@typescript-eslint/eslint-plugin": "^8.46.2",
23
+ "eslint-plugin-es-x": "^9.1.2",
22
24
  "eslint-plugin-eslint-comments": "^3.2.0",
23
- "eslint-plugin-jsdoc": "^54.1.1",
24
- "eslint-plugin-json-es": "^1.6.0",
25
- "eslint-plugin-n": "^17.20.0",
25
+ "eslint-plugin-jsdoc": "^61.1.11",
26
+ "eslint-plugin-jsonc": "^2.21.0",
27
+ "eslint-plugin-n": "^17.23.1",
26
28
  "eslint-plugin-promise": "^7.2.1",
27
- "eslint-plugin-regexp": "^2.9.0",
28
- "eslint-plugin-unicorn": "^56.0.1",
29
- "stylelint-plugin-use-baseline": "^1.0.0"
29
+ "eslint-plugin-regexp": "^2.10.0",
30
+ "eslint-plugin-unicorn": "^62.0.0",
31
+ "globals": "^16.5.0"
32
+ },
33
+ "devDependencies": {
34
+ "@types/node": "^24.9.2",
35
+ "@typescript-eslint/parser": "^8.46.2",
36
+ "eslint": "^9.38.0",
37
+ "stylelint-plugin-use-baseline": "^1.0.3"
30
38
  }
31
39
  }