@so1ve/eslint-plugin 0.45.0 → 0.45.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.
- package/dist/index.cjs +188 -32
- package/dist/index.d.ts +3 -1
- package/dist/index.mjs +188 -32
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -19,9 +19,9 @@ const util__namespace = /*#__PURE__*/_interopNamespaceDefault(util);
|
|
|
19
19
|
|
|
20
20
|
const createEslintRule = utils.ESLintUtils.RuleCreator((ruleName) => ruleName);
|
|
21
21
|
|
|
22
|
-
const RULE_NAME$
|
|
22
|
+
const RULE_NAME$9 = "generic-spacing";
|
|
23
23
|
const genericSpacing = createEslintRule({
|
|
24
|
-
name: RULE_NAME$
|
|
24
|
+
name: RULE_NAME$9,
|
|
25
25
|
meta: {
|
|
26
26
|
type: "layout",
|
|
27
27
|
docs: {
|
|
@@ -85,7 +85,7 @@ const genericSpacing = createEslintRule({
|
|
|
85
85
|
}
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
|
-
if (!hasSpacingBeforeParam && leftToken
|
|
88
|
+
if (!hasSpacingBeforeParam && util__namespace.isCommaToken(leftToken)) {
|
|
89
89
|
context.report({
|
|
90
90
|
node,
|
|
91
91
|
loc: {
|
|
@@ -115,15 +115,35 @@ const genericSpacing = createEslintRule({
|
|
|
115
115
|
if (hasSpacingBeforeNode && node.parent.type !== utils.AST_NODE_TYPES.TSFunctionType) {
|
|
116
116
|
context.report({
|
|
117
117
|
node,
|
|
118
|
+
loc: {
|
|
119
|
+
start: {
|
|
120
|
+
line: leftToken.loc.end.line,
|
|
121
|
+
column: leftToken.loc.end.column
|
|
122
|
+
},
|
|
123
|
+
end: {
|
|
124
|
+
line: node.loc.start.line,
|
|
125
|
+
column: node.loc.start.column
|
|
126
|
+
}
|
|
127
|
+
},
|
|
118
128
|
messageId: "genericSpacingMismatch",
|
|
119
129
|
*fix(fixer) {
|
|
120
130
|
yield fixer.removeRange([leftToken.range[1], node.range[0]]);
|
|
121
131
|
}
|
|
122
132
|
});
|
|
123
133
|
}
|
|
124
|
-
if (hasSpacingAfterParam &&
|
|
134
|
+
if (hasSpacingAfterParam && [utils.AST_NODE_TYPES.TSFunctionType, utils.AST_NODE_TYPES.FunctionDeclaration, utils.AST_NODE_TYPES.FunctionExpression].includes(node.parent.type)) {
|
|
125
135
|
context.report({
|
|
126
136
|
node,
|
|
137
|
+
loc: {
|
|
138
|
+
start: {
|
|
139
|
+
line: endBracket.loc.end.line,
|
|
140
|
+
column: endBracket.loc.end.column
|
|
141
|
+
},
|
|
142
|
+
end: {
|
|
143
|
+
line: rightToken.loc.start.line,
|
|
144
|
+
column: rightToken.loc.start.column
|
|
145
|
+
}
|
|
146
|
+
},
|
|
127
147
|
messageId: "genericSpacingMismatch",
|
|
128
148
|
*fix(fixer) {
|
|
129
149
|
yield fixer.removeRange([endBracket.range[1], rightToken.range[0]]);
|
|
@@ -192,18 +212,38 @@ const genericSpacing = createEslintRule({
|
|
|
192
212
|
const rightToken = sourceCode.getTokenAfter(param);
|
|
193
213
|
const hasSpacingBeforeParam = leftToken.value === "<" ? sourceCode.isSpaceBetween(leftToken, param) : false;
|
|
194
214
|
const hasSpacingAfterParam = rightToken.value === ">" ? sourceCode.isSpaceBetween(param, rightToken) : false;
|
|
195
|
-
if (hasSpacingBeforeParam) {
|
|
215
|
+
if (hasSpacingBeforeParam && leftToken.loc.end.line === param.loc.start.line) {
|
|
196
216
|
context.report({
|
|
197
217
|
node,
|
|
218
|
+
loc: {
|
|
219
|
+
start: {
|
|
220
|
+
line: leftToken.loc.end.line,
|
|
221
|
+
column: leftToken.loc.end.column
|
|
222
|
+
},
|
|
223
|
+
end: {
|
|
224
|
+
line: param.loc.start.line,
|
|
225
|
+
column: param.loc.start.column
|
|
226
|
+
}
|
|
227
|
+
},
|
|
198
228
|
messageId: "genericSpacingMismatch",
|
|
199
229
|
*fix(fixer) {
|
|
200
230
|
yield fixer.removeRange([leftToken.range[1], param.range[0]]);
|
|
201
231
|
}
|
|
202
232
|
});
|
|
203
233
|
}
|
|
204
|
-
if (hasSpacingAfterParam) {
|
|
234
|
+
if (hasSpacingAfterParam && param.loc.end.line === rightToken.loc.start.line) {
|
|
205
235
|
context.report({
|
|
206
236
|
node,
|
|
237
|
+
loc: {
|
|
238
|
+
start: {
|
|
239
|
+
line: param.loc.end.line,
|
|
240
|
+
column: param.loc.end.column
|
|
241
|
+
},
|
|
242
|
+
end: {
|
|
243
|
+
line: rightToken.loc.start.line,
|
|
244
|
+
column: rightToken.loc.start.column
|
|
245
|
+
}
|
|
246
|
+
},
|
|
207
247
|
messageId: "genericSpacingMismatch",
|
|
208
248
|
*fix(fixer) {
|
|
209
249
|
yield fixer.removeRange([param.range[1], rightToken.range[0]]);
|
|
@@ -248,9 +288,9 @@ const genericSpacing = createEslintRule({
|
|
|
248
288
|
}
|
|
249
289
|
});
|
|
250
290
|
|
|
251
|
-
const RULE_NAME$
|
|
291
|
+
const RULE_NAME$8 = "import-dedupe";
|
|
252
292
|
const importDedupe = createEslintRule({
|
|
253
|
-
name: RULE_NAME$
|
|
293
|
+
name: RULE_NAME$8,
|
|
254
294
|
meta: {
|
|
255
295
|
type: "problem",
|
|
256
296
|
docs: {
|
|
@@ -299,9 +339,9 @@ const importDedupe = createEslintRule({
|
|
|
299
339
|
});
|
|
300
340
|
|
|
301
341
|
const operatorOrAnyBracketOrKeywordRE = /^(\||&|\*|\+|\-|\/|%|<|>|<=|>=|==|!=|===|!==|\[|\(|\{|as|extends|implements|keyof|new|readonly|typeof|unique|unknown)/;
|
|
302
|
-
const RULE_NAME$
|
|
342
|
+
const RULE_NAME$7 = "space-between-generic-and-paren";
|
|
303
343
|
const spaceBetweenGenericAndParen = createEslintRule({
|
|
304
|
-
name: RULE_NAME$
|
|
344
|
+
name: RULE_NAME$7,
|
|
305
345
|
meta: {
|
|
306
346
|
type: "layout",
|
|
307
347
|
docs: {
|
|
@@ -375,19 +415,19 @@ const spaceBetweenGenericAndParen = createEslintRule({
|
|
|
375
415
|
}
|
|
376
416
|
});
|
|
377
417
|
|
|
378
|
-
const RULE_NAME$
|
|
379
|
-
const
|
|
380
|
-
name: RULE_NAME$
|
|
418
|
+
const RULE_NAME$6 = "no-space-before-paren";
|
|
419
|
+
const noSpaceBeforeParen = createEslintRule({
|
|
420
|
+
name: RULE_NAME$6,
|
|
381
421
|
meta: {
|
|
382
422
|
type: "layout",
|
|
383
423
|
docs: {
|
|
384
|
-
description: "
|
|
424
|
+
description: "Space before paren",
|
|
385
425
|
recommended: "error"
|
|
386
426
|
},
|
|
387
427
|
fixable: "whitespace",
|
|
388
428
|
schema: [],
|
|
389
429
|
messages: {
|
|
390
|
-
|
|
430
|
+
noSpaceBeforeParen: "Expected no space before paren"
|
|
391
431
|
}
|
|
392
432
|
},
|
|
393
433
|
defaultOptions: [],
|
|
@@ -404,7 +444,7 @@ const noSpacesBeforeParen = createEslintRule({
|
|
|
404
444
|
if (textBetweenImportAndParen.length > 0) {
|
|
405
445
|
context.report({
|
|
406
446
|
node,
|
|
407
|
-
messageId: "
|
|
447
|
+
messageId: "noSpaceBeforeParen",
|
|
408
448
|
*fix(fixer) {
|
|
409
449
|
yield fixer.removeRange(textBetweenImportAndParenRange);
|
|
410
450
|
}
|
|
@@ -433,7 +473,7 @@ const noSpacesBeforeParen = createEslintRule({
|
|
|
433
473
|
if (textBetweenFunctionNameAndParen.value.length > 0 && textBetweenFunctionNameAndParen.value !== "?.") {
|
|
434
474
|
context.report({
|
|
435
475
|
node,
|
|
436
|
-
messageId: "
|
|
476
|
+
messageId: "noSpaceBeforeParen",
|
|
437
477
|
*fix(fixer) {
|
|
438
478
|
yield fixer.replaceTextRange(textBetweenFunctionNameAndParenRange.value, node.optional ? "?." : "");
|
|
439
479
|
}
|
|
@@ -446,7 +486,7 @@ const noSpacesBeforeParen = createEslintRule({
|
|
|
446
486
|
if (preSpaces.length > 0) {
|
|
447
487
|
context.report({
|
|
448
488
|
node,
|
|
449
|
-
messageId: "
|
|
489
|
+
messageId: "noSpaceBeforeParen",
|
|
450
490
|
*fix(fixer) {
|
|
451
491
|
yield fixer.removeRange([callerEnd.value, callerEnd.value + preSpaces.length]);
|
|
452
492
|
}
|
|
@@ -455,7 +495,7 @@ const noSpacesBeforeParen = createEslintRule({
|
|
|
455
495
|
if (postSpaces.length > 0) {
|
|
456
496
|
context.report({
|
|
457
497
|
node,
|
|
458
|
-
messageId: "
|
|
498
|
+
messageId: "noSpaceBeforeParen",
|
|
459
499
|
*fix(fixer) {
|
|
460
500
|
yield fixer.removeRange([parenStart.value - postSpaces.length, parenStart.value]);
|
|
461
501
|
}
|
|
@@ -464,7 +504,7 @@ const noSpacesBeforeParen = createEslintRule({
|
|
|
464
504
|
if (spacesBeforeOptionalMark.length > 0 && !textBetweenFunctionNameAndParen.value.endsWith(" ")) {
|
|
465
505
|
context.report({
|
|
466
506
|
node,
|
|
467
|
-
messageId: "
|
|
507
|
+
messageId: "noSpaceBeforeParen",
|
|
468
508
|
*fix(fixer) {
|
|
469
509
|
yield fixer.removeRange([parenStart.value - spacesBeforeOptionalMark.length - 2, parenStart.value - 2]);
|
|
470
510
|
}
|
|
@@ -476,9 +516,9 @@ const noSpacesBeforeParen = createEslintRule({
|
|
|
476
516
|
}
|
|
477
517
|
});
|
|
478
518
|
|
|
479
|
-
const RULE_NAME$
|
|
519
|
+
const RULE_NAME$5 = "space-in-empty-block";
|
|
480
520
|
const spaceInEmptyBlock = createEslintRule({
|
|
481
|
-
name: RULE_NAME$
|
|
521
|
+
name: RULE_NAME$5,
|
|
482
522
|
meta: {
|
|
483
523
|
type: "layout",
|
|
484
524
|
docs: {
|
|
@@ -543,9 +583,9 @@ const spaceInEmptyBlock = createEslintRule({
|
|
|
543
583
|
}
|
|
544
584
|
});
|
|
545
585
|
|
|
546
|
-
const RULE_NAME$
|
|
586
|
+
const RULE_NAME$4 = "space-before-function-paren";
|
|
547
587
|
const spaceBeforeFunctionParen = createEslintRule({
|
|
548
|
-
name: RULE_NAME$
|
|
588
|
+
name: RULE_NAME$4,
|
|
549
589
|
meta: {
|
|
550
590
|
type: "layout",
|
|
551
591
|
docs: {
|
|
@@ -650,13 +690,13 @@ const spaceBeforeFunctionParen = createEslintRule({
|
|
|
650
690
|
}
|
|
651
691
|
});
|
|
652
692
|
|
|
653
|
-
const RULE_NAME$
|
|
693
|
+
const RULE_NAME$3 = "semi-spacing";
|
|
654
694
|
const semiSpacing = createEslintRule({
|
|
655
|
-
name: RULE_NAME$
|
|
695
|
+
name: RULE_NAME$3,
|
|
656
696
|
meta: {
|
|
657
697
|
type: "layout",
|
|
658
698
|
docs: {
|
|
659
|
-
description: "Semicolon spacing",
|
|
699
|
+
description: "Semicolon spacing in types",
|
|
660
700
|
recommended: "error"
|
|
661
701
|
},
|
|
662
702
|
fixable: "whitespace",
|
|
@@ -672,7 +712,7 @@ const semiSpacing = createEslintRule({
|
|
|
672
712
|
TSTypeAliasDeclaration(node) {
|
|
673
713
|
const leftToken = node.typeAnnotation;
|
|
674
714
|
const rightToken = sourceCode.getTokenAfter(node.typeAnnotation);
|
|
675
|
-
if (rightToken.type !== utils.AST_TOKEN_TYPES.Punctuator) {
|
|
715
|
+
if (rightToken.type !== utils.AST_TOKEN_TYPES.Punctuator || rightToken.value !== ";") {
|
|
676
716
|
return;
|
|
677
717
|
}
|
|
678
718
|
const hasSpacing = sourceCode.isSpaceBetween(leftToken, rightToken);
|
|
@@ -700,9 +740,9 @@ const semiSpacing = createEslintRule({
|
|
|
700
740
|
}
|
|
701
741
|
});
|
|
702
742
|
|
|
703
|
-
const RULE_NAME = "no-inline-type-import";
|
|
743
|
+
const RULE_NAME$2 = "no-inline-type-import";
|
|
704
744
|
const noInlineTypeImport = createEslintRule({
|
|
705
|
-
name: RULE_NAME,
|
|
745
|
+
name: RULE_NAME$2,
|
|
706
746
|
meta: {
|
|
707
747
|
type: "layout",
|
|
708
748
|
docs: {
|
|
@@ -749,6 +789,120 @@ import { ${valueSpecifiersText} } from "${node.source.value}";`);
|
|
|
749
789
|
}
|
|
750
790
|
});
|
|
751
791
|
|
|
792
|
+
const RULE_NAME$1 = "no-beginning-newline";
|
|
793
|
+
const noBeginningNewline = createEslintRule({
|
|
794
|
+
name: RULE_NAME$1,
|
|
795
|
+
meta: {
|
|
796
|
+
type: "layout",
|
|
797
|
+
docs: {
|
|
798
|
+
description: "No beginning newline",
|
|
799
|
+
recommended: "error"
|
|
800
|
+
},
|
|
801
|
+
fixable: "whitespace",
|
|
802
|
+
schema: [],
|
|
803
|
+
messages: {
|
|
804
|
+
noBeginningNewline: "No beginning newline"
|
|
805
|
+
}
|
|
806
|
+
},
|
|
807
|
+
defaultOptions: [],
|
|
808
|
+
create: (context) => {
|
|
809
|
+
const text = context.getSourceCode().text;
|
|
810
|
+
return {
|
|
811
|
+
Program: (node) => {
|
|
812
|
+
const newlines = text.match(/([\n]*)/)[1];
|
|
813
|
+
if (newlines.length > 0) {
|
|
814
|
+
context.report({
|
|
815
|
+
node,
|
|
816
|
+
loc: {
|
|
817
|
+
start: {
|
|
818
|
+
line: 0,
|
|
819
|
+
column: 0
|
|
820
|
+
},
|
|
821
|
+
end: node.loc.start
|
|
822
|
+
},
|
|
823
|
+
messageId: "noBeginningNewline",
|
|
824
|
+
*fix(fixer) {
|
|
825
|
+
yield fixer.removeRange([0, node.range[0]]);
|
|
826
|
+
}
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
});
|
|
833
|
+
|
|
834
|
+
const RULE_NAME = "array-bracket-spacing";
|
|
835
|
+
const arrayBracketSpacing = createEslintRule({
|
|
836
|
+
name: RULE_NAME,
|
|
837
|
+
meta: {
|
|
838
|
+
type: "layout",
|
|
839
|
+
docs: {
|
|
840
|
+
description: "Array bracket spacing",
|
|
841
|
+
recommended: "error"
|
|
842
|
+
},
|
|
843
|
+
fixable: "whitespace",
|
|
844
|
+
schema: [],
|
|
845
|
+
messages: {
|
|
846
|
+
arrayBracketSpacing: "Array bracket spacing mismatch"
|
|
847
|
+
}
|
|
848
|
+
},
|
|
849
|
+
defaultOptions: [],
|
|
850
|
+
create: (context) => {
|
|
851
|
+
const sourceCode = context.getSourceCode();
|
|
852
|
+
const text = sourceCode.getText();
|
|
853
|
+
const checkNode = (node) => {
|
|
854
|
+
const elements = node.type === utils.AST_NODE_TYPES.TSTupleType ? node.elementTypes : node.elements;
|
|
855
|
+
const firstElement = elements[0];
|
|
856
|
+
const lastElement = elements[elements.length - 1];
|
|
857
|
+
if (!firstElement) {
|
|
858
|
+
return;
|
|
859
|
+
}
|
|
860
|
+
const leftToken = sourceCode.getTokenBefore(firstElement);
|
|
861
|
+
const rightToken = reactivity.ref(sourceCode.getTokenAfter(lastElement));
|
|
862
|
+
if (rightToken.value.value === ",") {
|
|
863
|
+
rightToken.value = sourceCode.getTokenAfter(rightToken.value);
|
|
864
|
+
}
|
|
865
|
+
const textBetweenFirstAndToken = reactivity.computed(() => text.slice(leftToken.range[1], firstElement.range[0]));
|
|
866
|
+
const isNewline = reactivity.computed(() => textBetweenFirstAndToken.value.includes("\n"));
|
|
867
|
+
const textBetweenLastAndToken = reactivity.computed(() => text.slice(lastElement.range[1], rightToken.value.range[0]));
|
|
868
|
+
const hasNewlineAfter = reactivity.computed(() => textBetweenLastAndToken.value.includes("\n"));
|
|
869
|
+
if (sourceCode.isSpaceBetween(leftToken, firstElement) && !isNewline.value) {
|
|
870
|
+
context.report({
|
|
871
|
+
node,
|
|
872
|
+
messageId: "arrayBracketSpacing",
|
|
873
|
+
*fix(fixer) {
|
|
874
|
+
yield fixer.removeRange([leftToken.range[1], firstElement.range[0]]);
|
|
875
|
+
}
|
|
876
|
+
});
|
|
877
|
+
}
|
|
878
|
+
if (sourceCode.isSpaceBetween(lastElement, rightToken.value)) {
|
|
879
|
+
if (!isNewline.value) {
|
|
880
|
+
context.report({
|
|
881
|
+
node,
|
|
882
|
+
messageId: "arrayBracketSpacing",
|
|
883
|
+
*fix(fixer) {
|
|
884
|
+
yield fixer.removeRange([lastElement.range[1], rightToken.value.range[0]]);
|
|
885
|
+
}
|
|
886
|
+
});
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
if (isNewline.value && !hasNewlineAfter.value) {
|
|
890
|
+
context.report({
|
|
891
|
+
node,
|
|
892
|
+
messageId: "arrayBracketSpacing",
|
|
893
|
+
*fix(fixer) {
|
|
894
|
+
yield fixer.replaceTextRange([lastElement.range[1], rightToken.value.range[0]], "\n");
|
|
895
|
+
}
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
};
|
|
899
|
+
return {
|
|
900
|
+
TSTupleType: checkNode,
|
|
901
|
+
ArrayExpression: checkNode
|
|
902
|
+
};
|
|
903
|
+
}
|
|
904
|
+
});
|
|
905
|
+
|
|
752
906
|
const index = {
|
|
753
907
|
rules: {
|
|
754
908
|
"import-dedupe": importDedupe,
|
|
@@ -757,8 +911,10 @@ const index = {
|
|
|
757
911
|
"space-in-empty-block": spaceInEmptyBlock,
|
|
758
912
|
"semi-spacing": semiSpacing,
|
|
759
913
|
"no-inline-type-import": noInlineTypeImport,
|
|
760
|
-
"no-
|
|
761
|
-
"space-before-function-paren": spaceBeforeFunctionParen
|
|
914
|
+
"no-space-before-paren": noSpaceBeforeParen,
|
|
915
|
+
"space-before-function-paren": spaceBeforeFunctionParen,
|
|
916
|
+
"no-beginning-newline": noBeginningNewline,
|
|
917
|
+
"array-bracket-spacing": arrayBracketSpacing
|
|
762
918
|
}
|
|
763
919
|
};
|
|
764
920
|
|
package/dist/index.d.ts
CHANGED
|
@@ -19,8 +19,10 @@ declare const _default: {
|
|
|
19
19
|
"space-in-empty-block": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"noSpaceInEmptyBlock", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
|
|
20
20
|
"semi-spacing": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"noSpaceBeforeSemi", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
|
|
21
21
|
"no-inline-type-import": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"noInlineTypeImport", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
|
|
22
|
-
"no-
|
|
22
|
+
"no-space-before-paren": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"noSpaceBeforeParen", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
|
|
23
23
|
"space-before-function-paren": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<MessageIds, Options, _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
|
|
24
|
+
"no-beginning-newline": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"noBeginningNewline", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
|
|
25
|
+
"array-bracket-spacing": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"arrayBracketSpacing", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
|
|
24
26
|
};
|
|
25
27
|
};
|
|
26
28
|
|
package/dist/index.mjs
CHANGED
|
@@ -4,9 +4,9 @@ import { ref, computed } from '@vue/reactivity';
|
|
|
4
4
|
|
|
5
5
|
const createEslintRule = ESLintUtils.RuleCreator((ruleName) => ruleName);
|
|
6
6
|
|
|
7
|
-
const RULE_NAME$
|
|
7
|
+
const RULE_NAME$9 = "generic-spacing";
|
|
8
8
|
const genericSpacing = createEslintRule({
|
|
9
|
-
name: RULE_NAME$
|
|
9
|
+
name: RULE_NAME$9,
|
|
10
10
|
meta: {
|
|
11
11
|
type: "layout",
|
|
12
12
|
docs: {
|
|
@@ -70,7 +70,7 @@ const genericSpacing = createEslintRule({
|
|
|
70
70
|
}
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
|
-
if (!hasSpacingBeforeParam && leftToken
|
|
73
|
+
if (!hasSpacingBeforeParam && util.isCommaToken(leftToken)) {
|
|
74
74
|
context.report({
|
|
75
75
|
node,
|
|
76
76
|
loc: {
|
|
@@ -100,15 +100,35 @@ const genericSpacing = createEslintRule({
|
|
|
100
100
|
if (hasSpacingBeforeNode && node.parent.type !== AST_NODE_TYPES.TSFunctionType) {
|
|
101
101
|
context.report({
|
|
102
102
|
node,
|
|
103
|
+
loc: {
|
|
104
|
+
start: {
|
|
105
|
+
line: leftToken.loc.end.line,
|
|
106
|
+
column: leftToken.loc.end.column
|
|
107
|
+
},
|
|
108
|
+
end: {
|
|
109
|
+
line: node.loc.start.line,
|
|
110
|
+
column: node.loc.start.column
|
|
111
|
+
}
|
|
112
|
+
},
|
|
103
113
|
messageId: "genericSpacingMismatch",
|
|
104
114
|
*fix(fixer) {
|
|
105
115
|
yield fixer.removeRange([leftToken.range[1], node.range[0]]);
|
|
106
116
|
}
|
|
107
117
|
});
|
|
108
118
|
}
|
|
109
|
-
if (hasSpacingAfterParam && node.parent.type
|
|
119
|
+
if (hasSpacingAfterParam && [AST_NODE_TYPES.TSFunctionType, AST_NODE_TYPES.FunctionDeclaration, AST_NODE_TYPES.FunctionExpression].includes(node.parent.type)) {
|
|
110
120
|
context.report({
|
|
111
121
|
node,
|
|
122
|
+
loc: {
|
|
123
|
+
start: {
|
|
124
|
+
line: endBracket.loc.end.line,
|
|
125
|
+
column: endBracket.loc.end.column
|
|
126
|
+
},
|
|
127
|
+
end: {
|
|
128
|
+
line: rightToken.loc.start.line,
|
|
129
|
+
column: rightToken.loc.start.column
|
|
130
|
+
}
|
|
131
|
+
},
|
|
112
132
|
messageId: "genericSpacingMismatch",
|
|
113
133
|
*fix(fixer) {
|
|
114
134
|
yield fixer.removeRange([endBracket.range[1], rightToken.range[0]]);
|
|
@@ -177,18 +197,38 @@ const genericSpacing = createEslintRule({
|
|
|
177
197
|
const rightToken = sourceCode.getTokenAfter(param);
|
|
178
198
|
const hasSpacingBeforeParam = leftToken.value === "<" ? sourceCode.isSpaceBetween(leftToken, param) : false;
|
|
179
199
|
const hasSpacingAfterParam = rightToken.value === ">" ? sourceCode.isSpaceBetween(param, rightToken) : false;
|
|
180
|
-
if (hasSpacingBeforeParam) {
|
|
200
|
+
if (hasSpacingBeforeParam && leftToken.loc.end.line === param.loc.start.line) {
|
|
181
201
|
context.report({
|
|
182
202
|
node,
|
|
203
|
+
loc: {
|
|
204
|
+
start: {
|
|
205
|
+
line: leftToken.loc.end.line,
|
|
206
|
+
column: leftToken.loc.end.column
|
|
207
|
+
},
|
|
208
|
+
end: {
|
|
209
|
+
line: param.loc.start.line,
|
|
210
|
+
column: param.loc.start.column
|
|
211
|
+
}
|
|
212
|
+
},
|
|
183
213
|
messageId: "genericSpacingMismatch",
|
|
184
214
|
*fix(fixer) {
|
|
185
215
|
yield fixer.removeRange([leftToken.range[1], param.range[0]]);
|
|
186
216
|
}
|
|
187
217
|
});
|
|
188
218
|
}
|
|
189
|
-
if (hasSpacingAfterParam) {
|
|
219
|
+
if (hasSpacingAfterParam && param.loc.end.line === rightToken.loc.start.line) {
|
|
190
220
|
context.report({
|
|
191
221
|
node,
|
|
222
|
+
loc: {
|
|
223
|
+
start: {
|
|
224
|
+
line: param.loc.end.line,
|
|
225
|
+
column: param.loc.end.column
|
|
226
|
+
},
|
|
227
|
+
end: {
|
|
228
|
+
line: rightToken.loc.start.line,
|
|
229
|
+
column: rightToken.loc.start.column
|
|
230
|
+
}
|
|
231
|
+
},
|
|
192
232
|
messageId: "genericSpacingMismatch",
|
|
193
233
|
*fix(fixer) {
|
|
194
234
|
yield fixer.removeRange([param.range[1], rightToken.range[0]]);
|
|
@@ -233,9 +273,9 @@ const genericSpacing = createEslintRule({
|
|
|
233
273
|
}
|
|
234
274
|
});
|
|
235
275
|
|
|
236
|
-
const RULE_NAME$
|
|
276
|
+
const RULE_NAME$8 = "import-dedupe";
|
|
237
277
|
const importDedupe = createEslintRule({
|
|
238
|
-
name: RULE_NAME$
|
|
278
|
+
name: RULE_NAME$8,
|
|
239
279
|
meta: {
|
|
240
280
|
type: "problem",
|
|
241
281
|
docs: {
|
|
@@ -284,9 +324,9 @@ const importDedupe = createEslintRule({
|
|
|
284
324
|
});
|
|
285
325
|
|
|
286
326
|
const operatorOrAnyBracketOrKeywordRE = /^(\||&|\*|\+|\-|\/|%|<|>|<=|>=|==|!=|===|!==|\[|\(|\{|as|extends|implements|keyof|new|readonly|typeof|unique|unknown)/;
|
|
287
|
-
const RULE_NAME$
|
|
327
|
+
const RULE_NAME$7 = "space-between-generic-and-paren";
|
|
288
328
|
const spaceBetweenGenericAndParen = createEslintRule({
|
|
289
|
-
name: RULE_NAME$
|
|
329
|
+
name: RULE_NAME$7,
|
|
290
330
|
meta: {
|
|
291
331
|
type: "layout",
|
|
292
332
|
docs: {
|
|
@@ -360,19 +400,19 @@ const spaceBetweenGenericAndParen = createEslintRule({
|
|
|
360
400
|
}
|
|
361
401
|
});
|
|
362
402
|
|
|
363
|
-
const RULE_NAME$
|
|
364
|
-
const
|
|
365
|
-
name: RULE_NAME$
|
|
403
|
+
const RULE_NAME$6 = "no-space-before-paren";
|
|
404
|
+
const noSpaceBeforeParen = createEslintRule({
|
|
405
|
+
name: RULE_NAME$6,
|
|
366
406
|
meta: {
|
|
367
407
|
type: "layout",
|
|
368
408
|
docs: {
|
|
369
|
-
description: "
|
|
409
|
+
description: "Space before paren",
|
|
370
410
|
recommended: "error"
|
|
371
411
|
},
|
|
372
412
|
fixable: "whitespace",
|
|
373
413
|
schema: [],
|
|
374
414
|
messages: {
|
|
375
|
-
|
|
415
|
+
noSpaceBeforeParen: "Expected no space before paren"
|
|
376
416
|
}
|
|
377
417
|
},
|
|
378
418
|
defaultOptions: [],
|
|
@@ -389,7 +429,7 @@ const noSpacesBeforeParen = createEslintRule({
|
|
|
389
429
|
if (textBetweenImportAndParen.length > 0) {
|
|
390
430
|
context.report({
|
|
391
431
|
node,
|
|
392
|
-
messageId: "
|
|
432
|
+
messageId: "noSpaceBeforeParen",
|
|
393
433
|
*fix(fixer) {
|
|
394
434
|
yield fixer.removeRange(textBetweenImportAndParenRange);
|
|
395
435
|
}
|
|
@@ -418,7 +458,7 @@ const noSpacesBeforeParen = createEslintRule({
|
|
|
418
458
|
if (textBetweenFunctionNameAndParen.value.length > 0 && textBetweenFunctionNameAndParen.value !== "?.") {
|
|
419
459
|
context.report({
|
|
420
460
|
node,
|
|
421
|
-
messageId: "
|
|
461
|
+
messageId: "noSpaceBeforeParen",
|
|
422
462
|
*fix(fixer) {
|
|
423
463
|
yield fixer.replaceTextRange(textBetweenFunctionNameAndParenRange.value, node.optional ? "?." : "");
|
|
424
464
|
}
|
|
@@ -431,7 +471,7 @@ const noSpacesBeforeParen = createEslintRule({
|
|
|
431
471
|
if (preSpaces.length > 0) {
|
|
432
472
|
context.report({
|
|
433
473
|
node,
|
|
434
|
-
messageId: "
|
|
474
|
+
messageId: "noSpaceBeforeParen",
|
|
435
475
|
*fix(fixer) {
|
|
436
476
|
yield fixer.removeRange([callerEnd.value, callerEnd.value + preSpaces.length]);
|
|
437
477
|
}
|
|
@@ -440,7 +480,7 @@ const noSpacesBeforeParen = createEslintRule({
|
|
|
440
480
|
if (postSpaces.length > 0) {
|
|
441
481
|
context.report({
|
|
442
482
|
node,
|
|
443
|
-
messageId: "
|
|
483
|
+
messageId: "noSpaceBeforeParen",
|
|
444
484
|
*fix(fixer) {
|
|
445
485
|
yield fixer.removeRange([parenStart.value - postSpaces.length, parenStart.value]);
|
|
446
486
|
}
|
|
@@ -449,7 +489,7 @@ const noSpacesBeforeParen = createEslintRule({
|
|
|
449
489
|
if (spacesBeforeOptionalMark.length > 0 && !textBetweenFunctionNameAndParen.value.endsWith(" ")) {
|
|
450
490
|
context.report({
|
|
451
491
|
node,
|
|
452
|
-
messageId: "
|
|
492
|
+
messageId: "noSpaceBeforeParen",
|
|
453
493
|
*fix(fixer) {
|
|
454
494
|
yield fixer.removeRange([parenStart.value - spacesBeforeOptionalMark.length - 2, parenStart.value - 2]);
|
|
455
495
|
}
|
|
@@ -461,9 +501,9 @@ const noSpacesBeforeParen = createEslintRule({
|
|
|
461
501
|
}
|
|
462
502
|
});
|
|
463
503
|
|
|
464
|
-
const RULE_NAME$
|
|
504
|
+
const RULE_NAME$5 = "space-in-empty-block";
|
|
465
505
|
const spaceInEmptyBlock = createEslintRule({
|
|
466
|
-
name: RULE_NAME$
|
|
506
|
+
name: RULE_NAME$5,
|
|
467
507
|
meta: {
|
|
468
508
|
type: "layout",
|
|
469
509
|
docs: {
|
|
@@ -528,9 +568,9 @@ const spaceInEmptyBlock = createEslintRule({
|
|
|
528
568
|
}
|
|
529
569
|
});
|
|
530
570
|
|
|
531
|
-
const RULE_NAME$
|
|
571
|
+
const RULE_NAME$4 = "space-before-function-paren";
|
|
532
572
|
const spaceBeforeFunctionParen = createEslintRule({
|
|
533
|
-
name: RULE_NAME$
|
|
573
|
+
name: RULE_NAME$4,
|
|
534
574
|
meta: {
|
|
535
575
|
type: "layout",
|
|
536
576
|
docs: {
|
|
@@ -635,13 +675,13 @@ const spaceBeforeFunctionParen = createEslintRule({
|
|
|
635
675
|
}
|
|
636
676
|
});
|
|
637
677
|
|
|
638
|
-
const RULE_NAME$
|
|
678
|
+
const RULE_NAME$3 = "semi-spacing";
|
|
639
679
|
const semiSpacing = createEslintRule({
|
|
640
|
-
name: RULE_NAME$
|
|
680
|
+
name: RULE_NAME$3,
|
|
641
681
|
meta: {
|
|
642
682
|
type: "layout",
|
|
643
683
|
docs: {
|
|
644
|
-
description: "Semicolon spacing",
|
|
684
|
+
description: "Semicolon spacing in types",
|
|
645
685
|
recommended: "error"
|
|
646
686
|
},
|
|
647
687
|
fixable: "whitespace",
|
|
@@ -657,7 +697,7 @@ const semiSpacing = createEslintRule({
|
|
|
657
697
|
TSTypeAliasDeclaration(node) {
|
|
658
698
|
const leftToken = node.typeAnnotation;
|
|
659
699
|
const rightToken = sourceCode.getTokenAfter(node.typeAnnotation);
|
|
660
|
-
if (rightToken.type !== AST_TOKEN_TYPES.Punctuator) {
|
|
700
|
+
if (rightToken.type !== AST_TOKEN_TYPES.Punctuator || rightToken.value !== ";") {
|
|
661
701
|
return;
|
|
662
702
|
}
|
|
663
703
|
const hasSpacing = sourceCode.isSpaceBetween(leftToken, rightToken);
|
|
@@ -685,9 +725,9 @@ const semiSpacing = createEslintRule({
|
|
|
685
725
|
}
|
|
686
726
|
});
|
|
687
727
|
|
|
688
|
-
const RULE_NAME = "no-inline-type-import";
|
|
728
|
+
const RULE_NAME$2 = "no-inline-type-import";
|
|
689
729
|
const noInlineTypeImport = createEslintRule({
|
|
690
|
-
name: RULE_NAME,
|
|
730
|
+
name: RULE_NAME$2,
|
|
691
731
|
meta: {
|
|
692
732
|
type: "layout",
|
|
693
733
|
docs: {
|
|
@@ -734,6 +774,120 @@ import { ${valueSpecifiersText} } from "${node.source.value}";`);
|
|
|
734
774
|
}
|
|
735
775
|
});
|
|
736
776
|
|
|
777
|
+
const RULE_NAME$1 = "no-beginning-newline";
|
|
778
|
+
const noBeginningNewline = createEslintRule({
|
|
779
|
+
name: RULE_NAME$1,
|
|
780
|
+
meta: {
|
|
781
|
+
type: "layout",
|
|
782
|
+
docs: {
|
|
783
|
+
description: "No beginning newline",
|
|
784
|
+
recommended: "error"
|
|
785
|
+
},
|
|
786
|
+
fixable: "whitespace",
|
|
787
|
+
schema: [],
|
|
788
|
+
messages: {
|
|
789
|
+
noBeginningNewline: "No beginning newline"
|
|
790
|
+
}
|
|
791
|
+
},
|
|
792
|
+
defaultOptions: [],
|
|
793
|
+
create: (context) => {
|
|
794
|
+
const text = context.getSourceCode().text;
|
|
795
|
+
return {
|
|
796
|
+
Program: (node) => {
|
|
797
|
+
const newlines = text.match(/([\n]*)/)[1];
|
|
798
|
+
if (newlines.length > 0) {
|
|
799
|
+
context.report({
|
|
800
|
+
node,
|
|
801
|
+
loc: {
|
|
802
|
+
start: {
|
|
803
|
+
line: 0,
|
|
804
|
+
column: 0
|
|
805
|
+
},
|
|
806
|
+
end: node.loc.start
|
|
807
|
+
},
|
|
808
|
+
messageId: "noBeginningNewline",
|
|
809
|
+
*fix(fixer) {
|
|
810
|
+
yield fixer.removeRange([0, node.range[0]]);
|
|
811
|
+
}
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
};
|
|
816
|
+
}
|
|
817
|
+
});
|
|
818
|
+
|
|
819
|
+
const RULE_NAME = "array-bracket-spacing";
|
|
820
|
+
const arrayBracketSpacing = createEslintRule({
|
|
821
|
+
name: RULE_NAME,
|
|
822
|
+
meta: {
|
|
823
|
+
type: "layout",
|
|
824
|
+
docs: {
|
|
825
|
+
description: "Array bracket spacing",
|
|
826
|
+
recommended: "error"
|
|
827
|
+
},
|
|
828
|
+
fixable: "whitespace",
|
|
829
|
+
schema: [],
|
|
830
|
+
messages: {
|
|
831
|
+
arrayBracketSpacing: "Array bracket spacing mismatch"
|
|
832
|
+
}
|
|
833
|
+
},
|
|
834
|
+
defaultOptions: [],
|
|
835
|
+
create: (context) => {
|
|
836
|
+
const sourceCode = context.getSourceCode();
|
|
837
|
+
const text = sourceCode.getText();
|
|
838
|
+
const checkNode = (node) => {
|
|
839
|
+
const elements = node.type === AST_NODE_TYPES.TSTupleType ? node.elementTypes : node.elements;
|
|
840
|
+
const firstElement = elements[0];
|
|
841
|
+
const lastElement = elements[elements.length - 1];
|
|
842
|
+
if (!firstElement) {
|
|
843
|
+
return;
|
|
844
|
+
}
|
|
845
|
+
const leftToken = sourceCode.getTokenBefore(firstElement);
|
|
846
|
+
const rightToken = ref(sourceCode.getTokenAfter(lastElement));
|
|
847
|
+
if (rightToken.value.value === ",") {
|
|
848
|
+
rightToken.value = sourceCode.getTokenAfter(rightToken.value);
|
|
849
|
+
}
|
|
850
|
+
const textBetweenFirstAndToken = computed(() => text.slice(leftToken.range[1], firstElement.range[0]));
|
|
851
|
+
const isNewline = computed(() => textBetweenFirstAndToken.value.includes("\n"));
|
|
852
|
+
const textBetweenLastAndToken = computed(() => text.slice(lastElement.range[1], rightToken.value.range[0]));
|
|
853
|
+
const hasNewlineAfter = computed(() => textBetweenLastAndToken.value.includes("\n"));
|
|
854
|
+
if (sourceCode.isSpaceBetween(leftToken, firstElement) && !isNewline.value) {
|
|
855
|
+
context.report({
|
|
856
|
+
node,
|
|
857
|
+
messageId: "arrayBracketSpacing",
|
|
858
|
+
*fix(fixer) {
|
|
859
|
+
yield fixer.removeRange([leftToken.range[1], firstElement.range[0]]);
|
|
860
|
+
}
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
if (sourceCode.isSpaceBetween(lastElement, rightToken.value)) {
|
|
864
|
+
if (!isNewline.value) {
|
|
865
|
+
context.report({
|
|
866
|
+
node,
|
|
867
|
+
messageId: "arrayBracketSpacing",
|
|
868
|
+
*fix(fixer) {
|
|
869
|
+
yield fixer.removeRange([lastElement.range[1], rightToken.value.range[0]]);
|
|
870
|
+
}
|
|
871
|
+
});
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
if (isNewline.value && !hasNewlineAfter.value) {
|
|
875
|
+
context.report({
|
|
876
|
+
node,
|
|
877
|
+
messageId: "arrayBracketSpacing",
|
|
878
|
+
*fix(fixer) {
|
|
879
|
+
yield fixer.replaceTextRange([lastElement.range[1], rightToken.value.range[0]], "\n");
|
|
880
|
+
}
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
};
|
|
884
|
+
return {
|
|
885
|
+
TSTupleType: checkNode,
|
|
886
|
+
ArrayExpression: checkNode
|
|
887
|
+
};
|
|
888
|
+
}
|
|
889
|
+
});
|
|
890
|
+
|
|
737
891
|
const index = {
|
|
738
892
|
rules: {
|
|
739
893
|
"import-dedupe": importDedupe,
|
|
@@ -742,8 +896,10 @@ const index = {
|
|
|
742
896
|
"space-in-empty-block": spaceInEmptyBlock,
|
|
743
897
|
"semi-spacing": semiSpacing,
|
|
744
898
|
"no-inline-type-import": noInlineTypeImport,
|
|
745
|
-
"no-
|
|
746
|
-
"space-before-function-paren": spaceBeforeFunctionParen
|
|
899
|
+
"no-space-before-paren": noSpaceBeforeParen,
|
|
900
|
+
"space-before-function-paren": spaceBeforeFunctionParen,
|
|
901
|
+
"no-beginning-newline": noBeginningNewline,
|
|
902
|
+
"array-bracket-spacing": arrayBracketSpacing
|
|
747
903
|
}
|
|
748
904
|
};
|
|
749
905
|
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@so1ve/eslint-plugin",
|
|
3
|
-
"version": "0.45.
|
|
3
|
+
"version": "0.45.1",
|
|
4
4
|
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
|
5
5
|
"contributors": [
|
|
6
6
|
{
|
|
7
|
-
"name": "Ray <
|
|
7
|
+
"name": "Ray <i@mk1.io> (https://github.com/so1ve/)"
|
|
8
8
|
}
|
|
9
9
|
],
|
|
10
10
|
"keywords": [
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/node": "^18.11.18",
|
|
40
|
+
"@typescript-eslint/types": "^5.50.0",
|
|
40
41
|
"unbuild": "^1.1.1",
|
|
41
42
|
"vitest": "^0.28.3"
|
|
42
43
|
},
|