@so1ve/eslint-plugin 0.34.0 → 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 +132 -30
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +132 -30
- 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: {
|
|
@@ -29,11 +29,22 @@ const genericSpacing = createEslintRule({
|
|
|
29
29
|
const param = params[i];
|
|
30
30
|
const pre = sourceCode.text.slice(0, param.range[0]);
|
|
31
31
|
const preSpace = pre.match(/(\s+)$/)?.[0];
|
|
32
|
+
const preComma = pre.match(/(,)\s+$/)?.[0];
|
|
32
33
|
const post = sourceCode.text.slice(param.range[1]);
|
|
33
34
|
const postSpace = post.match(/^(\s*)/)?.[0];
|
|
34
|
-
if (preSpace && preSpace.length) {
|
|
35
|
+
if (preSpace && preSpace.length && !preComma) {
|
|
35
36
|
context.report({
|
|
36
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
|
+
},
|
|
37
48
|
messageId: "genericSpacingMismatch",
|
|
38
49
|
*fix(fixer) {
|
|
39
50
|
yield fixer.replaceTextRange([param.range[0] - preSpace.length, param.range[0]], "");
|
|
@@ -42,6 +53,16 @@ const genericSpacing = createEslintRule({
|
|
|
42
53
|
}
|
|
43
54
|
if (postSpace && postSpace.length) {
|
|
44
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
|
+
},
|
|
45
66
|
node,
|
|
46
67
|
messageId: "genericSpacingMismatch",
|
|
47
68
|
*fix(fixer) {
|
|
@@ -102,27 +123,56 @@ const genericSpacing = createEslintRule({
|
|
|
102
123
|
const endNode = node.constraint || node.name;
|
|
103
124
|
const from = endNode.range[1];
|
|
104
125
|
const to = node.default.range[0];
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
+
}
|
|
117
167
|
}
|
|
118
168
|
}
|
|
119
169
|
};
|
|
120
170
|
}
|
|
121
171
|
});
|
|
122
172
|
|
|
123
|
-
const RULE_NAME$
|
|
173
|
+
const RULE_NAME$3 = "import-dedupe";
|
|
124
174
|
const importDedupe = createEslintRule({
|
|
125
|
-
name: RULE_NAME$
|
|
175
|
+
name: RULE_NAME$3,
|
|
126
176
|
meta: {
|
|
127
177
|
type: "problem",
|
|
128
178
|
docs: {
|
|
@@ -170,9 +220,9 @@ const importDedupe = createEslintRule({
|
|
|
170
220
|
}
|
|
171
221
|
});
|
|
172
222
|
|
|
173
|
-
const RULE_NAME$
|
|
223
|
+
const RULE_NAME$2 = "space-between-generic-and-paren";
|
|
174
224
|
const spaceBetweenGenericAndParen = createEslintRule({
|
|
175
|
-
name: RULE_NAME$
|
|
225
|
+
name: RULE_NAME$2,
|
|
176
226
|
meta: {
|
|
177
227
|
type: "suggestion",
|
|
178
228
|
docs: {
|
|
@@ -188,12 +238,15 @@ const spaceBetweenGenericAndParen = createEslintRule({
|
|
|
188
238
|
defaultOptions: [],
|
|
189
239
|
create: (context) => {
|
|
190
240
|
const sourceCode = context.getSourceCode();
|
|
241
|
+
const text = sourceCode.text;
|
|
191
242
|
return {
|
|
192
243
|
TSTypeParameter: (node) => {
|
|
193
244
|
const spaceStartRange = node.range[1] + 1;
|
|
194
|
-
const post =
|
|
245
|
+
const post = text.slice(spaceStartRange);
|
|
195
246
|
const postSpace = post.match(/^(\s*)/)?.[0];
|
|
196
|
-
|
|
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) {
|
|
197
250
|
context.report({
|
|
198
251
|
loc: {
|
|
199
252
|
start: {
|
|
@@ -205,6 +258,7 @@ const spaceBetweenGenericAndParen = createEslintRule({
|
|
|
205
258
|
column: node.loc.end.column + 1 + postSpace.length
|
|
206
259
|
}
|
|
207
260
|
},
|
|
261
|
+
node,
|
|
208
262
|
messageId: "spaceBetweenGenericAndParenMismatch",
|
|
209
263
|
*fix(fixer) {
|
|
210
264
|
yield fixer.replaceTextRange([spaceStartRange, spaceStartRange + postSpace.length], "");
|
|
@@ -227,6 +281,7 @@ const spaceBetweenGenericAndParen = createEslintRule({
|
|
|
227
281
|
column: node.loc.start.column - 1
|
|
228
282
|
}
|
|
229
283
|
},
|
|
284
|
+
node,
|
|
230
285
|
messageId: "spaceBetweenGenericAndParenMismatch",
|
|
231
286
|
*fix(fixer) {
|
|
232
287
|
yield fixer.replaceTextRange([spaceEndRange - preSpace.length, spaceEndRange], "");
|
|
@@ -239,9 +294,9 @@ const spaceBetweenGenericAndParen = createEslintRule({
|
|
|
239
294
|
}
|
|
240
295
|
});
|
|
241
296
|
|
|
242
|
-
const RULE_NAME = "space-in-empty-block";
|
|
297
|
+
const RULE_NAME$1 = "space-in-empty-block";
|
|
243
298
|
const spaceInEmptyBlock = createEslintRule({
|
|
244
|
-
name: RULE_NAME,
|
|
299
|
+
name: RULE_NAME$1,
|
|
245
300
|
meta: {
|
|
246
301
|
type: "suggestion",
|
|
247
302
|
docs: {
|
|
@@ -268,18 +323,15 @@ const spaceInEmptyBlock = createEslintRule({
|
|
|
268
323
|
if (postSpace && postSpace.length) {
|
|
269
324
|
context.report({
|
|
270
325
|
loc: {
|
|
271
|
-
start:
|
|
272
|
-
line: node.loc.end.line,
|
|
273
|
-
column: node.loc.end.column - 2
|
|
274
|
-
},
|
|
326
|
+
start: node.loc.start,
|
|
275
327
|
end: {
|
|
276
328
|
line: node.loc.end.line,
|
|
277
|
-
column: node.loc.end.column -
|
|
329
|
+
column: node.loc.end.column - 1 + postSpace.length
|
|
278
330
|
}
|
|
279
331
|
},
|
|
280
332
|
messageId: "spaceInEmptyBlockMismatch",
|
|
281
333
|
*fix(fixer) {
|
|
282
|
-
yield fixer.replaceTextRange([
|
|
334
|
+
yield fixer.replaceTextRange([node.range[0] + 1, spaceStartRange + postSpace.length], "");
|
|
283
335
|
}
|
|
284
336
|
});
|
|
285
337
|
}
|
|
@@ -309,12 +361,62 @@ const spaceInEmptyBlock = createEslintRule({
|
|
|
309
361
|
}
|
|
310
362
|
});
|
|
311
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
|
+
|
|
312
413
|
const index = {
|
|
313
414
|
rules: {
|
|
314
415
|
"import-dedupe": importDedupe,
|
|
315
416
|
"generic-spacing": genericSpacing,
|
|
316
417
|
"space-between-generic-and-paren": spaceBetweenGenericAndParen,
|
|
317
|
-
"space-in-empty-block": spaceInEmptyBlock
|
|
418
|
+
"space-in-empty-block": spaceInEmptyBlock,
|
|
419
|
+
"semi-spacing": semiSpacing
|
|
318
420
|
}
|
|
319
421
|
};
|
|
320
422
|
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ declare const _default: {
|
|
|
6
6
|
"generic-spacing": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"genericSpacingMismatch", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
|
|
7
7
|
"space-between-generic-and-paren": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"spaceBetweenGenericAndParenMismatch", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
|
|
8
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>;
|
|
9
10
|
};
|
|
10
11
|
};
|
|
11
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: {
|
|
@@ -27,11 +27,22 @@ const genericSpacing = createEslintRule({
|
|
|
27
27
|
const param = params[i];
|
|
28
28
|
const pre = sourceCode.text.slice(0, param.range[0]);
|
|
29
29
|
const preSpace = pre.match(/(\s+)$/)?.[0];
|
|
30
|
+
const preComma = pre.match(/(,)\s+$/)?.[0];
|
|
30
31
|
const post = sourceCode.text.slice(param.range[1]);
|
|
31
32
|
const postSpace = post.match(/^(\s*)/)?.[0];
|
|
32
|
-
if (preSpace && preSpace.length) {
|
|
33
|
+
if (preSpace && preSpace.length && !preComma) {
|
|
33
34
|
context.report({
|
|
34
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
|
+
},
|
|
35
46
|
messageId: "genericSpacingMismatch",
|
|
36
47
|
*fix(fixer) {
|
|
37
48
|
yield fixer.replaceTextRange([param.range[0] - preSpace.length, param.range[0]], "");
|
|
@@ -40,6 +51,16 @@ const genericSpacing = createEslintRule({
|
|
|
40
51
|
}
|
|
41
52
|
if (postSpace && postSpace.length) {
|
|
42
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
|
+
},
|
|
43
64
|
node,
|
|
44
65
|
messageId: "genericSpacingMismatch",
|
|
45
66
|
*fix(fixer) {
|
|
@@ -100,27 +121,56 @@ const genericSpacing = createEslintRule({
|
|
|
100
121
|
const endNode = node.constraint || node.name;
|
|
101
122
|
const from = endNode.range[1];
|
|
102
123
|
const to = node.default.range[0];
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
+
}
|
|
115
165
|
}
|
|
116
166
|
}
|
|
117
167
|
};
|
|
118
168
|
}
|
|
119
169
|
});
|
|
120
170
|
|
|
121
|
-
const RULE_NAME$
|
|
171
|
+
const RULE_NAME$3 = "import-dedupe";
|
|
122
172
|
const importDedupe = createEslintRule({
|
|
123
|
-
name: RULE_NAME$
|
|
173
|
+
name: RULE_NAME$3,
|
|
124
174
|
meta: {
|
|
125
175
|
type: "problem",
|
|
126
176
|
docs: {
|
|
@@ -168,9 +218,9 @@ const importDedupe = createEslintRule({
|
|
|
168
218
|
}
|
|
169
219
|
});
|
|
170
220
|
|
|
171
|
-
const RULE_NAME$
|
|
221
|
+
const RULE_NAME$2 = "space-between-generic-and-paren";
|
|
172
222
|
const spaceBetweenGenericAndParen = createEslintRule({
|
|
173
|
-
name: RULE_NAME$
|
|
223
|
+
name: RULE_NAME$2,
|
|
174
224
|
meta: {
|
|
175
225
|
type: "suggestion",
|
|
176
226
|
docs: {
|
|
@@ -186,12 +236,15 @@ const spaceBetweenGenericAndParen = createEslintRule({
|
|
|
186
236
|
defaultOptions: [],
|
|
187
237
|
create: (context) => {
|
|
188
238
|
const sourceCode = context.getSourceCode();
|
|
239
|
+
const text = sourceCode.text;
|
|
189
240
|
return {
|
|
190
241
|
TSTypeParameter: (node) => {
|
|
191
242
|
const spaceStartRange = node.range[1] + 1;
|
|
192
|
-
const post =
|
|
243
|
+
const post = text.slice(spaceStartRange);
|
|
193
244
|
const postSpace = post.match(/^(\s*)/)?.[0];
|
|
194
|
-
|
|
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) {
|
|
195
248
|
context.report({
|
|
196
249
|
loc: {
|
|
197
250
|
start: {
|
|
@@ -203,6 +256,7 @@ const spaceBetweenGenericAndParen = createEslintRule({
|
|
|
203
256
|
column: node.loc.end.column + 1 + postSpace.length
|
|
204
257
|
}
|
|
205
258
|
},
|
|
259
|
+
node,
|
|
206
260
|
messageId: "spaceBetweenGenericAndParenMismatch",
|
|
207
261
|
*fix(fixer) {
|
|
208
262
|
yield fixer.replaceTextRange([spaceStartRange, spaceStartRange + postSpace.length], "");
|
|
@@ -225,6 +279,7 @@ const spaceBetweenGenericAndParen = createEslintRule({
|
|
|
225
279
|
column: node.loc.start.column - 1
|
|
226
280
|
}
|
|
227
281
|
},
|
|
282
|
+
node,
|
|
228
283
|
messageId: "spaceBetweenGenericAndParenMismatch",
|
|
229
284
|
*fix(fixer) {
|
|
230
285
|
yield fixer.replaceTextRange([spaceEndRange - preSpace.length, spaceEndRange], "");
|
|
@@ -237,9 +292,9 @@ const spaceBetweenGenericAndParen = createEslintRule({
|
|
|
237
292
|
}
|
|
238
293
|
});
|
|
239
294
|
|
|
240
|
-
const RULE_NAME = "space-in-empty-block";
|
|
295
|
+
const RULE_NAME$1 = "space-in-empty-block";
|
|
241
296
|
const spaceInEmptyBlock = createEslintRule({
|
|
242
|
-
name: RULE_NAME,
|
|
297
|
+
name: RULE_NAME$1,
|
|
243
298
|
meta: {
|
|
244
299
|
type: "suggestion",
|
|
245
300
|
docs: {
|
|
@@ -266,18 +321,15 @@ const spaceInEmptyBlock = createEslintRule({
|
|
|
266
321
|
if (postSpace && postSpace.length) {
|
|
267
322
|
context.report({
|
|
268
323
|
loc: {
|
|
269
|
-
start:
|
|
270
|
-
line: node.loc.end.line,
|
|
271
|
-
column: node.loc.end.column - 2
|
|
272
|
-
},
|
|
324
|
+
start: node.loc.start,
|
|
273
325
|
end: {
|
|
274
326
|
line: node.loc.end.line,
|
|
275
|
-
column: node.loc.end.column -
|
|
327
|
+
column: node.loc.end.column - 1 + postSpace.length
|
|
276
328
|
}
|
|
277
329
|
},
|
|
278
330
|
messageId: "spaceInEmptyBlockMismatch",
|
|
279
331
|
*fix(fixer) {
|
|
280
|
-
yield fixer.replaceTextRange([
|
|
332
|
+
yield fixer.replaceTextRange([node.range[0] + 1, spaceStartRange + postSpace.length], "");
|
|
281
333
|
}
|
|
282
334
|
});
|
|
283
335
|
}
|
|
@@ -307,12 +359,62 @@ const spaceInEmptyBlock = createEslintRule({
|
|
|
307
359
|
}
|
|
308
360
|
});
|
|
309
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
|
+
|
|
310
411
|
const index = {
|
|
311
412
|
rules: {
|
|
312
413
|
"import-dedupe": importDedupe,
|
|
313
414
|
"generic-spacing": genericSpacing,
|
|
314
415
|
"space-between-generic-and-paren": spaceBetweenGenericAndParen,
|
|
315
|
-
"space-in-empty-block": spaceInEmptyBlock
|
|
416
|
+
"space-in-empty-block": spaceInEmptyBlock,
|
|
417
|
+
"semi-spacing": semiSpacing
|
|
316
418
|
}
|
|
317
419
|
};
|
|
318
420
|
|