@so1ve/eslint-plugin 0.32.3 → 0.35.0
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 +286 -18
- package/dist/index.d.ts +3 -0
- package/dist/index.mjs +286 -18
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -4,9 +4,9 @@ const utils = require('@typescript-eslint/utils');
|
|
|
4
4
|
|
|
5
5
|
const createEslintRule = utils.ESLintUtils.RuleCreator((ruleName) => ruleName);
|
|
6
6
|
|
|
7
|
-
const RULE_NAME$
|
|
7
|
+
const RULE_NAME$4 = "generic-spacing";
|
|
8
8
|
const genericSpacing = createEslintRule({
|
|
9
|
-
name: RULE_NAME$
|
|
9
|
+
name: RULE_NAME$4,
|
|
10
10
|
meta: {
|
|
11
11
|
type: "suggestion",
|
|
12
12
|
docs: {
|
|
@@ -24,6 +24,53 @@ const genericSpacing = createEslintRule({
|
|
|
24
24
|
const sourceCode = context.getSourceCode();
|
|
25
25
|
return {
|
|
26
26
|
TSTypeParameterDeclaration: (node) => {
|
|
27
|
+
const params = node.params;
|
|
28
|
+
for (let i = 0; i < params.length; i++) {
|
|
29
|
+
const param = params[i];
|
|
30
|
+
const pre = sourceCode.text.slice(0, param.range[0]);
|
|
31
|
+
const preSpace = pre.match(/(\s+)$/)?.[0];
|
|
32
|
+
const preComma = pre.match(/(,)\s+$/)?.[0];
|
|
33
|
+
const post = sourceCode.text.slice(param.range[1]);
|
|
34
|
+
const postSpace = post.match(/^(\s*)/)?.[0];
|
|
35
|
+
if (preSpace && preSpace.length && !preComma) {
|
|
36
|
+
context.report({
|
|
37
|
+
node,
|
|
38
|
+
loc: {
|
|
39
|
+
start: {
|
|
40
|
+
line: param.loc.end.line,
|
|
41
|
+
column: param.loc.end.column - 1 - preSpace.length
|
|
42
|
+
},
|
|
43
|
+
end: {
|
|
44
|
+
line: param.loc.end.line,
|
|
45
|
+
column: param.loc.end.column - 1
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
messageId: "genericSpacingMismatch",
|
|
49
|
+
*fix(fixer) {
|
|
50
|
+
yield fixer.replaceTextRange([param.range[0] - preSpace.length, param.range[0]], "");
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
if (postSpace && postSpace.length) {
|
|
55
|
+
context.report({
|
|
56
|
+
loc: {
|
|
57
|
+
start: {
|
|
58
|
+
line: param.loc.end.line,
|
|
59
|
+
column: param.loc.end.column
|
|
60
|
+
},
|
|
61
|
+
end: {
|
|
62
|
+
line: param.loc.end.line,
|
|
63
|
+
column: param.loc.end.column + postSpace.length
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
node,
|
|
67
|
+
messageId: "genericSpacingMismatch",
|
|
68
|
+
*fix(fixer) {
|
|
69
|
+
yield fixer.replaceTextRange([param.range[1], param.range[1] + postSpace.length], "");
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
27
74
|
if (!["TSCallSignatureDeclaration", "ArrowFunctionExpression"].includes(node.parent.type)) {
|
|
28
75
|
const pre = sourceCode.text.slice(0, node.range[0]);
|
|
29
76
|
const preSpace = pre.match(/(\s+)$/)?.[0];
|
|
@@ -48,7 +95,6 @@ const genericSpacing = createEslintRule({
|
|
|
48
95
|
});
|
|
49
96
|
}
|
|
50
97
|
}
|
|
51
|
-
const params = node.params;
|
|
52
98
|
for (let i = 1; i < params.length; i++) {
|
|
53
99
|
const prev = params[i - 1];
|
|
54
100
|
const current = params[i];
|
|
@@ -77,27 +123,56 @@ const genericSpacing = createEslintRule({
|
|
|
77
123
|
const endNode = node.constraint || node.name;
|
|
78
124
|
const from = endNode.range[1];
|
|
79
125
|
const to = node.default.range[0];
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
126
|
+
const spaceAndEqual = sourceCode.text.slice(from, to);
|
|
127
|
+
if (spaceAndEqual !== " = ") {
|
|
128
|
+
const preSpace = spaceAndEqual.match(/^(\s*)/)?.[0];
|
|
129
|
+
const postSpace = spaceAndEqual.match(/(\s*)$/)?.[0];
|
|
130
|
+
if (preSpace.length !== 1) {
|
|
131
|
+
context.report({
|
|
132
|
+
*fix(fixer) {
|
|
133
|
+
yield fixer.replaceTextRange([from, from + preSpace.length], " ");
|
|
134
|
+
},
|
|
135
|
+
loc: {
|
|
136
|
+
start: {
|
|
137
|
+
line: node.loc.start.line,
|
|
138
|
+
column: node.loc.start.column + 1
|
|
139
|
+
},
|
|
140
|
+
end: {
|
|
141
|
+
line: node.loc.end.line,
|
|
142
|
+
column: node.loc.end.column - 2 - postSpace.length
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
node,
|
|
146
|
+
messageId: "genericSpacingMismatch"
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
if (postSpace.length !== 1) {
|
|
150
|
+
context.report({
|
|
151
|
+
*fix(fixer) {
|
|
152
|
+
yield fixer.replaceTextRange([to - postSpace.length, to], " ");
|
|
153
|
+
},
|
|
154
|
+
loc: {
|
|
155
|
+
start: {
|
|
156
|
+
line: node.loc.start.line,
|
|
157
|
+
column: node.loc.start.column + 2 + preSpace.length
|
|
158
|
+
},
|
|
159
|
+
end: {
|
|
160
|
+
line: node.loc.end.line,
|
|
161
|
+
column: node.loc.end.column - 1
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
messageId: "genericSpacingMismatch"
|
|
165
|
+
});
|
|
166
|
+
}
|
|
92
167
|
}
|
|
93
168
|
}
|
|
94
169
|
};
|
|
95
170
|
}
|
|
96
171
|
});
|
|
97
172
|
|
|
98
|
-
const RULE_NAME = "import-dedupe";
|
|
173
|
+
const RULE_NAME$3 = "import-dedupe";
|
|
99
174
|
const importDedupe = createEslintRule({
|
|
100
|
-
name: RULE_NAME,
|
|
175
|
+
name: RULE_NAME$3,
|
|
101
176
|
meta: {
|
|
102
177
|
type: "problem",
|
|
103
178
|
docs: {
|
|
@@ -145,10 +220,203 @@ const importDedupe = createEslintRule({
|
|
|
145
220
|
}
|
|
146
221
|
});
|
|
147
222
|
|
|
223
|
+
const RULE_NAME$2 = "space-between-generic-and-paren";
|
|
224
|
+
const spaceBetweenGenericAndParen = createEslintRule({
|
|
225
|
+
name: RULE_NAME$2,
|
|
226
|
+
meta: {
|
|
227
|
+
type: "suggestion",
|
|
228
|
+
docs: {
|
|
229
|
+
description: "Spaces between generic type parameters and paren",
|
|
230
|
+
recommended: "error"
|
|
231
|
+
},
|
|
232
|
+
fixable: "code",
|
|
233
|
+
schema: [],
|
|
234
|
+
messages: {
|
|
235
|
+
spaceBetweenGenericAndParenMismatch: "Space between generic and paren mismatch"
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
defaultOptions: [],
|
|
239
|
+
create: (context) => {
|
|
240
|
+
const sourceCode = context.getSourceCode();
|
|
241
|
+
const text = sourceCode.text;
|
|
242
|
+
return {
|
|
243
|
+
TSTypeParameter: (node) => {
|
|
244
|
+
const spaceStartRange = node.range[1] + 1;
|
|
245
|
+
const post = text.slice(spaceStartRange);
|
|
246
|
+
const postSpace = post.match(/^(\s*)/)?.[0];
|
|
247
|
+
const postEqual = post.slice(postSpace.length).match(/^(=)/)?.[0];
|
|
248
|
+
const postComma = text.slice(node.range[1]).match(/^(,)/)?.[0];
|
|
249
|
+
if (postSpace && postSpace.length && !postEqual && !postComma) {
|
|
250
|
+
context.report({
|
|
251
|
+
loc: {
|
|
252
|
+
start: {
|
|
253
|
+
line: node.loc.end.line,
|
|
254
|
+
column: node.loc.end.column + 1
|
|
255
|
+
},
|
|
256
|
+
end: {
|
|
257
|
+
line: node.loc.end.line,
|
|
258
|
+
column: node.loc.end.column + 1 + postSpace.length
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
node,
|
|
262
|
+
messageId: "spaceBetweenGenericAndParenMismatch",
|
|
263
|
+
*fix(fixer) {
|
|
264
|
+
yield fixer.replaceTextRange([spaceStartRange, spaceStartRange + postSpace.length], "");
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
if (node.parent?.parent.type === "FunctionDeclaration") {
|
|
269
|
+
const spaceEndRange = node.range[0] - 1;
|
|
270
|
+
const pre = sourceCode.text.slice(0, spaceEndRange);
|
|
271
|
+
const preSpace = pre.match(/(\s+)$/)?.[0];
|
|
272
|
+
if (preSpace && preSpace.length) {
|
|
273
|
+
context.report({
|
|
274
|
+
loc: {
|
|
275
|
+
start: {
|
|
276
|
+
line: node.loc.start.line,
|
|
277
|
+
column: node.loc.start.column - preSpace.length
|
|
278
|
+
},
|
|
279
|
+
end: {
|
|
280
|
+
line: node.loc.start.line,
|
|
281
|
+
column: node.loc.start.column - 1
|
|
282
|
+
}
|
|
283
|
+
},
|
|
284
|
+
node,
|
|
285
|
+
messageId: "spaceBetweenGenericAndParenMismatch",
|
|
286
|
+
*fix(fixer) {
|
|
287
|
+
yield fixer.replaceTextRange([spaceEndRange - preSpace.length, spaceEndRange], "");
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
const RULE_NAME$1 = "space-in-empty-block";
|
|
298
|
+
const spaceInEmptyBlock = createEslintRule({
|
|
299
|
+
name: RULE_NAME$1,
|
|
300
|
+
meta: {
|
|
301
|
+
type: "suggestion",
|
|
302
|
+
docs: {
|
|
303
|
+
description: "Spaces in empty block",
|
|
304
|
+
recommended: "error"
|
|
305
|
+
},
|
|
306
|
+
fixable: "code",
|
|
307
|
+
schema: [],
|
|
308
|
+
messages: {
|
|
309
|
+
spaceInEmptyBlockMismatch: "Space in empty block mismatch"
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
defaultOptions: [],
|
|
313
|
+
create: (context) => {
|
|
314
|
+
const sourceCode = context.getSourceCode();
|
|
315
|
+
return {
|
|
316
|
+
BlockStatement: (node) => {
|
|
317
|
+
if (node.body.length) {
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
const spaceStartRange = node.range[1] - 2;
|
|
321
|
+
const post = sourceCode.text.slice(spaceStartRange);
|
|
322
|
+
const postSpace = post.match(/^(\s*)/)?.[0];
|
|
323
|
+
if (postSpace && postSpace.length) {
|
|
324
|
+
context.report({
|
|
325
|
+
loc: {
|
|
326
|
+
start: node.loc.start,
|
|
327
|
+
end: {
|
|
328
|
+
line: node.loc.end.line,
|
|
329
|
+
column: node.loc.end.column - 1 + postSpace.length
|
|
330
|
+
}
|
|
331
|
+
},
|
|
332
|
+
messageId: "spaceInEmptyBlockMismatch",
|
|
333
|
+
*fix(fixer) {
|
|
334
|
+
yield fixer.replaceTextRange([node.range[0] + 1, spaceStartRange + postSpace.length], "");
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
const spaceEndRange = node.range[0] + 1;
|
|
339
|
+
const pre = sourceCode.text.slice(0, spaceEndRange);
|
|
340
|
+
const preSpace = pre.match(/(\s+)$/)?.[0];
|
|
341
|
+
if (preSpace && preSpace.length) {
|
|
342
|
+
context.report({
|
|
343
|
+
loc: {
|
|
344
|
+
start: {
|
|
345
|
+
line: node.loc.start.line,
|
|
346
|
+
column: node.loc.start.column - preSpace.length
|
|
347
|
+
},
|
|
348
|
+
end: {
|
|
349
|
+
line: node.loc.start.line,
|
|
350
|
+
column: node.loc.start.column
|
|
351
|
+
}
|
|
352
|
+
},
|
|
353
|
+
messageId: "spaceInEmptyBlockMismatch",
|
|
354
|
+
*fix(fixer) {
|
|
355
|
+
yield fixer.replaceTextRange([spaceEndRange - preSpace.length, spaceEndRange], "");
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
const RULE_NAME = "semi-spacing";
|
|
365
|
+
const semiSpacing = createEslintRule({
|
|
366
|
+
name: RULE_NAME,
|
|
367
|
+
meta: {
|
|
368
|
+
type: "suggestion",
|
|
369
|
+
docs: {
|
|
370
|
+
description: "Semicolon spacing",
|
|
371
|
+
recommended: "error"
|
|
372
|
+
},
|
|
373
|
+
fixable: "code",
|
|
374
|
+
schema: [],
|
|
375
|
+
messages: {
|
|
376
|
+
semiSpacingMismatch: "Semi spacing mismatch"
|
|
377
|
+
}
|
|
378
|
+
},
|
|
379
|
+
defaultOptions: [],
|
|
380
|
+
create: (context) => {
|
|
381
|
+
const sourceCode = context.getSourceCode();
|
|
382
|
+
const text = sourceCode.text;
|
|
383
|
+
return {
|
|
384
|
+
TSTypeAliasDeclaration(node) {
|
|
385
|
+
const sourceLine = text.slice(node.range[0], node.range[1]);
|
|
386
|
+
const preSemiSpace = sourceLine.match(/(\s+);$/)?.[0];
|
|
387
|
+
if (preSemiSpace) {
|
|
388
|
+
const spaceStart = node.range[0] + sourceLine.length - preSemiSpace.length;
|
|
389
|
+
const spaceEnd = node.range[0] + sourceLine.length - 1;
|
|
390
|
+
context.report({
|
|
391
|
+
loc: {
|
|
392
|
+
start: {
|
|
393
|
+
line: node.loc.start.line,
|
|
394
|
+
column: node.loc.start.column + sourceLine.length - preSemiSpace.length
|
|
395
|
+
},
|
|
396
|
+
end: {
|
|
397
|
+
line: node.loc.start.line,
|
|
398
|
+
column: node.loc.start.column + sourceLine.length - 1
|
|
399
|
+
}
|
|
400
|
+
},
|
|
401
|
+
node,
|
|
402
|
+
messageId: "semiSpacingMismatch",
|
|
403
|
+
*fix(fixer) {
|
|
404
|
+
yield fixer.removeRange([spaceStart, spaceEnd]);
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
|
|
148
413
|
const index = {
|
|
149
414
|
rules: {
|
|
150
415
|
"import-dedupe": importDedupe,
|
|
151
|
-
"generic-spacing": genericSpacing
|
|
416
|
+
"generic-spacing": genericSpacing,
|
|
417
|
+
"space-between-generic-and-paren": spaceBetweenGenericAndParen,
|
|
418
|
+
"space-in-empty-block": spaceInEmptyBlock,
|
|
419
|
+
"semi-spacing": semiSpacing
|
|
152
420
|
}
|
|
153
421
|
};
|
|
154
422
|
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,9 @@ declare const _default: {
|
|
|
4
4
|
rules: {
|
|
5
5
|
"import-dedupe": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"importDedupe", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
|
|
6
6
|
"generic-spacing": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"genericSpacingMismatch", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
|
|
7
|
+
"space-between-generic-and-paren": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"spaceBetweenGenericAndParenMismatch", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
|
|
8
|
+
"space-in-empty-block": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"spaceInEmptyBlockMismatch", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
|
|
9
|
+
"semi-spacing": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"semiSpacingMismatch", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
|
|
7
10
|
};
|
|
8
11
|
};
|
|
9
12
|
|
package/dist/index.mjs
CHANGED
|
@@ -2,9 +2,9 @@ import { ESLintUtils } from '@typescript-eslint/utils';
|
|
|
2
2
|
|
|
3
3
|
const createEslintRule = ESLintUtils.RuleCreator((ruleName) => ruleName);
|
|
4
4
|
|
|
5
|
-
const RULE_NAME$
|
|
5
|
+
const RULE_NAME$4 = "generic-spacing";
|
|
6
6
|
const genericSpacing = createEslintRule({
|
|
7
|
-
name: RULE_NAME$
|
|
7
|
+
name: RULE_NAME$4,
|
|
8
8
|
meta: {
|
|
9
9
|
type: "suggestion",
|
|
10
10
|
docs: {
|
|
@@ -22,6 +22,53 @@ const genericSpacing = createEslintRule({
|
|
|
22
22
|
const sourceCode = context.getSourceCode();
|
|
23
23
|
return {
|
|
24
24
|
TSTypeParameterDeclaration: (node) => {
|
|
25
|
+
const params = node.params;
|
|
26
|
+
for (let i = 0; i < params.length; i++) {
|
|
27
|
+
const param = params[i];
|
|
28
|
+
const pre = sourceCode.text.slice(0, param.range[0]);
|
|
29
|
+
const preSpace = pre.match(/(\s+)$/)?.[0];
|
|
30
|
+
const preComma = pre.match(/(,)\s+$/)?.[0];
|
|
31
|
+
const post = sourceCode.text.slice(param.range[1]);
|
|
32
|
+
const postSpace = post.match(/^(\s*)/)?.[0];
|
|
33
|
+
if (preSpace && preSpace.length && !preComma) {
|
|
34
|
+
context.report({
|
|
35
|
+
node,
|
|
36
|
+
loc: {
|
|
37
|
+
start: {
|
|
38
|
+
line: param.loc.end.line,
|
|
39
|
+
column: param.loc.end.column - 1 - preSpace.length
|
|
40
|
+
},
|
|
41
|
+
end: {
|
|
42
|
+
line: param.loc.end.line,
|
|
43
|
+
column: param.loc.end.column - 1
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
messageId: "genericSpacingMismatch",
|
|
47
|
+
*fix(fixer) {
|
|
48
|
+
yield fixer.replaceTextRange([param.range[0] - preSpace.length, param.range[0]], "");
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (postSpace && postSpace.length) {
|
|
53
|
+
context.report({
|
|
54
|
+
loc: {
|
|
55
|
+
start: {
|
|
56
|
+
line: param.loc.end.line,
|
|
57
|
+
column: param.loc.end.column
|
|
58
|
+
},
|
|
59
|
+
end: {
|
|
60
|
+
line: param.loc.end.line,
|
|
61
|
+
column: param.loc.end.column + postSpace.length
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
node,
|
|
65
|
+
messageId: "genericSpacingMismatch",
|
|
66
|
+
*fix(fixer) {
|
|
67
|
+
yield fixer.replaceTextRange([param.range[1], param.range[1] + postSpace.length], "");
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
25
72
|
if (!["TSCallSignatureDeclaration", "ArrowFunctionExpression"].includes(node.parent.type)) {
|
|
26
73
|
const pre = sourceCode.text.slice(0, node.range[0]);
|
|
27
74
|
const preSpace = pre.match(/(\s+)$/)?.[0];
|
|
@@ -46,7 +93,6 @@ const genericSpacing = createEslintRule({
|
|
|
46
93
|
});
|
|
47
94
|
}
|
|
48
95
|
}
|
|
49
|
-
const params = node.params;
|
|
50
96
|
for (let i = 1; i < params.length; i++) {
|
|
51
97
|
const prev = params[i - 1];
|
|
52
98
|
const current = params[i];
|
|
@@ -75,27 +121,56 @@ const genericSpacing = createEslintRule({
|
|
|
75
121
|
const endNode = node.constraint || node.name;
|
|
76
122
|
const from = endNode.range[1];
|
|
77
123
|
const to = node.default.range[0];
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
124
|
+
const spaceAndEqual = sourceCode.text.slice(from, to);
|
|
125
|
+
if (spaceAndEqual !== " = ") {
|
|
126
|
+
const preSpace = spaceAndEqual.match(/^(\s*)/)?.[0];
|
|
127
|
+
const postSpace = spaceAndEqual.match(/(\s*)$/)?.[0];
|
|
128
|
+
if (preSpace.length !== 1) {
|
|
129
|
+
context.report({
|
|
130
|
+
*fix(fixer) {
|
|
131
|
+
yield fixer.replaceTextRange([from, from + preSpace.length], " ");
|
|
132
|
+
},
|
|
133
|
+
loc: {
|
|
134
|
+
start: {
|
|
135
|
+
line: node.loc.start.line,
|
|
136
|
+
column: node.loc.start.column + 1
|
|
137
|
+
},
|
|
138
|
+
end: {
|
|
139
|
+
line: node.loc.end.line,
|
|
140
|
+
column: node.loc.end.column - 2 - postSpace.length
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
node,
|
|
144
|
+
messageId: "genericSpacingMismatch"
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
if (postSpace.length !== 1) {
|
|
148
|
+
context.report({
|
|
149
|
+
*fix(fixer) {
|
|
150
|
+
yield fixer.replaceTextRange([to - postSpace.length, to], " ");
|
|
151
|
+
},
|
|
152
|
+
loc: {
|
|
153
|
+
start: {
|
|
154
|
+
line: node.loc.start.line,
|
|
155
|
+
column: node.loc.start.column + 2 + preSpace.length
|
|
156
|
+
},
|
|
157
|
+
end: {
|
|
158
|
+
line: node.loc.end.line,
|
|
159
|
+
column: node.loc.end.column - 1
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
messageId: "genericSpacingMismatch"
|
|
163
|
+
});
|
|
164
|
+
}
|
|
90
165
|
}
|
|
91
166
|
}
|
|
92
167
|
};
|
|
93
168
|
}
|
|
94
169
|
});
|
|
95
170
|
|
|
96
|
-
const RULE_NAME = "import-dedupe";
|
|
171
|
+
const RULE_NAME$3 = "import-dedupe";
|
|
97
172
|
const importDedupe = createEslintRule({
|
|
98
|
-
name: RULE_NAME,
|
|
173
|
+
name: RULE_NAME$3,
|
|
99
174
|
meta: {
|
|
100
175
|
type: "problem",
|
|
101
176
|
docs: {
|
|
@@ -143,10 +218,203 @@ const importDedupe = createEslintRule({
|
|
|
143
218
|
}
|
|
144
219
|
});
|
|
145
220
|
|
|
221
|
+
const RULE_NAME$2 = "space-between-generic-and-paren";
|
|
222
|
+
const spaceBetweenGenericAndParen = createEslintRule({
|
|
223
|
+
name: RULE_NAME$2,
|
|
224
|
+
meta: {
|
|
225
|
+
type: "suggestion",
|
|
226
|
+
docs: {
|
|
227
|
+
description: "Spaces between generic type parameters and paren",
|
|
228
|
+
recommended: "error"
|
|
229
|
+
},
|
|
230
|
+
fixable: "code",
|
|
231
|
+
schema: [],
|
|
232
|
+
messages: {
|
|
233
|
+
spaceBetweenGenericAndParenMismatch: "Space between generic and paren mismatch"
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
defaultOptions: [],
|
|
237
|
+
create: (context) => {
|
|
238
|
+
const sourceCode = context.getSourceCode();
|
|
239
|
+
const text = sourceCode.text;
|
|
240
|
+
return {
|
|
241
|
+
TSTypeParameter: (node) => {
|
|
242
|
+
const spaceStartRange = node.range[1] + 1;
|
|
243
|
+
const post = text.slice(spaceStartRange);
|
|
244
|
+
const postSpace = post.match(/^(\s*)/)?.[0];
|
|
245
|
+
const postEqual = post.slice(postSpace.length).match(/^(=)/)?.[0];
|
|
246
|
+
const postComma = text.slice(node.range[1]).match(/^(,)/)?.[0];
|
|
247
|
+
if (postSpace && postSpace.length && !postEqual && !postComma) {
|
|
248
|
+
context.report({
|
|
249
|
+
loc: {
|
|
250
|
+
start: {
|
|
251
|
+
line: node.loc.end.line,
|
|
252
|
+
column: node.loc.end.column + 1
|
|
253
|
+
},
|
|
254
|
+
end: {
|
|
255
|
+
line: node.loc.end.line,
|
|
256
|
+
column: node.loc.end.column + 1 + postSpace.length
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
node,
|
|
260
|
+
messageId: "spaceBetweenGenericAndParenMismatch",
|
|
261
|
+
*fix(fixer) {
|
|
262
|
+
yield fixer.replaceTextRange([spaceStartRange, spaceStartRange + postSpace.length], "");
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
if (node.parent?.parent.type === "FunctionDeclaration") {
|
|
267
|
+
const spaceEndRange = node.range[0] - 1;
|
|
268
|
+
const pre = sourceCode.text.slice(0, spaceEndRange);
|
|
269
|
+
const preSpace = pre.match(/(\s+)$/)?.[0];
|
|
270
|
+
if (preSpace && preSpace.length) {
|
|
271
|
+
context.report({
|
|
272
|
+
loc: {
|
|
273
|
+
start: {
|
|
274
|
+
line: node.loc.start.line,
|
|
275
|
+
column: node.loc.start.column - preSpace.length
|
|
276
|
+
},
|
|
277
|
+
end: {
|
|
278
|
+
line: node.loc.start.line,
|
|
279
|
+
column: node.loc.start.column - 1
|
|
280
|
+
}
|
|
281
|
+
},
|
|
282
|
+
node,
|
|
283
|
+
messageId: "spaceBetweenGenericAndParenMismatch",
|
|
284
|
+
*fix(fixer) {
|
|
285
|
+
yield fixer.replaceTextRange([spaceEndRange - preSpace.length, spaceEndRange], "");
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
const RULE_NAME$1 = "space-in-empty-block";
|
|
296
|
+
const spaceInEmptyBlock = createEslintRule({
|
|
297
|
+
name: RULE_NAME$1,
|
|
298
|
+
meta: {
|
|
299
|
+
type: "suggestion",
|
|
300
|
+
docs: {
|
|
301
|
+
description: "Spaces in empty block",
|
|
302
|
+
recommended: "error"
|
|
303
|
+
},
|
|
304
|
+
fixable: "code",
|
|
305
|
+
schema: [],
|
|
306
|
+
messages: {
|
|
307
|
+
spaceInEmptyBlockMismatch: "Space in empty block mismatch"
|
|
308
|
+
}
|
|
309
|
+
},
|
|
310
|
+
defaultOptions: [],
|
|
311
|
+
create: (context) => {
|
|
312
|
+
const sourceCode = context.getSourceCode();
|
|
313
|
+
return {
|
|
314
|
+
BlockStatement: (node) => {
|
|
315
|
+
if (node.body.length) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
const spaceStartRange = node.range[1] - 2;
|
|
319
|
+
const post = sourceCode.text.slice(spaceStartRange);
|
|
320
|
+
const postSpace = post.match(/^(\s*)/)?.[0];
|
|
321
|
+
if (postSpace && postSpace.length) {
|
|
322
|
+
context.report({
|
|
323
|
+
loc: {
|
|
324
|
+
start: node.loc.start,
|
|
325
|
+
end: {
|
|
326
|
+
line: node.loc.end.line,
|
|
327
|
+
column: node.loc.end.column - 1 + postSpace.length
|
|
328
|
+
}
|
|
329
|
+
},
|
|
330
|
+
messageId: "spaceInEmptyBlockMismatch",
|
|
331
|
+
*fix(fixer) {
|
|
332
|
+
yield fixer.replaceTextRange([node.range[0] + 1, spaceStartRange + postSpace.length], "");
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
const spaceEndRange = node.range[0] + 1;
|
|
337
|
+
const pre = sourceCode.text.slice(0, spaceEndRange);
|
|
338
|
+
const preSpace = pre.match(/(\s+)$/)?.[0];
|
|
339
|
+
if (preSpace && preSpace.length) {
|
|
340
|
+
context.report({
|
|
341
|
+
loc: {
|
|
342
|
+
start: {
|
|
343
|
+
line: node.loc.start.line,
|
|
344
|
+
column: node.loc.start.column - preSpace.length
|
|
345
|
+
},
|
|
346
|
+
end: {
|
|
347
|
+
line: node.loc.start.line,
|
|
348
|
+
column: node.loc.start.column
|
|
349
|
+
}
|
|
350
|
+
},
|
|
351
|
+
messageId: "spaceInEmptyBlockMismatch",
|
|
352
|
+
*fix(fixer) {
|
|
353
|
+
yield fixer.replaceTextRange([spaceEndRange - preSpace.length, spaceEndRange], "");
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
const RULE_NAME = "semi-spacing";
|
|
363
|
+
const semiSpacing = createEslintRule({
|
|
364
|
+
name: RULE_NAME,
|
|
365
|
+
meta: {
|
|
366
|
+
type: "suggestion",
|
|
367
|
+
docs: {
|
|
368
|
+
description: "Semicolon spacing",
|
|
369
|
+
recommended: "error"
|
|
370
|
+
},
|
|
371
|
+
fixable: "code",
|
|
372
|
+
schema: [],
|
|
373
|
+
messages: {
|
|
374
|
+
semiSpacingMismatch: "Semi spacing mismatch"
|
|
375
|
+
}
|
|
376
|
+
},
|
|
377
|
+
defaultOptions: [],
|
|
378
|
+
create: (context) => {
|
|
379
|
+
const sourceCode = context.getSourceCode();
|
|
380
|
+
const text = sourceCode.text;
|
|
381
|
+
return {
|
|
382
|
+
TSTypeAliasDeclaration(node) {
|
|
383
|
+
const sourceLine = text.slice(node.range[0], node.range[1]);
|
|
384
|
+
const preSemiSpace = sourceLine.match(/(\s+);$/)?.[0];
|
|
385
|
+
if (preSemiSpace) {
|
|
386
|
+
const spaceStart = node.range[0] + sourceLine.length - preSemiSpace.length;
|
|
387
|
+
const spaceEnd = node.range[0] + sourceLine.length - 1;
|
|
388
|
+
context.report({
|
|
389
|
+
loc: {
|
|
390
|
+
start: {
|
|
391
|
+
line: node.loc.start.line,
|
|
392
|
+
column: node.loc.start.column + sourceLine.length - preSemiSpace.length
|
|
393
|
+
},
|
|
394
|
+
end: {
|
|
395
|
+
line: node.loc.start.line,
|
|
396
|
+
column: node.loc.start.column + sourceLine.length - 1
|
|
397
|
+
}
|
|
398
|
+
},
|
|
399
|
+
node,
|
|
400
|
+
messageId: "semiSpacingMismatch",
|
|
401
|
+
*fix(fixer) {
|
|
402
|
+
yield fixer.removeRange([spaceStart, spaceEnd]);
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
|
|
146
411
|
const index = {
|
|
147
412
|
rules: {
|
|
148
413
|
"import-dedupe": importDedupe,
|
|
149
|
-
"generic-spacing": genericSpacing
|
|
414
|
+
"generic-spacing": genericSpacing,
|
|
415
|
+
"space-between-generic-and-paren": spaceBetweenGenericAndParen,
|
|
416
|
+
"space-in-empty-block": spaceInEmptyBlock,
|
|
417
|
+
"semi-spacing": semiSpacing
|
|
150
418
|
}
|
|
151
419
|
};
|
|
152
420
|
|