@so1ve/eslint-plugin 0.42.1 → 0.43.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 +35 -14
- package/dist/index.mjs +35 -14
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const utils = require('@typescript-eslint/utils');
|
|
4
|
+
const reactivity = require('@vue/reactivity');
|
|
4
5
|
|
|
5
6
|
const createEslintRule = utils.ESLintUtils.RuleCreator((ruleName) => ruleName);
|
|
6
7
|
|
|
@@ -411,32 +412,43 @@ const noSpacesBeforeParen = createEslintRule({
|
|
|
411
412
|
}
|
|
412
413
|
},
|
|
413
414
|
CallExpression(node) {
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
const
|
|
419
|
-
const
|
|
420
|
-
const
|
|
421
|
-
|
|
422
|
-
|
|
415
|
+
let caller = "property" in node.callee ? node.callee.property : node.callee;
|
|
416
|
+
if (caller.type === "TSInstantiationExpression" && "property" in caller.expression) {
|
|
417
|
+
caller = caller.expression.property;
|
|
418
|
+
}
|
|
419
|
+
const callerEnd = reactivity.ref(caller.range[1]);
|
|
420
|
+
const textAfterCaller = reactivity.computed(() => text.slice(callerEnd.value));
|
|
421
|
+
const parenStart = reactivity.ref(callerEnd.value + textAfterCaller.value.indexOf("("));
|
|
422
|
+
const textBetweenFunctionNameAndParenRange = reactivity.computed(() => [callerEnd.value, parenStart.value]);
|
|
423
|
+
const textBetweenFunctionNameAndParen = reactivity.computed(() => text.slice(...textBetweenFunctionNameAndParenRange.value));
|
|
424
|
+
const hasGenerics = reactivity.computed(() => /^\s*</.test(textBetweenFunctionNameAndParen.value));
|
|
425
|
+
const hasIndex = reactivity.computed(() => textBetweenFunctionNameAndParen.value.startsWith("]"));
|
|
426
|
+
if (hasIndex.value) {
|
|
427
|
+
callerEnd.value += 1;
|
|
428
|
+
}
|
|
429
|
+
if (node.optional) {
|
|
430
|
+
parenStart.value = callerEnd.value + textAfterCaller.value.indexOf("(");
|
|
431
|
+
}
|
|
432
|
+
if (!hasGenerics.value) {
|
|
433
|
+
if (textBetweenFunctionNameAndParen.value.length > 0 && textBetweenFunctionNameAndParen.value !== "?.") {
|
|
423
434
|
context.report({
|
|
424
435
|
node,
|
|
425
436
|
messageId: "noSpacesBeforeParen",
|
|
426
437
|
*fix(fixer) {
|
|
427
|
-
yield fixer.
|
|
438
|
+
yield fixer.replaceTextRange(textBetweenFunctionNameAndParenRange.value, node.optional ? "?." : "");
|
|
428
439
|
}
|
|
429
440
|
});
|
|
430
441
|
}
|
|
431
442
|
} else {
|
|
432
|
-
const preSpaces = /^(\s*)/.exec(textBetweenFunctionNameAndParen)[1];
|
|
433
|
-
const postSpaces = /(\s*)$/.exec(textBetweenFunctionNameAndParen)[1];
|
|
443
|
+
const preSpaces = /^(\s*)/.exec(textBetweenFunctionNameAndParen.value)[1];
|
|
444
|
+
const postSpaces = /(\s*)$/.exec(textBetweenFunctionNameAndParen.value)[1];
|
|
445
|
+
const spacesBeforeOptionalMark = /(\s*)\?\./.exec(textBetweenFunctionNameAndParen.value)?.[1] || "";
|
|
434
446
|
if (preSpaces.length > 0) {
|
|
435
447
|
context.report({
|
|
436
448
|
node,
|
|
437
449
|
messageId: "noSpacesBeforeParen",
|
|
438
450
|
*fix(fixer) {
|
|
439
|
-
yield fixer.removeRange([
|
|
451
|
+
yield fixer.removeRange([callerEnd.value, callerEnd.value + preSpaces.length]);
|
|
440
452
|
}
|
|
441
453
|
});
|
|
442
454
|
}
|
|
@@ -445,7 +457,16 @@ const noSpacesBeforeParen = createEslintRule({
|
|
|
445
457
|
node,
|
|
446
458
|
messageId: "noSpacesBeforeParen",
|
|
447
459
|
*fix(fixer) {
|
|
448
|
-
yield fixer.removeRange([parenStart - postSpaces.length, parenStart]);
|
|
460
|
+
yield fixer.removeRange([parenStart.value - postSpaces.length, parenStart.value]);
|
|
461
|
+
}
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
if (spacesBeforeOptionalMark.length > 0 && !textBetweenFunctionNameAndParen.value.endsWith(" ")) {
|
|
465
|
+
context.report({
|
|
466
|
+
node,
|
|
467
|
+
messageId: "noSpacesBeforeParen",
|
|
468
|
+
*fix(fixer) {
|
|
469
|
+
yield fixer.removeRange([parenStart.value - spacesBeforeOptionalMark.length - 2, parenStart.value - 2]);
|
|
449
470
|
}
|
|
450
471
|
});
|
|
451
472
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
+
import { ref, computed } from '@vue/reactivity';
|
|
2
3
|
|
|
3
4
|
const createEslintRule = ESLintUtils.RuleCreator((ruleName) => ruleName);
|
|
4
5
|
|
|
@@ -409,32 +410,43 @@ const noSpacesBeforeParen = createEslintRule({
|
|
|
409
410
|
}
|
|
410
411
|
},
|
|
411
412
|
CallExpression(node) {
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
const
|
|
417
|
-
const
|
|
418
|
-
const
|
|
419
|
-
|
|
420
|
-
|
|
413
|
+
let caller = "property" in node.callee ? node.callee.property : node.callee;
|
|
414
|
+
if (caller.type === "TSInstantiationExpression" && "property" in caller.expression) {
|
|
415
|
+
caller = caller.expression.property;
|
|
416
|
+
}
|
|
417
|
+
const callerEnd = ref(caller.range[1]);
|
|
418
|
+
const textAfterCaller = computed(() => text.slice(callerEnd.value));
|
|
419
|
+
const parenStart = ref(callerEnd.value + textAfterCaller.value.indexOf("("));
|
|
420
|
+
const textBetweenFunctionNameAndParenRange = computed(() => [callerEnd.value, parenStart.value]);
|
|
421
|
+
const textBetweenFunctionNameAndParen = computed(() => text.slice(...textBetweenFunctionNameAndParenRange.value));
|
|
422
|
+
const hasGenerics = computed(() => /^\s*</.test(textBetweenFunctionNameAndParen.value));
|
|
423
|
+
const hasIndex = computed(() => textBetweenFunctionNameAndParen.value.startsWith("]"));
|
|
424
|
+
if (hasIndex.value) {
|
|
425
|
+
callerEnd.value += 1;
|
|
426
|
+
}
|
|
427
|
+
if (node.optional) {
|
|
428
|
+
parenStart.value = callerEnd.value + textAfterCaller.value.indexOf("(");
|
|
429
|
+
}
|
|
430
|
+
if (!hasGenerics.value) {
|
|
431
|
+
if (textBetweenFunctionNameAndParen.value.length > 0 && textBetweenFunctionNameAndParen.value !== "?.") {
|
|
421
432
|
context.report({
|
|
422
433
|
node,
|
|
423
434
|
messageId: "noSpacesBeforeParen",
|
|
424
435
|
*fix(fixer) {
|
|
425
|
-
yield fixer.
|
|
436
|
+
yield fixer.replaceTextRange(textBetweenFunctionNameAndParenRange.value, node.optional ? "?." : "");
|
|
426
437
|
}
|
|
427
438
|
});
|
|
428
439
|
}
|
|
429
440
|
} else {
|
|
430
|
-
const preSpaces = /^(\s*)/.exec(textBetweenFunctionNameAndParen)[1];
|
|
431
|
-
const postSpaces = /(\s*)$/.exec(textBetweenFunctionNameAndParen)[1];
|
|
441
|
+
const preSpaces = /^(\s*)/.exec(textBetweenFunctionNameAndParen.value)[1];
|
|
442
|
+
const postSpaces = /(\s*)$/.exec(textBetweenFunctionNameAndParen.value)[1];
|
|
443
|
+
const spacesBeforeOptionalMark = /(\s*)\?\./.exec(textBetweenFunctionNameAndParen.value)?.[1] || "";
|
|
432
444
|
if (preSpaces.length > 0) {
|
|
433
445
|
context.report({
|
|
434
446
|
node,
|
|
435
447
|
messageId: "noSpacesBeforeParen",
|
|
436
448
|
*fix(fixer) {
|
|
437
|
-
yield fixer.removeRange([
|
|
449
|
+
yield fixer.removeRange([callerEnd.value, callerEnd.value + preSpaces.length]);
|
|
438
450
|
}
|
|
439
451
|
});
|
|
440
452
|
}
|
|
@@ -443,7 +455,16 @@ const noSpacesBeforeParen = createEslintRule({
|
|
|
443
455
|
node,
|
|
444
456
|
messageId: "noSpacesBeforeParen",
|
|
445
457
|
*fix(fixer) {
|
|
446
|
-
yield fixer.removeRange([parenStart - postSpaces.length, parenStart]);
|
|
458
|
+
yield fixer.removeRange([parenStart.value - postSpaces.length, parenStart.value]);
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
if (spacesBeforeOptionalMark.length > 0 && !textBetweenFunctionNameAndParen.value.endsWith(" ")) {
|
|
463
|
+
context.report({
|
|
464
|
+
node,
|
|
465
|
+
messageId: "noSpacesBeforeParen",
|
|
466
|
+
*fix(fixer) {
|
|
467
|
+
yield fixer.removeRange([parenStart.value - spacesBeforeOptionalMark.length - 2, parenStart.value - 2]);
|
|
447
468
|
}
|
|
448
469
|
});
|
|
449
470
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@so1ve/eslint-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.43.0",
|
|
4
4
|
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
|
5
5
|
"contributors": [
|
|
6
6
|
{
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@typescript-eslint/utils": "^5.48.0",
|
|
35
|
+
"@vue/reactivity": "^3.2.45",
|
|
35
36
|
"eslint-define-config": "^1.13.0"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|