@so1ve/eslint-plugin 0.42.2 → 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 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,31 +412,43 @@ const noSpacesBeforeParen = createEslintRule({
411
412
  }
412
413
  },
413
414
  CallExpression(node) {
414
- const caller = "property" in node.callee ? node.callee.property : node.callee;
415
- const textAfterCaller = text.slice(caller.range[1]);
416
- const parenStart = caller.range[1] + textAfterCaller.indexOf("(");
417
- const textBetweenFunctionNameAndParenRange = [caller.range[1], parenStart];
418
- const textBetweenFunctionNameAndParen = text.slice(...textBetweenFunctionNameAndParenRange);
419
- const hasGenerics = textBetweenFunctionNameAndParen.includes("<");
420
- if (!hasGenerics) {
421
- if (textBetweenFunctionNameAndParen.length > 0) {
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 !== "?.") {
422
434
  context.report({
423
435
  node,
424
436
  messageId: "noSpacesBeforeParen",
425
437
  *fix(fixer) {
426
- yield fixer.removeRange(textBetweenFunctionNameAndParenRange);
438
+ yield fixer.replaceTextRange(textBetweenFunctionNameAndParenRange.value, node.optional ? "?." : "");
427
439
  }
428
440
  });
429
441
  }
430
442
  } else {
431
- const preSpaces = /^(\s*)/.exec(textBetweenFunctionNameAndParen)[1];
432
- 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] || "";
433
446
  if (preSpaces.length > 0) {
434
447
  context.report({
435
448
  node,
436
449
  messageId: "noSpacesBeforeParen",
437
450
  *fix(fixer) {
438
- yield fixer.removeRange([caller.range[1], caller.range[1] + preSpaces.length]);
451
+ yield fixer.removeRange([callerEnd.value, callerEnd.value + preSpaces.length]);
439
452
  }
440
453
  });
441
454
  }
@@ -444,7 +457,16 @@ const noSpacesBeforeParen = createEslintRule({
444
457
  node,
445
458
  messageId: "noSpacesBeforeParen",
446
459
  *fix(fixer) {
447
- 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]);
448
470
  }
449
471
  });
450
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,31 +410,43 @@ const noSpacesBeforeParen = createEslintRule({
409
410
  }
410
411
  },
411
412
  CallExpression(node) {
412
- const caller = "property" in node.callee ? node.callee.property : node.callee;
413
- const textAfterCaller = text.slice(caller.range[1]);
414
- const parenStart = caller.range[1] + textAfterCaller.indexOf("(");
415
- const textBetweenFunctionNameAndParenRange = [caller.range[1], parenStart];
416
- const textBetweenFunctionNameAndParen = text.slice(...textBetweenFunctionNameAndParenRange);
417
- const hasGenerics = textBetweenFunctionNameAndParen.includes("<");
418
- if (!hasGenerics) {
419
- if (textBetweenFunctionNameAndParen.length > 0) {
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 !== "?.") {
420
432
  context.report({
421
433
  node,
422
434
  messageId: "noSpacesBeforeParen",
423
435
  *fix(fixer) {
424
- yield fixer.removeRange(textBetweenFunctionNameAndParenRange);
436
+ yield fixer.replaceTextRange(textBetweenFunctionNameAndParenRange.value, node.optional ? "?." : "");
425
437
  }
426
438
  });
427
439
  }
428
440
  } else {
429
- const preSpaces = /^(\s*)/.exec(textBetweenFunctionNameAndParen)[1];
430
- 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] || "";
431
444
  if (preSpaces.length > 0) {
432
445
  context.report({
433
446
  node,
434
447
  messageId: "noSpacesBeforeParen",
435
448
  *fix(fixer) {
436
- yield fixer.removeRange([caller.range[1], caller.range[1] + preSpaces.length]);
449
+ yield fixer.removeRange([callerEnd.value, callerEnd.value + preSpaces.length]);
437
450
  }
438
451
  });
439
452
  }
@@ -442,7 +455,16 @@ const noSpacesBeforeParen = createEslintRule({
442
455
  node,
443
456
  messageId: "noSpacesBeforeParen",
444
457
  *fix(fixer) {
445
- 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]);
446
468
  }
447
469
  });
448
470
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@so1ve/eslint-plugin",
3
- "version": "0.42.2",
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": {