@so1ve/eslint-plugin 0.32.2 → 0.34.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 +172 -6
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +172 -6
- 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$3 = "generic-spacing";
|
|
8
8
|
const genericSpacing = createEslintRule({
|
|
9
|
-
name: RULE_NAME$
|
|
9
|
+
name: RULE_NAME$3,
|
|
10
10
|
meta: {
|
|
11
11
|
type: "suggestion",
|
|
12
12
|
docs: {
|
|
@@ -24,6 +24,32 @@ 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 post = sourceCode.text.slice(param.range[1]);
|
|
33
|
+
const postSpace = post.match(/^(\s*)/)?.[0];
|
|
34
|
+
if (preSpace && preSpace.length) {
|
|
35
|
+
context.report({
|
|
36
|
+
node,
|
|
37
|
+
messageId: "genericSpacingMismatch",
|
|
38
|
+
*fix(fixer) {
|
|
39
|
+
yield fixer.replaceTextRange([param.range[0] - preSpace.length, param.range[0]], "");
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
if (postSpace && postSpace.length) {
|
|
44
|
+
context.report({
|
|
45
|
+
node,
|
|
46
|
+
messageId: "genericSpacingMismatch",
|
|
47
|
+
*fix(fixer) {
|
|
48
|
+
yield fixer.replaceTextRange([param.range[1], param.range[1] + postSpace.length], "");
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
27
53
|
if (!["TSCallSignatureDeclaration", "ArrowFunctionExpression"].includes(node.parent.type)) {
|
|
28
54
|
const pre = sourceCode.text.slice(0, node.range[0]);
|
|
29
55
|
const preSpace = pre.match(/(\s+)$/)?.[0];
|
|
@@ -48,7 +74,6 @@ const genericSpacing = createEslintRule({
|
|
|
48
74
|
});
|
|
49
75
|
}
|
|
50
76
|
}
|
|
51
|
-
const params = node.params;
|
|
52
77
|
for (let i = 1; i < params.length; i++) {
|
|
53
78
|
const prev = params[i - 1];
|
|
54
79
|
const current = params[i];
|
|
@@ -95,9 +120,9 @@ const genericSpacing = createEslintRule({
|
|
|
95
120
|
}
|
|
96
121
|
});
|
|
97
122
|
|
|
98
|
-
const RULE_NAME = "import-dedupe";
|
|
123
|
+
const RULE_NAME$2 = "import-dedupe";
|
|
99
124
|
const importDedupe = createEslintRule({
|
|
100
|
-
name: RULE_NAME,
|
|
125
|
+
name: RULE_NAME$2,
|
|
101
126
|
meta: {
|
|
102
127
|
type: "problem",
|
|
103
128
|
docs: {
|
|
@@ -145,10 +170,151 @@ const importDedupe = createEslintRule({
|
|
|
145
170
|
}
|
|
146
171
|
});
|
|
147
172
|
|
|
173
|
+
const RULE_NAME$1 = "space-between-generic-and-paren";
|
|
174
|
+
const spaceBetweenGenericAndParen = createEslintRule({
|
|
175
|
+
name: RULE_NAME$1,
|
|
176
|
+
meta: {
|
|
177
|
+
type: "suggestion",
|
|
178
|
+
docs: {
|
|
179
|
+
description: "Spaces between generic type parameters and paren",
|
|
180
|
+
recommended: "error"
|
|
181
|
+
},
|
|
182
|
+
fixable: "code",
|
|
183
|
+
schema: [],
|
|
184
|
+
messages: {
|
|
185
|
+
spaceBetweenGenericAndParenMismatch: "Space between generic and paren mismatch"
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
defaultOptions: [],
|
|
189
|
+
create: (context) => {
|
|
190
|
+
const sourceCode = context.getSourceCode();
|
|
191
|
+
return {
|
|
192
|
+
TSTypeParameter: (node) => {
|
|
193
|
+
const spaceStartRange = node.range[1] + 1;
|
|
194
|
+
const post = sourceCode.text.slice(spaceStartRange);
|
|
195
|
+
const postSpace = post.match(/^(\s*)/)?.[0];
|
|
196
|
+
if (postSpace && postSpace.length) {
|
|
197
|
+
context.report({
|
|
198
|
+
loc: {
|
|
199
|
+
start: {
|
|
200
|
+
line: node.loc.end.line,
|
|
201
|
+
column: node.loc.end.column + 1
|
|
202
|
+
},
|
|
203
|
+
end: {
|
|
204
|
+
line: node.loc.end.line,
|
|
205
|
+
column: node.loc.end.column + 1 + postSpace.length
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
messageId: "spaceBetweenGenericAndParenMismatch",
|
|
209
|
+
*fix(fixer) {
|
|
210
|
+
yield fixer.replaceTextRange([spaceStartRange, spaceStartRange + postSpace.length], "");
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
if (node.parent?.parent.type === "FunctionDeclaration") {
|
|
215
|
+
const spaceEndRange = node.range[0] - 1;
|
|
216
|
+
const pre = sourceCode.text.slice(0, spaceEndRange);
|
|
217
|
+
const preSpace = pre.match(/(\s+)$/)?.[0];
|
|
218
|
+
if (preSpace && preSpace.length) {
|
|
219
|
+
context.report({
|
|
220
|
+
loc: {
|
|
221
|
+
start: {
|
|
222
|
+
line: node.loc.start.line,
|
|
223
|
+
column: node.loc.start.column - preSpace.length
|
|
224
|
+
},
|
|
225
|
+
end: {
|
|
226
|
+
line: node.loc.start.line,
|
|
227
|
+
column: node.loc.start.column - 1
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
messageId: "spaceBetweenGenericAndParenMismatch",
|
|
231
|
+
*fix(fixer) {
|
|
232
|
+
yield fixer.replaceTextRange([spaceEndRange - preSpace.length, spaceEndRange], "");
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
const RULE_NAME = "space-in-empty-block";
|
|
243
|
+
const spaceInEmptyBlock = createEslintRule({
|
|
244
|
+
name: RULE_NAME,
|
|
245
|
+
meta: {
|
|
246
|
+
type: "suggestion",
|
|
247
|
+
docs: {
|
|
248
|
+
description: "Spaces in empty block",
|
|
249
|
+
recommended: "error"
|
|
250
|
+
},
|
|
251
|
+
fixable: "code",
|
|
252
|
+
schema: [],
|
|
253
|
+
messages: {
|
|
254
|
+
spaceInEmptyBlockMismatch: "Space in empty block mismatch"
|
|
255
|
+
}
|
|
256
|
+
},
|
|
257
|
+
defaultOptions: [],
|
|
258
|
+
create: (context) => {
|
|
259
|
+
const sourceCode = context.getSourceCode();
|
|
260
|
+
return {
|
|
261
|
+
BlockStatement: (node) => {
|
|
262
|
+
if (node.body.length) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
const spaceStartRange = node.range[1] - 2;
|
|
266
|
+
const post = sourceCode.text.slice(spaceStartRange);
|
|
267
|
+
const postSpace = post.match(/^(\s*)/)?.[0];
|
|
268
|
+
if (postSpace && postSpace.length) {
|
|
269
|
+
context.report({
|
|
270
|
+
loc: {
|
|
271
|
+
start: {
|
|
272
|
+
line: node.loc.end.line,
|
|
273
|
+
column: node.loc.end.column - 2
|
|
274
|
+
},
|
|
275
|
+
end: {
|
|
276
|
+
line: node.loc.end.line,
|
|
277
|
+
column: node.loc.end.column - 2 + postSpace.length
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
messageId: "spaceInEmptyBlockMismatch",
|
|
281
|
+
*fix(fixer) {
|
|
282
|
+
yield fixer.replaceTextRange([spaceStartRange, spaceStartRange + postSpace.length], "");
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
const spaceEndRange = node.range[0] + 1;
|
|
287
|
+
const pre = sourceCode.text.slice(0, spaceEndRange);
|
|
288
|
+
const preSpace = pre.match(/(\s+)$/)?.[0];
|
|
289
|
+
if (preSpace && preSpace.length) {
|
|
290
|
+
context.report({
|
|
291
|
+
loc: {
|
|
292
|
+
start: {
|
|
293
|
+
line: node.loc.start.line,
|
|
294
|
+
column: node.loc.start.column - preSpace.length
|
|
295
|
+
},
|
|
296
|
+
end: {
|
|
297
|
+
line: node.loc.start.line,
|
|
298
|
+
column: node.loc.start.column
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
messageId: "spaceInEmptyBlockMismatch",
|
|
302
|
+
*fix(fixer) {
|
|
303
|
+
yield fixer.replaceTextRange([spaceEndRange - preSpace.length, spaceEndRange], "");
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
|
|
148
312
|
const index = {
|
|
149
313
|
rules: {
|
|
150
314
|
"import-dedupe": importDedupe,
|
|
151
|
-
"generic-spacing": genericSpacing
|
|
315
|
+
"generic-spacing": genericSpacing,
|
|
316
|
+
"space-between-generic-and-paren": spaceBetweenGenericAndParen,
|
|
317
|
+
"space-in-empty-block": spaceInEmptyBlock
|
|
152
318
|
}
|
|
153
319
|
};
|
|
154
320
|
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ 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>;
|
|
7
9
|
};
|
|
8
10
|
};
|
|
9
11
|
|
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$3 = "generic-spacing";
|
|
6
6
|
const genericSpacing = createEslintRule({
|
|
7
|
-
name: RULE_NAME$
|
|
7
|
+
name: RULE_NAME$3,
|
|
8
8
|
meta: {
|
|
9
9
|
type: "suggestion",
|
|
10
10
|
docs: {
|
|
@@ -22,6 +22,32 @@ 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 post = sourceCode.text.slice(param.range[1]);
|
|
31
|
+
const postSpace = post.match(/^(\s*)/)?.[0];
|
|
32
|
+
if (preSpace && preSpace.length) {
|
|
33
|
+
context.report({
|
|
34
|
+
node,
|
|
35
|
+
messageId: "genericSpacingMismatch",
|
|
36
|
+
*fix(fixer) {
|
|
37
|
+
yield fixer.replaceTextRange([param.range[0] - preSpace.length, param.range[0]], "");
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if (postSpace && postSpace.length) {
|
|
42
|
+
context.report({
|
|
43
|
+
node,
|
|
44
|
+
messageId: "genericSpacingMismatch",
|
|
45
|
+
*fix(fixer) {
|
|
46
|
+
yield fixer.replaceTextRange([param.range[1], param.range[1] + postSpace.length], "");
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
25
51
|
if (!["TSCallSignatureDeclaration", "ArrowFunctionExpression"].includes(node.parent.type)) {
|
|
26
52
|
const pre = sourceCode.text.slice(0, node.range[0]);
|
|
27
53
|
const preSpace = pre.match(/(\s+)$/)?.[0];
|
|
@@ -46,7 +72,6 @@ const genericSpacing = createEslintRule({
|
|
|
46
72
|
});
|
|
47
73
|
}
|
|
48
74
|
}
|
|
49
|
-
const params = node.params;
|
|
50
75
|
for (let i = 1; i < params.length; i++) {
|
|
51
76
|
const prev = params[i - 1];
|
|
52
77
|
const current = params[i];
|
|
@@ -93,9 +118,9 @@ const genericSpacing = createEslintRule({
|
|
|
93
118
|
}
|
|
94
119
|
});
|
|
95
120
|
|
|
96
|
-
const RULE_NAME = "import-dedupe";
|
|
121
|
+
const RULE_NAME$2 = "import-dedupe";
|
|
97
122
|
const importDedupe = createEslintRule({
|
|
98
|
-
name: RULE_NAME,
|
|
123
|
+
name: RULE_NAME$2,
|
|
99
124
|
meta: {
|
|
100
125
|
type: "problem",
|
|
101
126
|
docs: {
|
|
@@ -143,10 +168,151 @@ const importDedupe = createEslintRule({
|
|
|
143
168
|
}
|
|
144
169
|
});
|
|
145
170
|
|
|
171
|
+
const RULE_NAME$1 = "space-between-generic-and-paren";
|
|
172
|
+
const spaceBetweenGenericAndParen = createEslintRule({
|
|
173
|
+
name: RULE_NAME$1,
|
|
174
|
+
meta: {
|
|
175
|
+
type: "suggestion",
|
|
176
|
+
docs: {
|
|
177
|
+
description: "Spaces between generic type parameters and paren",
|
|
178
|
+
recommended: "error"
|
|
179
|
+
},
|
|
180
|
+
fixable: "code",
|
|
181
|
+
schema: [],
|
|
182
|
+
messages: {
|
|
183
|
+
spaceBetweenGenericAndParenMismatch: "Space between generic and paren mismatch"
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
defaultOptions: [],
|
|
187
|
+
create: (context) => {
|
|
188
|
+
const sourceCode = context.getSourceCode();
|
|
189
|
+
return {
|
|
190
|
+
TSTypeParameter: (node) => {
|
|
191
|
+
const spaceStartRange = node.range[1] + 1;
|
|
192
|
+
const post = sourceCode.text.slice(spaceStartRange);
|
|
193
|
+
const postSpace = post.match(/^(\s*)/)?.[0];
|
|
194
|
+
if (postSpace && postSpace.length) {
|
|
195
|
+
context.report({
|
|
196
|
+
loc: {
|
|
197
|
+
start: {
|
|
198
|
+
line: node.loc.end.line,
|
|
199
|
+
column: node.loc.end.column + 1
|
|
200
|
+
},
|
|
201
|
+
end: {
|
|
202
|
+
line: node.loc.end.line,
|
|
203
|
+
column: node.loc.end.column + 1 + postSpace.length
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
messageId: "spaceBetweenGenericAndParenMismatch",
|
|
207
|
+
*fix(fixer) {
|
|
208
|
+
yield fixer.replaceTextRange([spaceStartRange, spaceStartRange + postSpace.length], "");
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
if (node.parent?.parent.type === "FunctionDeclaration") {
|
|
213
|
+
const spaceEndRange = node.range[0] - 1;
|
|
214
|
+
const pre = sourceCode.text.slice(0, spaceEndRange);
|
|
215
|
+
const preSpace = pre.match(/(\s+)$/)?.[0];
|
|
216
|
+
if (preSpace && preSpace.length) {
|
|
217
|
+
context.report({
|
|
218
|
+
loc: {
|
|
219
|
+
start: {
|
|
220
|
+
line: node.loc.start.line,
|
|
221
|
+
column: node.loc.start.column - preSpace.length
|
|
222
|
+
},
|
|
223
|
+
end: {
|
|
224
|
+
line: node.loc.start.line,
|
|
225
|
+
column: node.loc.start.column - 1
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
messageId: "spaceBetweenGenericAndParenMismatch",
|
|
229
|
+
*fix(fixer) {
|
|
230
|
+
yield fixer.replaceTextRange([spaceEndRange - preSpace.length, spaceEndRange], "");
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
const RULE_NAME = "space-in-empty-block";
|
|
241
|
+
const spaceInEmptyBlock = createEslintRule({
|
|
242
|
+
name: RULE_NAME,
|
|
243
|
+
meta: {
|
|
244
|
+
type: "suggestion",
|
|
245
|
+
docs: {
|
|
246
|
+
description: "Spaces in empty block",
|
|
247
|
+
recommended: "error"
|
|
248
|
+
},
|
|
249
|
+
fixable: "code",
|
|
250
|
+
schema: [],
|
|
251
|
+
messages: {
|
|
252
|
+
spaceInEmptyBlockMismatch: "Space in empty block mismatch"
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
defaultOptions: [],
|
|
256
|
+
create: (context) => {
|
|
257
|
+
const sourceCode = context.getSourceCode();
|
|
258
|
+
return {
|
|
259
|
+
BlockStatement: (node) => {
|
|
260
|
+
if (node.body.length) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
const spaceStartRange = node.range[1] - 2;
|
|
264
|
+
const post = sourceCode.text.slice(spaceStartRange);
|
|
265
|
+
const postSpace = post.match(/^(\s*)/)?.[0];
|
|
266
|
+
if (postSpace && postSpace.length) {
|
|
267
|
+
context.report({
|
|
268
|
+
loc: {
|
|
269
|
+
start: {
|
|
270
|
+
line: node.loc.end.line,
|
|
271
|
+
column: node.loc.end.column - 2
|
|
272
|
+
},
|
|
273
|
+
end: {
|
|
274
|
+
line: node.loc.end.line,
|
|
275
|
+
column: node.loc.end.column - 2 + postSpace.length
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
messageId: "spaceInEmptyBlockMismatch",
|
|
279
|
+
*fix(fixer) {
|
|
280
|
+
yield fixer.replaceTextRange([spaceStartRange, spaceStartRange + postSpace.length], "");
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
const spaceEndRange = node.range[0] + 1;
|
|
285
|
+
const pre = sourceCode.text.slice(0, spaceEndRange);
|
|
286
|
+
const preSpace = pre.match(/(\s+)$/)?.[0];
|
|
287
|
+
if (preSpace && preSpace.length) {
|
|
288
|
+
context.report({
|
|
289
|
+
loc: {
|
|
290
|
+
start: {
|
|
291
|
+
line: node.loc.start.line,
|
|
292
|
+
column: node.loc.start.column - preSpace.length
|
|
293
|
+
},
|
|
294
|
+
end: {
|
|
295
|
+
line: node.loc.start.line,
|
|
296
|
+
column: node.loc.start.column
|
|
297
|
+
}
|
|
298
|
+
},
|
|
299
|
+
messageId: "spaceInEmptyBlockMismatch",
|
|
300
|
+
*fix(fixer) {
|
|
301
|
+
yield fixer.replaceTextRange([spaceEndRange - preSpace.length, spaceEndRange], "");
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
|
|
146
310
|
const index = {
|
|
147
311
|
rules: {
|
|
148
312
|
"import-dedupe": importDedupe,
|
|
149
|
-
"generic-spacing": genericSpacing
|
|
313
|
+
"generic-spacing": genericSpacing,
|
|
314
|
+
"space-between-generic-and-paren": spaceBetweenGenericAndParen,
|
|
315
|
+
"space-in-empty-block": spaceInEmptyBlock
|
|
150
316
|
}
|
|
151
317
|
};
|
|
152
318
|
|