@so1ve/eslint-plugin 0.36.1 → 0.37.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 +82 -4
- package/dist/index.mjs +82 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -37,12 +37,12 @@ const genericSpacing = createEslintRule({
|
|
|
37
37
|
node,
|
|
38
38
|
loc: {
|
|
39
39
|
start: {
|
|
40
|
-
line: param.loc.
|
|
41
|
-
column: param.loc.
|
|
40
|
+
line: param.loc.start.line,
|
|
41
|
+
column: param.loc.start.column + 1 - preSpace.length
|
|
42
42
|
},
|
|
43
43
|
end: {
|
|
44
|
-
line: param.loc.
|
|
45
|
-
column: param.loc.
|
|
44
|
+
line: param.loc.start.line,
|
|
45
|
+
column: param.loc.start.column - 1
|
|
46
46
|
}
|
|
47
47
|
},
|
|
48
48
|
messageId: "genericSpacingMismatch",
|
|
@@ -165,6 +165,84 @@ const genericSpacing = createEslintRule({
|
|
|
165
165
|
});
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
|
+
},
|
|
169
|
+
TSTypeParameterInstantiation: (node) => {
|
|
170
|
+
const params = node.params;
|
|
171
|
+
for (let i = 0; i < params.length; i++) {
|
|
172
|
+
const param = params[i];
|
|
173
|
+
const pre = sourceCode.text.slice(0, param.range[0]);
|
|
174
|
+
const preSpace = pre.match(/(\s+)$/)?.[0];
|
|
175
|
+
const preComma = pre.match(/(,)\s+$/)?.[0];
|
|
176
|
+
const post = sourceCode.text.slice(param.range[1]);
|
|
177
|
+
const postSpace = post.match(/^(\s*)/)?.[0];
|
|
178
|
+
if (preSpace && preSpace.length && !preComma) {
|
|
179
|
+
context.report({
|
|
180
|
+
node,
|
|
181
|
+
loc: {
|
|
182
|
+
start: {
|
|
183
|
+
line: param.loc.start.line,
|
|
184
|
+
column: param.loc.start.column + 1 - preSpace.length
|
|
185
|
+
},
|
|
186
|
+
end: {
|
|
187
|
+
line: param.loc.start.line,
|
|
188
|
+
column: param.loc.start.column - 1
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
messageId: "genericSpacingMismatch",
|
|
192
|
+
*fix(fixer) {
|
|
193
|
+
yield fixer.replaceTextRange([param.range[0] - preSpace.length, param.range[0]], "");
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
if (postSpace && postSpace.length) {
|
|
198
|
+
context.report({
|
|
199
|
+
loc: {
|
|
200
|
+
start: {
|
|
201
|
+
line: param.loc.end.line,
|
|
202
|
+
column: param.loc.end.column
|
|
203
|
+
},
|
|
204
|
+
end: {
|
|
205
|
+
line: param.loc.end.line,
|
|
206
|
+
column: param.loc.end.column + postSpace.length
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
node,
|
|
210
|
+
messageId: "genericSpacingMismatch",
|
|
211
|
+
*fix(fixer) {
|
|
212
|
+
yield fixer.replaceTextRange([param.range[1], param.range[1] + postSpace.length], "");
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
TSInterfaceDeclaration: (node) => {
|
|
219
|
+
if (!node.extends || !node.typeParameters) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
const text = sourceCode.getText();
|
|
223
|
+
const { typeParameters } = node;
|
|
224
|
+
const extendsKeywordStart = typeParameters.range[1];
|
|
225
|
+
const extendsKeywordEnd = node.extends[0].range[0];
|
|
226
|
+
const extendsText = text.slice(extendsKeywordStart, extendsKeywordEnd);
|
|
227
|
+
if (!/^\s+/.test(extendsText)) {
|
|
228
|
+
context.report({
|
|
229
|
+
loc: {
|
|
230
|
+
start: {
|
|
231
|
+
line: typeParameters.loc.end.line,
|
|
232
|
+
column: typeParameters.loc.end.column
|
|
233
|
+
},
|
|
234
|
+
end: {
|
|
235
|
+
line: typeParameters.loc.end.line,
|
|
236
|
+
column: typeParameters.loc.end.column + 7
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
node,
|
|
240
|
+
messageId: "genericSpacingMismatch",
|
|
241
|
+
*fix(fixer) {
|
|
242
|
+
yield fixer.replaceTextRange([extendsKeywordStart, extendsKeywordEnd - 8], " ");
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
}
|
|
168
246
|
}
|
|
169
247
|
};
|
|
170
248
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -35,12 +35,12 @@ const genericSpacing = createEslintRule({
|
|
|
35
35
|
node,
|
|
36
36
|
loc: {
|
|
37
37
|
start: {
|
|
38
|
-
line: param.loc.
|
|
39
|
-
column: param.loc.
|
|
38
|
+
line: param.loc.start.line,
|
|
39
|
+
column: param.loc.start.column + 1 - preSpace.length
|
|
40
40
|
},
|
|
41
41
|
end: {
|
|
42
|
-
line: param.loc.
|
|
43
|
-
column: param.loc.
|
|
42
|
+
line: param.loc.start.line,
|
|
43
|
+
column: param.loc.start.column - 1
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
46
|
messageId: "genericSpacingMismatch",
|
|
@@ -163,6 +163,84 @@ const genericSpacing = createEslintRule({
|
|
|
163
163
|
});
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
+
},
|
|
167
|
+
TSTypeParameterInstantiation: (node) => {
|
|
168
|
+
const params = node.params;
|
|
169
|
+
for (let i = 0; i < params.length; i++) {
|
|
170
|
+
const param = params[i];
|
|
171
|
+
const pre = sourceCode.text.slice(0, param.range[0]);
|
|
172
|
+
const preSpace = pre.match(/(\s+)$/)?.[0];
|
|
173
|
+
const preComma = pre.match(/(,)\s+$/)?.[0];
|
|
174
|
+
const post = sourceCode.text.slice(param.range[1]);
|
|
175
|
+
const postSpace = post.match(/^(\s*)/)?.[0];
|
|
176
|
+
if (preSpace && preSpace.length && !preComma) {
|
|
177
|
+
context.report({
|
|
178
|
+
node,
|
|
179
|
+
loc: {
|
|
180
|
+
start: {
|
|
181
|
+
line: param.loc.start.line,
|
|
182
|
+
column: param.loc.start.column + 1 - preSpace.length
|
|
183
|
+
},
|
|
184
|
+
end: {
|
|
185
|
+
line: param.loc.start.line,
|
|
186
|
+
column: param.loc.start.column - 1
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
messageId: "genericSpacingMismatch",
|
|
190
|
+
*fix(fixer) {
|
|
191
|
+
yield fixer.replaceTextRange([param.range[0] - preSpace.length, param.range[0]], "");
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
if (postSpace && postSpace.length) {
|
|
196
|
+
context.report({
|
|
197
|
+
loc: {
|
|
198
|
+
start: {
|
|
199
|
+
line: param.loc.end.line,
|
|
200
|
+
column: param.loc.end.column
|
|
201
|
+
},
|
|
202
|
+
end: {
|
|
203
|
+
line: param.loc.end.line,
|
|
204
|
+
column: param.loc.end.column + postSpace.length
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
node,
|
|
208
|
+
messageId: "genericSpacingMismatch",
|
|
209
|
+
*fix(fixer) {
|
|
210
|
+
yield fixer.replaceTextRange([param.range[1], param.range[1] + postSpace.length], "");
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
TSInterfaceDeclaration: (node) => {
|
|
217
|
+
if (!node.extends || !node.typeParameters) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
const text = sourceCode.getText();
|
|
221
|
+
const { typeParameters } = node;
|
|
222
|
+
const extendsKeywordStart = typeParameters.range[1];
|
|
223
|
+
const extendsKeywordEnd = node.extends[0].range[0];
|
|
224
|
+
const extendsText = text.slice(extendsKeywordStart, extendsKeywordEnd);
|
|
225
|
+
if (!/^\s+/.test(extendsText)) {
|
|
226
|
+
context.report({
|
|
227
|
+
loc: {
|
|
228
|
+
start: {
|
|
229
|
+
line: typeParameters.loc.end.line,
|
|
230
|
+
column: typeParameters.loc.end.column
|
|
231
|
+
},
|
|
232
|
+
end: {
|
|
233
|
+
line: typeParameters.loc.end.line,
|
|
234
|
+
column: typeParameters.loc.end.column + 7
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
node,
|
|
238
|
+
messageId: "genericSpacingMismatch",
|
|
239
|
+
*fix(fixer) {
|
|
240
|
+
yield fixer.replaceTextRange([extendsKeywordStart, extendsKeywordEnd - 8], " ");
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
}
|
|
166
244
|
}
|
|
167
245
|
};
|
|
168
246
|
}
|