@so1ve/eslint-plugin 0.45.0 → 0.45.2

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