@kikiutils/eslint-config 11.5.0 → 12.0.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.
Files changed (112) hide show
  1. package/README.md +41 -23
  2. package/dist/_internals/configs/base-rules.d.ts.map +1 -1
  3. package/dist/_internals/configs/base-rules.js +38 -37
  4. package/dist/_internals/configs/base-rules.js.map +1 -1
  5. package/dist/_internals/configs/jsdoc.d.ts +0 -36
  6. package/dist/_internals/configs/jsdoc.d.ts.map +1 -1
  7. package/dist/_internals/configs/jsdoc.js +1 -42
  8. package/dist/_internals/configs/jsdoc.js.map +1 -1
  9. package/dist/_internals/configs/type-aware.d.ts.map +1 -1
  10. package/dist/_internals/configs/type-aware.js +26 -1
  11. package/dist/_internals/configs/type-aware.js.map +1 -1
  12. package/dist/_internals/configs/typescript.d.ts +42 -0
  13. package/dist/_internals/configs/typescript.d.ts.map +1 -0
  14. package/dist/_internals/configs/typescript.js +49 -0
  15. package/dist/_internals/configs/typescript.js.map +1 -0
  16. package/dist/_internals/eslint-plugin-promise.d.ts +7 -0
  17. package/dist/_internals/eslint-plugin-promise.d.ts.map +1 -0
  18. package/dist/_internals/rules/consistent-condition-layout.d.ts.map +1 -1
  19. package/dist/_internals/rules/consistent-condition-layout.js +15 -14
  20. package/dist/_internals/rules/consistent-condition-layout.js.map +1 -1
  21. package/dist/_internals/rules/consistent-parameter-layout.d.ts.map +1 -1
  22. package/dist/_internals/rules/consistent-parameter-layout.js +17 -11
  23. package/dist/_internals/rules/consistent-parameter-layout.js.map +1 -1
  24. package/dist/_internals/rules/index.d.ts +7 -1
  25. package/dist/_internals/rules/index.d.ts.map +1 -1
  26. package/dist/_internals/rules/index.js +11 -2
  27. package/dist/_internals/rules/index.js.map +1 -1
  28. package/dist/_internals/rules/no-composable-in-head-getter.d.ts.map +1 -1
  29. package/dist/_internals/rules/no-composable-in-head-getter.js +97 -19
  30. package/dist/_internals/rules/no-composable-in-head-getter.js.map +1 -1
  31. package/dist/_internals/rules/no-reactive-composable-return.d.ts +3 -0
  32. package/dist/_internals/rules/no-reactive-composable-return.d.ts.map +1 -0
  33. package/dist/_internals/rules/no-reactive-composable-return.js +43 -0
  34. package/dist/_internals/rules/no-reactive-composable-return.js.map +1 -0
  35. package/dist/_internals/rules/no-reactive-destructure.d.ts +3 -0
  36. package/dist/_internals/rules/no-reactive-destructure.d.ts.map +1 -0
  37. package/dist/_internals/rules/no-reactive-destructure.js +44 -0
  38. package/dist/_internals/rules/no-reactive-destructure.js.map +1 -0
  39. package/dist/_internals/rules/no-silent-catch.d.ts.map +1 -1
  40. package/dist/_internals/rules/no-silent-catch.js +3 -2
  41. package/dist/_internals/rules/no-silent-catch.js.map +1 -1
  42. package/dist/_internals/rules/no-thenable-zod-refinement.d.ts.map +1 -1
  43. package/dist/_internals/rules/no-thenable-zod-refinement.js +9 -3
  44. package/dist/_internals/rules/no-thenable-zod-refinement.js.map +1 -1
  45. package/dist/_internals/rules/prefer-enhanced-date.d.ts +3 -0
  46. package/dist/_internals/rules/prefer-enhanced-date.d.ts.map +1 -0
  47. package/dist/_internals/rules/prefer-enhanced-date.js +307 -0
  48. package/dist/_internals/rules/prefer-enhanced-date.js.map +1 -0
  49. package/dist/_internals/rules/promise-function-async.d.ts.map +1 -1
  50. package/dist/_internals/rules/promise-function-async.js.map +1 -1
  51. package/dist/_internals/rules/statement-padding.d.ts.map +1 -1
  52. package/dist/_internals/rules/statement-padding.js +19 -15
  53. package/dist/_internals/rules/statement-padding.js.map +1 -1
  54. package/dist/_internals/rules/utils.d.ts +23 -0
  55. package/dist/_internals/rules/utils.d.ts.map +1 -0
  56. package/dist/_internals/rules/utils.js +17 -0
  57. package/dist/_internals/rules/utils.js.map +1 -0
  58. package/dist/_internals/rules/vue-reactivity.d.ts +3 -0
  59. package/dist/_internals/rules/vue-reactivity.d.ts.map +1 -0
  60. package/dist/_internals/rules/vue-reactivity.js +30 -0
  61. package/dist/_internals/rules/vue-reactivity.js.map +1 -0
  62. package/dist/base.d.ts.map +1 -1
  63. package/dist/base.js +51 -29
  64. package/dist/base.js.map +1 -1
  65. package/dist/nuxt.d.ts +3 -1
  66. package/dist/nuxt.d.ts.map +1 -1
  67. package/dist/nuxt.js +53 -3
  68. package/dist/nuxt.js.map +1 -1
  69. package/dist/style.d.ts.map +1 -1
  70. package/dist/style.js +1 -0
  71. package/dist/style.js.map +1 -1
  72. package/dist/vue.d.ts +1 -1
  73. package/dist/vue.d.ts.map +1 -1
  74. package/dist/vue.js +17 -19
  75. package/dist/vue.js.map +1 -1
  76. package/package.json +6 -5
  77. package/src/_internals/configs/base-rules.ts +30 -44
  78. package/src/_internals/configs/jsdoc.ts +0 -51
  79. package/src/_internals/configs/type-aware.ts +29 -1
  80. package/src/_internals/configs/typescript.ts +62 -0
  81. package/src/_internals/eslint-plugin-promise.d.ts +6 -0
  82. package/src/_internals/rules/consistent-condition-layout.ts +20 -23
  83. package/src/_internals/rules/consistent-parameter-layout.ts +30 -34
  84. package/src/_internals/rules/index.ts +10 -1
  85. package/src/_internals/rules/no-composable-in-head-getter.ts +132 -26
  86. package/src/_internals/rules/no-reactive-composable-return.ts +55 -0
  87. package/src/_internals/rules/no-reactive-destructure.ts +64 -0
  88. package/src/_internals/rules/no-silent-catch.ts +4 -10
  89. package/src/_internals/rules/no-thenable-zod-refinement.ts +14 -9
  90. package/src/_internals/rules/prefer-enhanced-date.ts +448 -0
  91. package/src/_internals/rules/promise-function-async.ts +2 -6
  92. package/src/_internals/rules/statement-padding.ts +23 -24
  93. package/src/_internals/{utils.ts → rules/utils.ts} +31 -0
  94. package/src/_internals/rules/vue-reactivity.ts +42 -0
  95. package/src/base.ts +51 -47
  96. package/src/nuxt.ts +90 -5
  97. package/src/style.ts +1 -0
  98. package/src/vue.ts +24 -26
  99. package/dist/_internals/configs/restricted-syntax.d.ts +0 -5
  100. package/dist/_internals/configs/restricted-syntax.d.ts.map +0 -1
  101. package/dist/_internals/configs/restricted-syntax.js +0 -12
  102. package/dist/_internals/configs/restricted-syntax.js.map +0 -1
  103. package/dist/_internals/configs/typefest.d.ts +0 -3
  104. package/dist/_internals/configs/typefest.d.ts.map +0 -1
  105. package/dist/_internals/configs/typefest.js +0 -21
  106. package/dist/_internals/configs/typefest.js.map +0 -1
  107. package/dist/_internals/utils.d.ts +0 -4
  108. package/dist/_internals/utils.d.ts.map +0 -1
  109. package/dist/_internals/utils.js +0 -10
  110. package/dist/_internals/utils.js.map +0 -1
  111. package/src/_internals/configs/restricted-syntax.ts +0 -8
  112. package/src/_internals/configs/typefest.ts +0 -19
@@ -1,5 +1,17 @@
1
- import { defineScriptAndTemplateVisitors } from "../utils.js";
1
+ import { defineScriptAndTemplateVisitors, insertNewlines } from "./utils.js";
2
2
  // src/_internals/rules/consistent-condition-layout.ts
3
+ const comparisonOperators = /* @__PURE__ */ new Set([
4
+ "!=",
5
+ "!==",
6
+ "<",
7
+ "<=",
8
+ "==",
9
+ "===",
10
+ ">",
11
+ ">=",
12
+ "in",
13
+ "instanceof"
14
+ ]);
3
15
  const consistentConditionLayout = {
4
16
  create(context) {
5
17
  function createVisitor(tokenStore) {
@@ -39,25 +51,14 @@ const consistentConditionLayout = {
39
51
  operators = [];
40
52
  }
41
53
  if (newlineOffsets.length) context.report({
42
- fix: (fixer) => newlineOffsets.map((offset) => fixer.insertTextBeforeRange([offset, offset], "\n")),
54
+ fix: insertNewlines(newlineOffsets),
43
55
  messageId: "newline",
44
56
  node
45
57
  });
46
58
  }
47
59
  return {
48
60
  BinaryExpression: (node) => {
49
- if ([
50
- "!=",
51
- "!==",
52
- "<",
53
- "<=",
54
- "==",
55
- "===",
56
- ">",
57
- ">=",
58
- "in",
59
- "instanceof"
60
- ].includes(node.operator)) checkParentheses(node);
61
+ if (comparisonOperators.has(node.operator)) checkParentheses(node);
61
62
  },
62
63
  DoWhileStatement: (node) => checkParentheses(node.test),
63
64
  IfStatement: (node) => checkParentheses(node.test),
@@ -1 +1 @@
1
- {"version":3,"file":"consistent-condition-layout.js","names":[],"sources":["../../../src/_internals/rules/consistent-condition-layout.ts"],"sourcesContent":["import type {\n AST,\n Rule,\n} from 'eslint';\n\nimport type { TokenStore } from '../utils';\nimport { defineScriptAndTemplateVisitors } from '../utils';\n\ntype LogicalNode = Extract<Rule.Node, { type: 'LogicalExpression' }>;\n\nexport const consistentConditionLayout: Rule.RuleModule = {\n create(context) {\n function createVisitor(tokenStore: TokenStore): Rule.RuleListener {\n const checkedOpeningOffsets = new Set<number>();\n\n function collectOperators(node: LogicalNode['left'], operators: AST.Token[]): void {\n if (node.type !== 'LogicalExpression' || (node.operator !== '&&' && node.operator !== '||')) return;\n const operator = tokenStore.getTokensBetween(node.left, node.right)\n .find((token) => token.type === 'Punctuator' && token.value === node.operator)!;\n\n function collectChild(child: LogicalNode['left']): void {\n const before = tokenStore.getTokenBefore(child);\n const after = tokenStore.getTokenAfter(child);\n if (\n before?.value === '('\n && after?.value === ')'\n && before.range[0] >= node.range![0]\n && after.range[1] <= node.range![1]\n ) return;\n\n collectOperators(child, operators);\n }\n\n collectChild(node.left);\n operators.push(operator);\n collectChild(node.right);\n }\n\n function checkParentheses(node: LogicalNode['left']): void {\n let openingParen = tokenStore.getTokenBefore(node);\n let closingParen = tokenStore.getTokenAfter(node);\n let operators: AST.Token[] | undefined;\n const newlineOffsets: number[] = [];\n while (openingParen?.value === '(' && closingParen?.value === ')') {\n if (\n !checkedOpeningOffsets.has(openingParen.range[0])\n && openingParen.loc.start.line !== closingParen.loc.end.line\n ) {\n checkedOpeningOffsets.add(openingParen.range[0]);\n if (!operators) {\n operators = [];\n collectOperators(node, operators);\n }\n\n const next = tokenStore.getTokenAfter(openingParen)!;\n if (openingParen.loc.end.line === next.loc.start.line) {\n newlineOffsets.push(openingParen.range[1]);\n }\n\n for (const operator of operators) {\n if (tokenStore.getTokenBefore(operator)!.loc.end.line === operator.loc.start.line) {\n newlineOffsets.push(operator.range[0]);\n }\n }\n\n if (tokenStore.getTokenBefore(closingParen)!.loc.end.line === closingParen.loc.start.line) {\n newlineOffsets.push(closingParen.range[0]);\n }\n }\n\n openingParen = tokenStore.getTokenBefore(openingParen);\n closingParen = tokenStore.getTokenAfter(closingParen);\n // An outer pair contains one grouped item, not the inner logical chain.\n operators = [];\n }\n\n if (newlineOffsets.length) {\n context.report({\n fix: (fixer) => newlineOffsets.map((offset) => fixer.insertTextBeforeRange(\n [\n offset,\n offset,\n ],\n '\\n',\n )),\n messageId: 'newline',\n node,\n });\n }\n }\n\n return {\n BinaryExpression: (node) => {\n if (\n [\n '!=',\n '!==',\n '<',\n '<=',\n '==',\n '===',\n '>',\n '>=',\n 'in',\n 'instanceof',\n ].includes(node.operator)\n ) checkParentheses(node);\n },\n DoWhileStatement: (node) => checkParentheses(node.test),\n IfStatement: (node) => checkParentheses(node.test),\n LogicalExpression: (node) => {\n if (node.operator === '&&' || node.operator === '||') checkParentheses(node);\n },\n UnaryExpression: (node) => {\n if (node.operator === '!') checkParentheses(node);\n },\n WhileStatement: (node) => checkParentheses(node.test),\n };\n }\n\n return defineScriptAndTemplateVisitors(context.sourceCode, createVisitor);\n },\n meta: {\n docs: { description: 'Expand multiline parenthesized conditions one logical item per line.' },\n fixable: 'whitespace',\n messages: { newline: 'Put each logical item and both parentheses on separate lines in a multiline condition.' },\n schema: [],\n type: 'layout',\n },\n};\n"],"mappings":";;AAUA,MAAa,4BAA6C;CACtD,OAAO,SAAS;EACZ,SAAS,cAAc,YAA2C;GAC9D,MAAM,wCAAwB,IAAI,IAAY;GAE9C,SAAS,iBAAiB,MAA2B,WAA8B;IAC/E,IAAI,KAAK,SAAS,uBAAwB,KAAK,aAAa,QAAQ,KAAK,aAAa,MAAO;IAC7F,MAAM,WAAW,WAAW,iBAAiB,KAAK,MAAM,KAAK,KAAK,CAAC,CAC9D,MAAM,UAAU,MAAM,SAAS,gBAAgB,MAAM,UAAU,KAAK,QAAQ;IAEjF,SAAS,aAAa,OAAkC;KACpD,MAAM,SAAS,WAAW,eAAe,KAAK;KAC9C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,CACI,QACA,MACJ,GACA,IACJ,CAAC;KACD,WAAW;KACX;IACJ,CAAC;GAET;GAEA,OAAO;IACH,mBAAmB,SAAS;KACxB,IACI;MACI;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;KACJ,CAAC,CAAC,SAAS,KAAK,QAAQ,GAC1B,iBAAiB,IAAI;IAC3B;IACA,mBAAmB,SAAS,iBAAiB,KAAK,IAAI;IACtD,cAAc,SAAS,iBAAiB,KAAK,IAAI;IACjD,oBAAoB,SAAS;KACzB,IAAI,KAAK,aAAa,QAAQ,KAAK,aAAa,MAAM,iBAAiB,IAAI;IAC/E;IACA,kBAAkB,SAAS;KACvB,IAAI,KAAK,aAAa,KAAK,iBAAiB,IAAI;IACpD;IACA,iBAAiB,SAAS,iBAAiB,KAAK,IAAI;GACxD;EACJ;EAEA,OAAO,gCAAgC,QAAQ,YAAY,aAAa;CAC5E;CACA,MAAM;EACF,MAAM,EAAE,aAAa,uEAAuE;EAC5F,SAAS;EACT,UAAU,EAAE,SAAS,yFAAyF;EAC9G,QAAQ,CAAC;EACT,MAAM;CACV;AACJ"}
1
+ {"version":3,"file":"consistent-condition-layout.js","names":[],"sources":["../../../src/_internals/rules/consistent-condition-layout.ts"],"sourcesContent":["import type {\n AST,\n Rule,\n} from 'eslint';\n\nimport type { TokenStore } from './utils';\nimport {\n defineScriptAndTemplateVisitors,\n insertNewlines,\n} from './utils';\n\ntype LogicalNode = Extract<Rule.Node, { type: 'LogicalExpression' }>;\n\nconst comparisonOperators = new Set([\n '!=',\n '!==',\n '<',\n '<=',\n '==',\n '===',\n '>',\n '>=',\n 'in',\n 'instanceof',\n]);\n\nexport const consistentConditionLayout: Rule.RuleModule = {\n create(context) {\n function createVisitor(tokenStore: TokenStore): Rule.RuleListener {\n const checkedOpeningOffsets = new Set<number>();\n\n function collectOperators(node: LogicalNode['left'], operators: AST.Token[]): void {\n if (node.type !== 'LogicalExpression' || (node.operator !== '&&' && node.operator !== '||')) return;\n const operator = tokenStore.getTokensBetween(node.left, node.right)\n .find((token) => token.type === 'Punctuator' && token.value === node.operator)!;\n\n function collectChild(child: LogicalNode['left']): void {\n const before = tokenStore.getTokenBefore(child);\n const after = tokenStore.getTokenAfter(child);\n if (\n before?.value === '('\n && after?.value === ')'\n && before.range[0] >= node.range![0]\n && after.range[1] <= node.range![1]\n ) return;\n\n collectOperators(child, operators);\n }\n\n collectChild(node.left);\n operators.push(operator);\n collectChild(node.right);\n }\n\n function checkParentheses(node: LogicalNode['left']): void {\n let openingParen = tokenStore.getTokenBefore(node);\n let closingParen = tokenStore.getTokenAfter(node);\n let operators: AST.Token[] | undefined;\n const newlineOffsets: number[] = [];\n while (openingParen?.value === '(' && closingParen?.value === ')') {\n if (\n !checkedOpeningOffsets.has(openingParen.range[0])\n && openingParen.loc.start.line !== closingParen.loc.end.line\n ) {\n checkedOpeningOffsets.add(openingParen.range[0]);\n if (!operators) {\n operators = [];\n collectOperators(node, operators);\n }\n\n const next = tokenStore.getTokenAfter(openingParen)!;\n if (openingParen.loc.end.line === next.loc.start.line) {\n newlineOffsets.push(openingParen.range[1]);\n }\n\n for (const operator of operators) {\n if (tokenStore.getTokenBefore(operator)!.loc.end.line === operator.loc.start.line) {\n newlineOffsets.push(operator.range[0]);\n }\n }\n\n if (tokenStore.getTokenBefore(closingParen)!.loc.end.line === closingParen.loc.start.line) {\n newlineOffsets.push(closingParen.range[0]);\n }\n }\n\n openingParen = tokenStore.getTokenBefore(openingParen);\n closingParen = tokenStore.getTokenAfter(closingParen);\n // An outer pair contains one grouped item, not the inner logical chain.\n operators = [];\n }\n\n if (newlineOffsets.length) {\n context.report({\n fix: insertNewlines(newlineOffsets),\n messageId: 'newline',\n node,\n });\n }\n }\n\n return {\n BinaryExpression: (node) => {\n if (comparisonOperators.has(node.operator)) checkParentheses(node);\n },\n DoWhileStatement: (node) => checkParentheses(node.test),\n IfStatement: (node) => checkParentheses(node.test),\n LogicalExpression: (node) => {\n if (node.operator === '&&' || node.operator === '||') checkParentheses(node);\n },\n UnaryExpression: (node) => {\n if (node.operator === '!') checkParentheses(node);\n },\n WhileStatement: (node) => checkParentheses(node.test),\n };\n }\n\n return defineScriptAndTemplateVisitors(context.sourceCode, createVisitor);\n },\n meta: {\n docs: { description: 'Expand multiline parenthesized conditions one logical item per line.' },\n fixable: 'whitespace',\n messages: { newline: 'Put each logical item and both parentheses on separate lines in a multiline condition.' },\n schema: [],\n type: 'layout',\n },\n};\n"],"mappings":";;AAaA,MAAM,sCAAsB,IAAI,IAAI;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ,CAAC;AAED,MAAa,4BAA6C;CACtD,OAAO,SAAS;EACZ,SAAS,cAAc,YAA2C;GAC9D,MAAM,wCAAwB,IAAI,IAAY;GAE9C,SAAS,iBAAiB,MAA2B,WAA8B;IAC/E,IAAI,KAAK,SAAS,uBAAwB,KAAK,aAAa,QAAQ,KAAK,aAAa,MAAO;IAC7F,MAAM,WAAW,WAAW,iBAAiB,KAAK,MAAM,KAAK,KAAK,CAAC,CAC9D,MAAM,UAAU,MAAM,SAAS,gBAAgB,MAAM,UAAU,KAAK,QAAQ;IAEjF,SAAS,aAAa,OAAkC;KACpD,MAAM,SAAS,WAAW,eAAe,KAAK;KAC9C,MAAM,QAAQ,WAAW,cAAc,KAAK;KAC5C,IACI,QAAQ,UAAU,OACf,OAAO,UAAU,OACjB,OAAO,MAAM,MAAM,KAAK,MAAO,MAC/B,MAAM,MAAM,MAAM,KAAK,MAAO,IACnC;KAEF,iBAAiB,OAAO,SAAS;IACrC;IAEA,aAAa,KAAK,IAAI;IACtB,UAAU,KAAK,QAAQ;IACvB,aAAa,KAAK,KAAK;GAC3B;GAEA,SAAS,iBAAiB,MAAiC;IACvD,IAAI,eAAe,WAAW,eAAe,IAAI;IACjD,IAAI,eAAe,WAAW,cAAc,IAAI;IAChD,IAAI;IACJ,MAAM,iBAA2B,CAAC;IAClC,OAAO,cAAc,UAAU,OAAO,cAAc,UAA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CACA,MAAM;EACF,MAAM,EAAE,aAAa,uEAAuE;EAC5F,SAAS;EACT,UAAU,EAAE,SAAS,yFAAyF;EAC9G,QAAQ,CAAC;EACT,MAAM;CACV;AACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"consistent-parameter-layout.d.ts","names":[],"sources":["../../../src/_internals/rules/consistent-parameter-layout.ts"],"mappings":";qBAgBa,2BAA2B,KAAK"}
1
+ {"version":3,"file":"consistent-parameter-layout.d.ts","names":[],"sources":["../../../src/_internals/rules/consistent-parameter-layout.ts"],"mappings":";qBA+Ba,2BAA2B,KAAK"}
@@ -1,13 +1,23 @@
1
- import { defineScriptAndTemplateVisitors } from "../utils.js";
1
+ import { defineScriptAndTemplateVisitors, insertNewlines, isMemberNamed } from "./utils.js";
2
2
  // src/_internals/rules/consistent-parameter-layout.ts
3
+ function isTestCall(callee) {
4
+ let target = callee;
5
+ if (target.type === "CallExpression") {
6
+ if (!isMemberNamed(target.callee, "for")) return false;
7
+ target = target.callee.object;
8
+ }
9
+ if (isMemberNamed(target, "concurrent")) target = target.object;
10
+ return target.type === "Identifier" && (target.name === "describe" || target.name === "it");
11
+ }
3
12
  const consistentParameterLayout = {
4
13
  create(context) {
5
14
  const compactTestCalls = context.options[0]?.compactTestCalls === true;
6
15
  function createVisitor(tokenStore, isTemplate) {
16
+ const getCallOpeningParen = (node) => tokenStore.getTokenAfter(node.typeArguments ?? node.callee, (token) => token.type === "Punctuator" && token.value === "(");
7
17
  function checkTestCallLayout(node) {
8
18
  const items = node.arguments;
9
19
  if (!items.length) return;
10
- const openingParen = tokenStore.getTokenAfter(node.typeArguments ?? node.callee, (token) => token.type === "Punctuator" && token.value === "(");
20
+ const openingParen = getCallOpeningParen(node);
11
21
  const closingParen = tokenStore.getLastToken(node);
12
22
  const previous = tokenStore.getTokenBefore(closingParen);
13
23
  const gaps = [[
@@ -52,7 +62,7 @@ const consistentParameterLayout = {
52
62
  const firstType = first.type;
53
63
  if (isSingleParameter && (firstType === "JSXElement" || firstType === "JSXFragment")) return;
54
64
  let openingParen;
55
- if (node.type === "CallExpression" || node.type === "NewExpression") openingParen = tokenStore.getTokenAfter(node.typeArguments ?? node.callee, (token) => token.type === "Punctuator" && token.value === "(");
65
+ if (node.type === "CallExpression" || node.type === "NewExpression") openingParen = getCallOpeningParen(node);
56
66
  else openingParen = tokenStore.getTokenBefore(first);
57
67
  if (!openingParen || openingParen.value !== "(") return;
58
68
  if (openingParen.range[0] < node.range[0]) return;
@@ -83,7 +93,7 @@ const consistentParameterLayout = {
83
93
  }
84
94
  if (closingParen.value === ")" && tokenStore.getTokenBefore(closingParen).loc.end.line === closingParen.loc.start.line) newlineOffsets.push(closingParen.range[0]);
85
95
  if (newlineOffsets.length) context.report({
86
- fix: (fixer) => newlineOffsets.map((offset) => fixer.insertTextBeforeRange([offset, offset], "\n")),
96
+ fix: insertNewlines(newlineOffsets),
87
97
  messageId: "newline",
88
98
  node: first
89
99
  });
@@ -99,13 +109,9 @@ const consistentParameterLayout = {
99
109
  return {
100
110
  ArrowFunctionExpression: (node) => checkParameterLayout(node, node.params),
101
111
  CallExpression: (node) => {
102
- const { callee } = node;
103
- if (compactTestCalls) {
104
- const target = callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier" && callee.property.name === "concurrent" ? callee.object : callee;
105
- if (target.type === "Identifier" && (target.name === "describe" || target.name === "it")) {
106
- checkTestCallLayout(node);
107
- return;
108
- }
112
+ if (compactTestCalls && isTestCall(node.callee)) {
113
+ checkTestCallLayout(node);
114
+ return;
109
115
  }
110
116
  checkParameterLayout(node, node.arguments);
111
117
  },
@@ -1 +1 @@
1
- {"version":3,"file":"consistent-parameter-layout.js","names":[],"sources":["../../../src/_internals/rules/consistent-parameter-layout.ts"],"sourcesContent":["import type {\n AST,\n Rule,\n} from 'eslint';\n\nimport type { TokenStore } from '../utils';\nimport { defineScriptAndTemplateVisitors } from '../utils';\n\ntype CallNode = Extract<Rule.Node, { type: 'CallExpression' | 'NewExpression' }> & { typeArguments?: Rule.Node };\ntype FunctionNode = Extract<\n Rule.Node,\n { type: 'ArrowFunctionExpression' | 'FunctionDeclaration' | 'FunctionExpression' }\n>;\n\ntype ListItem = CallNode['arguments'][number] | FunctionNode['params'][number];\n\nexport const consistentParameterLayout: Rule.RuleModule = {\n create(context) {\n const compactTestCalls = context.options[0]?.compactTestCalls === true;\n\n function createVisitor(tokenStore: TokenStore, isTemplate: boolean): Rule.RuleListener {\n function checkTestCallLayout(node: CallNode): void {\n const items = node.arguments;\n if (!items.length) return;\n const openingParen = tokenStore.getTokenAfter(\n node.typeArguments ?? node.callee,\n (token) => token.type === 'Punctuator' && token.value === '(',\n )!;\n\n const closingParen = tokenStore.getLastToken(node)!;\n const previous = tokenStore.getTokenBefore(closingParen)!;\n const gaps: Array<[AST.Token, AST.Token, string]> = [\n [\n openingParen,\n tokenStore.getTokenAfter(openingParen)!,\n '',\n ],\n [\n previous,\n closingParen,\n '',\n ],\n ];\n\n for (let index = 1; index < items.length; index++) {\n const comma = tokenStore.getTokensBetween(items[index - 1]!, items[index]!)\n .find((token) => token.type === 'Punctuator' && token.value === ',')!;\n\n gaps.push(\n [\n tokenStore.getTokenBefore(comma)!,\n comma,\n '',\n ],\n [\n comma,\n tokenStore.getTokenAfter(comma)!,\n ' ',\n ],\n );\n }\n\n if (previous.value === ',') {\n gaps.push([\n tokenStore.getTokenBefore(previous)!,\n previous,\n '',\n ]);\n }\n\n // Keep the whole list's layout when a boundary comment prevents safe compaction.\n if (gaps.some(([left, right]) => tokenStore.commentsExistBetween(left, right))) return;\n const multilineGaps = gaps.filter(([left, right]) => left.loc.end.line !== right.loc.start.line);\n if (!multilineGaps.length) return;\n\n context.report({\n fix: (fixer) => multilineGaps.map(([\n left,\n right,\n text,\n ]) => fixer.replaceTextRange(\n [\n left.range[1],\n right.range[0],\n ],\n text,\n )),\n messageId: 'compactTestCall',\n node,\n });\n }\n\n function checkParameterLayout(\n node: CallNode | FunctionNode,\n items: readonly ListItem[],\n ): void {\n const first = items[0];\n if (!first) return;\n const isSingleParameter = items.length === 1;\n\n // JSX argument layout belongs to the JSX formatting rules.\n const firstType: string = first.type;\n if (isSingleParameter && (firstType === 'JSXElement' || firstType === 'JSXFragment')) return;\n let openingParen;\n if (node.type === 'CallExpression' || node.type === 'NewExpression') {\n openingParen = tokenStore.getTokenAfter(\n node.typeArguments ?? node.callee,\n (token) => token.type === 'Punctuator' && token.value === '(',\n );\n } else {\n openingParen = tokenStore.getTokenBefore(first);\n }\n\n if (!openingParen || openingParen.value !== '(') return;\n // An unparenthesized arrow must not borrow its parent's delimiters.\n if (openingParen.range[0] < node.range![0]) return;\n const closingParen = node.type === 'CallExpression' || node.type === 'NewExpression'\n ? tokenStore.getLastToken(node)\n : tokenStore.getTokenAfter(items.at(-1)!, (token) => token.value === ')');\n\n const next = tokenStore.getTokenAfter(openingParen)!;\n\n if (isSingleParameter) {\n if (!closingParen || closingParen.value !== ')') return;\n let previous = tokenStore.getTokenBefore(closingParen)!;\n if (previous.value === ',') previous = tokenStore.getTokenBefore(previous)!;\n if (\n tokenStore.commentsExistBetween(openingParen, next)\n || tokenStore.commentsExistBetween(previous, closingParen)\n ) return;\n\n const hasOpeningNewline = openingParen.loc.end.line !== next.loc.start.line;\n const hasClosingNewline = tokenStore.getTokenBefore(closingParen)!.loc.end.line\n !== closingParen.loc.start.line;\n\n if (hasOpeningNewline === hasClosingNewline) return;\n\n context.report({\n fix: (fixer) => hasOpeningNewline\n ? fixer.insertTextBefore(closingParen, '\\n')\n : fixer.insertTextAfter(openingParen, '\\n'),\n messageId: 'singleBoundary',\n node,\n });\n\n return;\n }\n\n if (!closingParen || openingParen.loc.start.line === closingParen.loc.end.line) return;\n\n if (isTemplate) {\n // Script list formatters do not traverse Vue template expressions.\n const newlineOffsets: number[] = [];\n if (openingParen.loc.end.line === next.loc.start.line) newlineOffsets.push(openingParen.range[1]);\n for (let index = 1; index < items.length; index++) {\n const item = items[index]!;\n const comma = tokenStore.getTokensBetween(items[index - 1]!, item)\n .find((token) => token.value === ',');\n\n if (comma && comma.loc.end.line === tokenStore.getTokenAfter(comma)!.loc.start.line) {\n newlineOffsets.push(comma.range[1]);\n }\n }\n\n if (\n closingParen.value === ')'\n && tokenStore.getTokenBefore(closingParen)!.loc.end.line === closingParen.loc.start.line\n ) newlineOffsets.push(closingParen.range[0]);\n\n if (newlineOffsets.length) {\n context.report({\n fix: (fixer) => newlineOffsets.map((offset) => fixer.insertTextBeforeRange(\n [\n offset,\n offset,\n ],\n '\\n',\n )),\n messageId: 'newline',\n node: first,\n });\n }\n\n return;\n }\n\n if (openingParen.loc.end.line !== next.loc.start.line) return;\n\n context.report({\n fix: (fixer) => fixer.insertTextAfter(openingParen, '\\n'),\n messageId: 'newline',\n node: first,\n });\n }\n\n return {\n ArrowFunctionExpression: (node) => checkParameterLayout(node, node.params),\n CallExpression: (node) => {\n const { callee } = node;\n if (compactTestCalls) {\n const target = callee.type === 'MemberExpression'\n && !callee.computed\n && callee.property.type === 'Identifier'\n && callee.property.name === 'concurrent'\n ? callee.object\n : callee;\n\n if (\n target.type === 'Identifier'\n && (target.name === 'describe' || target.name === 'it')\n ) {\n checkTestCallLayout(node);\n return;\n }\n }\n\n checkParameterLayout(node, node.arguments);\n },\n FunctionDeclaration: (node) => checkParameterLayout(node, node.params),\n FunctionExpression: (node) => checkParameterLayout(node, node.params),\n NewExpression: (node) => checkParameterLayout(node, node.arguments),\n };\n }\n\n return defineScriptAndTemplateVisitors(context.sourceCode, createVisitor);\n },\n meta: {\n docs: { description: 'Keep parameter boundaries consistent, expand multiline lists, and compact test calls.' },\n fixable: 'whitespace',\n messages: {\n compactTestCall: 'Keep test-call arguments beside their parentheses and each other.',\n newline: 'Start a multiline parameter list on a new line.',\n singleBoundary: 'Use matching newline boundaries around a single parameter.',\n },\n schema: [\n {\n additionalProperties: false,\n properties: { compactTestCalls: { type: 'boolean' } },\n type: 'object',\n },\n ],\n type: 'layout',\n },\n};\n"],"mappings":";;AAgBA,MAAa,4B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Ac,OAAO,SAAS,OACpD;OACE,oBAAoB,IAAI;OACxB;MACJ;KACJ;KAEA,qBAAqB,MAAM,KAAK,SAAS;IAC7C;IACA,sBAAsB,SAAS,qBAAqB,MAAM,KAAK,MAAM;IACrE,qBAAqB,SAAS,qBAAqB,MAAM,KAAK,MAAM;IACpE,gBAAgB,SAAS,qBAAqB,MAAM,KAAK,SAAS;GACtE;EACJ;EAEA,OAAO,gCAAgC,QAAQ,YAAY,aAAa;CAC5E;CACA,MAAM;EACF,MAAM,EAAE,aAAa,wFAAwF;EAC7G,SAAS;EACT,UAAU;GACN,iBAAiB;GACjB,SAAS;GACT,gBAAgB;EACpB;EACA,QAAQ,CACJ;GACI,sBAAsB;GACtB,YAAY,EAAE,kBAAkB,EAAE,MAAM,UAAU,EAAE;GACpD,MAAM;EACV,CACJ;EACA,MAAM;CACV;AACJ"}
1
+ {"version":3,"file":"consistent-parameter-layout.js","names":[],"sources":["../../../src/_internals/rules/consistent-parameter-layout.ts"],"sourcesContent":["import type {\n AST,\n Rule,\n} from 'eslint';\n\nimport type { TokenStore } from './utils';\nimport {\n defineScriptAndTemplateVisitors,\n insertNewlines,\n isMemberNamed,\n} from './utils';\n\ntype CallNode = Extract<Rule.Node, { type: 'CallExpression' | 'NewExpression' }> & { typeArguments?: Rule.Node };\ntype FunctionNode = Extract<\n Rule.Node,\n { type: 'ArrowFunctionExpression' | 'FunctionDeclaration' | 'FunctionExpression' }\n>;\n\ntype ListItem = CallNode['arguments'][number] | FunctionNode['params'][number];\n\nfunction isTestCall(callee: CallNode['callee']): boolean {\n let target = callee;\n if (target.type === 'CallExpression') {\n if (!isMemberNamed(target.callee, 'for')) return false;\n target = target.callee.object;\n }\n\n if (isMemberNamed(target, 'concurrent')) target = target.object;\n return target.type === 'Identifier' && (target.name === 'describe' || target.name === 'it');\n}\n\nexport const consistentParameterLayout: Rule.RuleModule = {\n create(context) {\n const options = context.options[0] as undefined | { compactTestCalls?: boolean };\n const compactTestCalls = options?.compactTestCalls === true;\n\n function createVisitor(tokenStore: TokenStore, isTemplate: boolean): Rule.RuleListener {\n const getCallOpeningParen = (node: CallNode) => tokenStore.getTokenAfter(\n node.typeArguments ?? node.callee,\n (token) => token.type === 'Punctuator' && token.value === '(',\n );\n\n function checkTestCallLayout(node: CallNode): void {\n const items = node.arguments;\n if (!items.length) return;\n const openingParen = getCallOpeningParen(node)!;\n\n const closingParen = tokenStore.getLastToken(node)!;\n const previous = tokenStore.getTokenBefore(closingParen)!;\n const gaps: Array<[AST.Token, AST.Token, string]> = [\n [\n openingParen,\n tokenStore.getTokenAfter(openingParen)!,\n '',\n ],\n [\n previous,\n closingParen,\n '',\n ],\n ];\n\n for (let index = 1; index < items.length; index++) {\n const comma = tokenStore.getTokensBetween(items[index - 1]!, items[index]!)\n .find((token) => token.type === 'Punctuator' && token.value === ',')!;\n\n gaps.push(\n [\n tokenStore.getTokenBefore(comma)!,\n comma,\n '',\n ],\n [\n comma,\n tokenStore.getTokenAfter(comma)!,\n ' ',\n ],\n );\n }\n\n if (previous.value === ',') {\n gaps.push([\n tokenStore.getTokenBefore(previous)!,\n previous,\n '',\n ]);\n }\n\n // Keep the whole list's layout when a boundary comment prevents safe compaction.\n if (gaps.some(([left, right]) => tokenStore.commentsExistBetween(left, right))) return;\n const multilineGaps = gaps.filter(([left, right]) => left.loc.end.line !== right.loc.start.line);\n if (!multilineGaps.length) return;\n\n context.report({\n fix: (fixer) => multilineGaps.map(([\n left,\n right,\n text,\n ]) => fixer.replaceTextRange(\n [\n left.range[1],\n right.range[0],\n ],\n text,\n )),\n messageId: 'compactTestCall',\n node,\n });\n }\n\n function checkParameterLayout(\n node: CallNode | FunctionNode,\n items: readonly ListItem[],\n ): void {\n const first = items[0];\n if (!first) return;\n const isSingleParameter = items.length === 1;\n\n // JSX argument layout belongs to the JSX formatting rules.\n const firstType: string = first.type;\n if (isSingleParameter && (firstType === 'JSXElement' || firstType === 'JSXFragment')) return;\n let openingParen;\n if (node.type === 'CallExpression' || node.type === 'NewExpression') {\n openingParen = getCallOpeningParen(node);\n } else {\n openingParen = tokenStore.getTokenBefore(first);\n }\n\n if (!openingParen || openingParen.value !== '(') return;\n // An unparenthesized arrow must not borrow its parent's delimiters.\n if (openingParen.range[0] < node.range![0]) return;\n const closingParen = node.type === 'CallExpression' || node.type === 'NewExpression'\n ? tokenStore.getLastToken(node)\n : tokenStore.getTokenAfter(items.at(-1)!, (token) => token.value === ')');\n\n const next = tokenStore.getTokenAfter(openingParen)!;\n\n if (isSingleParameter) {\n if (!closingParen || closingParen.value !== ')') return;\n let previous = tokenStore.getTokenBefore(closingParen)!;\n if (previous.value === ',') previous = tokenStore.getTokenBefore(previous)!;\n if (\n tokenStore.commentsExistBetween(openingParen, next)\n || tokenStore.commentsExistBetween(previous, closingParen)\n ) return;\n\n const hasOpeningNewline = openingParen.loc.end.line !== next.loc.start.line;\n const hasClosingNewline = tokenStore.getTokenBefore(closingParen)!.loc.end.line\n !== closingParen.loc.start.line;\n\n if (hasOpeningNewline === hasClosingNewline) return;\n\n context.report({\n fix: (fixer) => hasOpeningNewline\n ? fixer.insertTextBefore(closingParen, '\\n')\n : fixer.insertTextAfter(openingParen, '\\n'),\n messageId: 'singleBoundary',\n node,\n });\n\n return;\n }\n\n if (!closingParen || openingParen.loc.start.line === closingParen.loc.end.line) return;\n\n if (isTemplate) {\n // Script list formatters do not traverse Vue template expressions.\n const newlineOffsets: number[] = [];\n if (openingParen.loc.end.line === next.loc.start.line) newlineOffsets.push(openingParen.range[1]);\n for (let index = 1; index < items.length; index++) {\n const item = items[index]!;\n const comma = tokenStore.getTokensBetween(items[index - 1]!, item)\n .find((token) => token.value === ',');\n\n if (comma && comma.loc.end.line === tokenStore.getTokenAfter(comma)!.loc.start.line) {\n newlineOffsets.push(comma.range[1]);\n }\n }\n\n if (\n closingParen.value === ')'\n && tokenStore.getTokenBefore(closingParen)!.loc.end.line === closingParen.loc.start.line\n ) newlineOffsets.push(closingParen.range[0]);\n\n if (newlineOffsets.length) {\n context.report({\n fix: insertNewlines(newlineOffsets),\n messageId: 'newline',\n node: first,\n });\n }\n\n return;\n }\n\n if (openingParen.loc.end.line !== next.loc.start.line) return;\n\n context.report({\n fix: (fixer) => fixer.insertTextAfter(openingParen, '\\n'),\n messageId: 'newline',\n node: first,\n });\n }\n\n return {\n ArrowFunctionExpression: (node) => checkParameterLayout(node, node.params),\n CallExpression: (node) => {\n if (compactTestCalls && isTestCall(node.callee)) {\n checkTestCallLayout(node);\n return;\n }\n\n checkParameterLayout(node, node.arguments);\n },\n FunctionDeclaration: (node) => checkParameterLayout(node, node.params),\n FunctionExpression: (node) => checkParameterLayout(node, node.params),\n NewExpression: (node) => checkParameterLayout(node, node.arguments),\n };\n }\n\n return defineScriptAndTemplateVisitors(context.sourceCode, createVisitor);\n },\n meta: {\n docs: { description: 'Keep parameter boundaries consistent, expand multiline lists, and compact test calls.' },\n fixable: 'whitespace',\n messages: {\n compactTestCall: 'Keep test-call arguments beside their parentheses and each other.',\n newline: 'Start a multiline parameter list on a new line.',\n singleBoundary: 'Use matching newline boundaries around a single parameter.',\n },\n schema: [\n {\n additionalProperties: false,\n properties: { compactTestCalls: { type: 'boolean' } },\n type: 'object',\n },\n ],\n type: 'layout',\n },\n};\n"],"mappings":";;AAoBA,SAAS,WAAW,QAAqC;CACrD,IAAI,SAAS;CACb,IAAI,OAAO,SAAS,kBAAkB;EAClC,IAAI,CAAC,cAAc,OAAO,QAAQ,KAAK,GAAG,OAAO;EACjD,SAAS,OAAO,OAAO;CAC3B;CAEA,IAAI,cAAc,QAAQ,YAAY,GAAG,SAAS,OAAO;CACzD,OAAO,OAAO,SAAS,iBAAiB,OAAO,SAAS,cAAc,OAAO,SAAS;AAC1F;AAEA,MAAa,4BAA6C;CACtD,OAAO,SAAS;EAEZ,MAAM,mBADU,QAAQ,QAAQ,EACA,EAAE,qBAAqB;EAEvD,SAAS,cAAc,YAAwB,YAAwC;GACnF,MAAM,uBAAuB,SAAmB,WAAW,cACvD,KAAK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GACI,sBAAsB;GACtB,YAAY,EAAE,kBAAkB,EAAE,MAAM,UAAU,EAAE;GACpD,MAAM;EACV,CACJ;EACA,MAAM;CACV;AACJ"}
@@ -1,4 +1,4 @@
1
- export declare const customPlugins: {
1
+ export declare const kikiutilsPlugin: {
2
2
  rules: {
3
3
  'comment-indent': import("eslint").Rule.RuleModule;
4
4
  'compact-iteration-layout': import("eslint").Rule.RuleModule;
@@ -6,12 +6,18 @@ export declare const customPlugins: {
6
6
  'consistent-parameter-layout': import("eslint").Rule.RuleModule;
7
7
  'nitro-route-method-suffix': import("eslint").Rule.RuleModule;
8
8
  'no-composable-in-head-getter': import("eslint").Rule.RuleModule;
9
+ 'no-reactive-composable-return': import("eslint").Rule.RuleModule;
10
+ 'no-reactive-destructure': import("eslint").Rule.RuleModule;
11
+ 'no-restricted-nuxt-app-syntax': import("eslint").Rule.RuleModule;
12
+ 'no-restricted-nuxt-component-syntax': import("eslint").Rule.RuleModule;
9
13
  'no-restricted-nuxt-page-syntax': import("eslint").Rule.RuleModule;
10
14
  'no-restricted-nuxt-server-imports': import("eslint").Rule.RuleModule;
11
15
  'no-restricted-nuxt-syntax': import("eslint").Rule.RuleModule;
12
16
  'no-restricted-test-imports': import("eslint").Rule.RuleModule;
17
+ 'no-restricted-test-syntax': import("eslint").Rule.RuleModule;
13
18
  'no-silent-catch': import("eslint").Rule.RuleModule;
14
19
  'no-thenable-zod-refinement': import("eslint").Rule.RuleModule;
20
+ 'prefer-enhanced-date': import("eslint").Rule.RuleModule;
15
21
  'promise-function-async': import("eslint").Rule.RuleModule;
16
22
  'statement-padding': import("eslint").Rule.RuleModule;
17
23
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/_internals/rules/index.ts"],"mappings":"A,qBAoBa"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/_internals/rules/index.ts"],"mappings":"A,qBAuBa"}
@@ -5,30 +5,39 @@ import { consistentConditionLayout } from "./consistent-condition-layout.js";
5
5
  import { consistentParameterLayout } from "./consistent-parameter-layout.js";
6
6
  import { nitroRouteMethodSuffix } from "./nitro-route-method-suffix.js";
7
7
  import { noComposableInHeadGetter } from "./no-composable-in-head-getter.js";
8
+ import { noReactiveComposableReturn } from "./no-reactive-composable-return.js";
9
+ import { noReactiveDestructure } from "./no-reactive-destructure.js";
8
10
  import { noSilentCatch } from "./no-silent-catch.js";
9
11
  import { noThenableZodRefinement } from "./no-thenable-zod-refinement.js";
12
+ import { preferEnhancedDate } from "./prefer-enhanced-date.js";
10
13
  import { promiseFunctionAsync } from "./promise-function-async.js";
11
14
  import { statementPadding } from "./statement-padding.js";
12
15
  // src/_internals/rules/index.ts
13
16
  const coreRules = builtinRules;
14
17
  const noRestrictedImports = coreRules.get("no-restricted-imports");
15
18
  const noRestrictedSyntax = coreRules.get("no-restricted-syntax");
16
- const customPlugins = { rules: {
19
+ const kikiutilsPlugin = { rules: {
17
20
  "comment-indent": commentIndent,
18
21
  "compact-iteration-layout": compactIterationLayout,
19
22
  "consistent-condition-layout": consistentConditionLayout,
20
23
  "consistent-parameter-layout": consistentParameterLayout,
21
24
  "nitro-route-method-suffix": nitroRouteMethodSuffix,
22
25
  "no-composable-in-head-getter": noComposableInHeadGetter,
26
+ "no-reactive-composable-return": noReactiveComposableReturn,
27
+ "no-reactive-destructure": noReactiveDestructure,
28
+ "no-restricted-nuxt-app-syntax": noRestrictedSyntax,
29
+ "no-restricted-nuxt-component-syntax": noRestrictedSyntax,
23
30
  "no-restricted-nuxt-page-syntax": noRestrictedSyntax,
24
31
  "no-restricted-nuxt-server-imports": noRestrictedImports,
25
32
  "no-restricted-nuxt-syntax": noRestrictedSyntax,
26
33
  "no-restricted-test-imports": noRestrictedImports,
34
+ "no-restricted-test-syntax": noRestrictedSyntax,
27
35
  "no-silent-catch": noSilentCatch,
28
36
  "no-thenable-zod-refinement": noThenableZodRefinement,
37
+ "prefer-enhanced-date": preferEnhancedDate,
29
38
  "promise-function-async": promiseFunctionAsync,
30
39
  "statement-padding": statementPadding
31
40
  } };
32
- export { customPlugins };
41
+ export { kikiutilsPlugin };
33
42
 
34
43
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../src/_internals/rules/index.ts"],"sourcesContent":["import { builtinRules } from 'eslint/use-at-your-own-risk';\n\nimport { commentIndent } from './comment-indent';\nimport { compactIterationLayout } from './compact-iteration-layout';\nimport { consistentConditionLayout } from './consistent-condition-layout';\nimport { consistentParameterLayout } from './consistent-parameter-layout';\nimport { nitroRouteMethodSuffix } from './nitro-route-method-suffix';\nimport { noComposableInHeadGetter } from './no-composable-in-head-getter';\nimport { noSilentCatch } from './no-silent-catch';\nimport { noThenableZodRefinement } from './no-thenable-zod-refinement';\nimport { promiseFunctionAsync } from './promise-function-async';\nimport { statementPadding } from './statement-padding';\n\n// Each scope adds its restrictions under its own name: a later config replaces a rule's whole option list,\n// so sharing the core rule would drop the restrictions of every broader scope.\n// eslint-disable-next-line ts/no-deprecated -- No supported API exposes core rules yet; typescript-eslint uses it too.\nconst coreRules = builtinRules;\nconst noRestrictedImports = coreRules.get('no-restricted-imports')!;\nconst noRestrictedSyntax = coreRules.get('no-restricted-syntax')!;\n\nexport const customPlugins = {\n rules: {\n 'comment-indent': commentIndent,\n 'compact-iteration-layout': compactIterationLayout,\n 'consistent-condition-layout': consistentConditionLayout,\n 'consistent-parameter-layout': consistentParameterLayout,\n 'nitro-route-method-suffix': nitroRouteMethodSuffix,\n 'no-composable-in-head-getter': noComposableInHeadGetter,\n 'no-restricted-nuxt-page-syntax': noRestrictedSyntax,\n 'no-restricted-nuxt-server-imports': noRestrictedImports,\n 'no-restricted-nuxt-syntax': noRestrictedSyntax,\n 'no-restricted-test-imports': noRestrictedImports,\n 'no-silent-catch': noSilentCatch,\n 'no-thenable-zod-refinement': noThenableZodRefinement,\n 'promise-function-async': promiseFunctionAsync,\n 'statement-padding': statementPadding,\n },\n};\n"],"mappings":";;;;;;;;;;;;AAgBA,MAAM,YAAY;AAClB,MAAM,sBAAsB,UAAU,IAAI,uBAAuB;AACjE,MAAM,qBAAqB,UAAU,IAAI,sBAAsB;AAE/D,MAAa,gBAAgB,EACzB,OAAO;CACH,kBAAkB;CAClB,4BAA4B;CAC5B,+BAA+B;CAC/B,+BAA+B;CAC/B,6BAA6B;CAC7B,gCAAgC;CAChC,kCAAkC;CAClC,qCAAqC;CACrC,6BAA6B;CAC7B,8BAA8B;CAC9B,mBAAmB;CACnB,8BAA8B;CAC9B,0BAA0B;CAC1B,qBAAqB;AACzB,EACJ"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/_internals/rules/index.ts"],"sourcesContent":["import { builtinRules } from 'eslint/use-at-your-own-risk';\n\nimport { commentIndent } from './comment-indent';\nimport { compactIterationLayout } from './compact-iteration-layout';\nimport { consistentConditionLayout } from './consistent-condition-layout';\nimport { consistentParameterLayout } from './consistent-parameter-layout';\nimport { nitroRouteMethodSuffix } from './nitro-route-method-suffix';\nimport { noComposableInHeadGetter } from './no-composable-in-head-getter';\nimport { noReactiveComposableReturn } from './no-reactive-composable-return';\nimport { noReactiveDestructure } from './no-reactive-destructure';\nimport { noSilentCatch } from './no-silent-catch';\nimport { noThenableZodRefinement } from './no-thenable-zod-refinement';\nimport { preferEnhancedDate } from './prefer-enhanced-date';\nimport { promiseFunctionAsync } from './promise-function-async';\nimport { statementPadding } from './statement-padding';\n\n// Each scope adds its restrictions under its own name: a later config replaces a rule's whole option list,\n// so sharing the core rule would drop the restrictions of every broader scope.\n// eslint-disable-next-line ts/no-deprecated -- No supported API exposes core rules yet; typescript-eslint uses it too.\nconst coreRules = builtinRules;\nconst noRestrictedImports = coreRules.get('no-restricted-imports')!;\nconst noRestrictedSyntax = coreRules.get('no-restricted-syntax')!;\n\nexport const kikiutilsPlugin = {\n rules: {\n 'comment-indent': commentIndent,\n 'compact-iteration-layout': compactIterationLayout,\n 'consistent-condition-layout': consistentConditionLayout,\n 'consistent-parameter-layout': consistentParameterLayout,\n 'nitro-route-method-suffix': nitroRouteMethodSuffix,\n 'no-composable-in-head-getter': noComposableInHeadGetter,\n 'no-reactive-composable-return': noReactiveComposableReturn,\n 'no-reactive-destructure': noReactiveDestructure,\n 'no-restricted-nuxt-app-syntax': noRestrictedSyntax,\n 'no-restricted-nuxt-component-syntax': noRestrictedSyntax,\n 'no-restricted-nuxt-page-syntax': noRestrictedSyntax,\n 'no-restricted-nuxt-server-imports': noRestrictedImports,\n 'no-restricted-nuxt-syntax': noRestrictedSyntax,\n 'no-restricted-test-imports': noRestrictedImports,\n 'no-restricted-test-syntax': noRestrictedSyntax,\n 'no-silent-catch': noSilentCatch,\n 'no-thenable-zod-refinement': noThenableZodRefinement,\n 'prefer-enhanced-date': preferEnhancedDate,\n 'promise-function-async': promiseFunctionAsync,\n 'statement-padding': statementPadding,\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;AAmBA,MAAM,YAAY;AAClB,MAAM,sBAAsB,UAAU,IAAI,uBAAuB;AACjE,MAAM,qBAAqB,UAAU,IAAI,sBAAsB;AAE/D,MAAa,kBAAkB,EAC3B,OAAO;CACH,kBAAkB;CAClB,4BAA4B;CAC5B,+BAA+B;CAC/B,+BAA+B;CAC/B,6BAA6B;CAC7B,gCAAgC;CAChC,iCAAiC;CACjC,2BAA2B;CAC3B,iCAAiC;CACjC,uCAAuC;CACvC,kCAAkC;CAClC,qCAAqC;CACrC,6BAA6B;CAC7B,8BAA8B;CAC9B,6BAA6B;CAC7B,mBAAmB;CACnB,8BAA8B;CAC9B,wBAAwB;CACxB,0BAA0B;CAC1B,qBAAqB;AACzB,EACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"no-composable-in-head-getter.d.ts","names":[],"sources":["../../../src/_internals/rules/no-composable-in-head-getter.ts"],"mappings":";qBAaa,0BAA0B,KAAK"}
1
+ {"version":3,"file":"no-composable-in-head-getter.d.ts","names":[],"sources":["../../../src/_internals/rules/no-composable-in-head-getter.ts"],"mappings":";qBAoEa,0BAA0B,KAAK"}
@@ -1,3 +1,5 @@
1
+ import ts from "typescript";
2
+ import { composablePattern } from "./utils.js";
1
3
  // src/_internals/rules/no-composable-in-head-getter.ts
2
4
  const headComposables = /* @__PURE__ */ new Set([
3
5
  "useHead",
@@ -7,31 +9,107 @@ const headComposables = /* @__PURE__ */ new Set([
7
9
  "useServerHeadSafe",
8
10
  "useServerSeoMeta"
9
11
  ]);
10
- const composablePattern = /^use[A-Z]/;
12
+ function findCalledComposable(bodies) {
13
+ let composable;
14
+ const visit = (node) => {
15
+ if (composable || ts.isFunctionLike(node)) return;
16
+ if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && composablePattern.test(node.expression.text)) {
17
+ composable = node.expression.text;
18
+ return;
19
+ }
20
+ ts.forEachChild(node, visit);
21
+ };
22
+ for (const body of bodies) {
23
+ visit(body);
24
+ if (composable) return composable;
25
+ }
26
+ }
27
+ function getBody(node) {
28
+ if (node && ts.isFunctionLike(node) && "body" in node) return node.body;
29
+ }
30
+ function getImplementationBodies(checker, call) {
31
+ const callee = ts.isPropertyAccessExpression(call.expression) ? call.expression.name : call.expression;
32
+ let symbol = checker.getSymbolAtLocation(callee);
33
+ if (symbol && symbol.flags & ts.SymbolFlags.Alias) symbol = checker.getAliasedSymbol(symbol);
34
+ const values = (symbol?.declarations ?? []).map((declaration) => {
35
+ if (ts.isVariableDeclaration(declaration) || ts.isPropertyAssignment(declaration)) return declaration.initializer;
36
+ return getBody(declaration) && declaration;
37
+ });
38
+ if (values.some(Boolean)) return values.map((value) => getBody(value)).filter((body) => body !== void 0);
39
+ const declaration = checker.getResolvedSignature(call)?.getDeclaration();
40
+ const name = declaration && ts.isFunctionDeclaration(declaration) ? declaration.name : void 0;
41
+ return (name ? checker.getSymbolAtLocation(name)?.declarations ?? [] : [declaration]).map((implementation) => getBody(implementation)).filter((body) => body !== void 0);
42
+ }
11
43
  const noComposableInHeadGetter = {
12
44
  create(context) {
13
- return { CallExpression(node) {
14
- if (node.callee.type !== "Identifier" || !composablePattern.test(node.callee.name)) return;
15
- let insideFunction = false;
16
- for (const parent of context.sourceCode.getAncestors(node).reverse()) {
17
- if (parent.type === "ArrowFunctionExpression" || parent.type === "FunctionExpression") insideFunction = true;
18
- if (insideFunction && parent.type === "CallExpression" && parent.callee.type === "Identifier" && headComposables.has(parent.callee.name)) {
19
- context.report({
20
- data: {
21
- composable: node.callee.name,
22
- head: parent.callee.name
23
- },
24
- messageId: "getter",
25
- node
26
- });
27
- return;
28
- }
45
+ const services = context.sourceCode.parserServices;
46
+ const checker = services?.program?.getTypeChecker();
47
+ const nodeMap = services?.esTreeNodeToTSNodeMap;
48
+ const headCalls = [];
49
+ const getters = [];
50
+ function enterFunction(node) {
51
+ const headCall = headCalls.at(-1);
52
+ if (!headCall) return;
53
+ const { parent } = node;
54
+ if (parent.type === "CallExpression" && parent !== headCall.node && (parent.callee.type !== "Identifier" || parent.callee.name !== "computed")) return;
55
+ getters.push({
56
+ head: headCall.head,
57
+ node
58
+ });
59
+ }
60
+ function exitFunction(node) {
61
+ if (getters.at(-1)?.node === node) getters.pop();
62
+ }
63
+ function checkCall(node, head) {
64
+ const { callee } = node;
65
+ if (callee.type === "Identifier" && composablePattern.test(callee.name)) {
66
+ context.report({
67
+ data: {
68
+ composable: callee.name,
69
+ head
70
+ },
71
+ messageId: "getter",
72
+ node
73
+ });
74
+ return;
29
75
  }
30
- } };
76
+ if (!checker || !nodeMap) return;
77
+ const composable = findCalledComposable(getImplementationBodies(checker, nodeMap.get(node)));
78
+ if (!composable) return;
79
+ context.report({
80
+ data: {
81
+ composable,
82
+ function: context.sourceCode.getText(callee),
83
+ head
84
+ },
85
+ messageId: "indirectGetter",
86
+ node
87
+ });
88
+ }
89
+ return {
90
+ "ArrowFunctionExpression": enterFunction,
91
+ "ArrowFunctionExpression:exit": exitFunction,
92
+ CallExpression(node) {
93
+ const getter = getters.at(-1);
94
+ if (getter) checkCall(node, getter.head);
95
+ if (node.callee.type === "Identifier" && headComposables.has(node.callee.name)) headCalls.push({
96
+ head: node.callee.name,
97
+ node
98
+ });
99
+ },
100
+ "CallExpression:exit": (node) => {
101
+ if (headCalls.at(-1)?.node === node) headCalls.pop();
102
+ },
103
+ "FunctionExpression": enterFunction,
104
+ "FunctionExpression:exit": exitFunction
105
+ };
31
106
  },
32
107
  meta: {
33
108
  docs: { description: "Disallow calling composables inside `useHead`/`useSeoMeta` getters." },
34
- messages: { getter: "`{{ composable }}()` runs when the `{{ head }}` getter is evaluated after setup, outside the component context. Call it in setup and use its result in the getter." },
109
+ messages: {
110
+ getter: "`{{ composable }}()` runs when the `{{ head }}` getter is evaluated after setup, outside the component context. Call it in setup and use its result in the getter.",
111
+ indirectGetter: "`{{ function }}()` calls `{{ composable }}()`, which runs when the `{{ head }}` getter is evaluated after setup, outside the component context. Get what it needs in setup, such as a function returned by a composable, and call that in the getter."
112
+ },
35
113
  schema: [],
36
114
  type: "problem"
37
115
  }
@@ -1 +1 @@
1
- {"version":3,"file":"no-composable-in-head-getter.js","names":[],"sources":["../../../src/_internals/rules/no-composable-in-head-getter.ts"],"sourcesContent":["import type { Rule } from 'eslint';\n\nconst headComposables = new Set([\n 'useHead',\n 'useHeadSafe',\n 'useSeoMeta',\n 'useServerHead',\n 'useServerHeadSafe',\n 'useServerSeoMeta',\n]);\n\nconst composablePattern = /^use[A-Z]/;\n\nexport const noComposableInHeadGetter: Rule.RuleModule = {\n create(context) {\n return {\n CallExpression(node) {\n if (node.callee.type !== 'Identifier' || !composablePattern.test(node.callee.name)) return;\n let insideFunction = false;\n for (const parent of context.sourceCode.getAncestors(node).reverse()) {\n if (parent.type === 'ArrowFunctionExpression' || parent.type === 'FunctionExpression') {\n insideFunction = true;\n }\n\n if (\n insideFunction\n && parent.type === 'CallExpression'\n && parent.callee.type === 'Identifier'\n && headComposables.has(parent.callee.name)\n ) {\n context.report({\n data: {\n composable: node.callee.name,\n head: parent.callee.name,\n },\n messageId: 'getter',\n node,\n });\n\n return;\n }\n }\n },\n };\n },\n meta: {\n docs: { description: 'Disallow calling composables inside `useHead`/`useSeoMeta` getters.' },\n messages: { getter: '`{{ composable }}()` runs when the `{{ head }}` getter is evaluated after setup, outside the component context. Call it in setup and use its result in the getter.' },\n schema: [],\n type: 'problem',\n },\n};\n"],"mappings":";AAEA,MAAM,kCAAkB,IAAI,IAAI;CAC5B;CACA;CACA;CACA;CACA;CACA;AACJ,CAAC;AAED,MAAM,oBAAoB;AAE1B,MAAa,2BAA4C;CACrD,OAAO,SAAS;EACZ,OAAO,EACH,eAAe,MAAM;GACjB,IAAI,KAAK,OAAO,SAAS,gBAAgB,CAAC,kBAAkB,KAAK,KAAK,OAAO,IAAI,GAAG;GACpF,IAAI,iBAAiB;GACrB,KAAK,MAAM,UAAU,QAAQ,WAAW,aAAa,IAAI,CAAC,CAAC,QAAQ,GAAG;IAClE,IAAI,OAAO,SAAS,6BAA6B,OAAO,SAAS,sBAC7D,iBAAiB;IAGrB,IACI,kBACG,OAAO,SAAS,oBAChB,OAAO,OAAO,SAAS,gBACvB,gBAAgB,IAAI,OAAO,OAAO,IAAI,GAC3C;KACE,QAAQ,OAAO;MACX,MAAM;OACF,YAAY,KAAK,OAAO;OACxB,MAAM,OAAO,OAAO;MACxB;MACA,WAAW;MACX;KACJ,CAAC;KAED;IACJ;GACJ;EACJ,EACJ;CACJ;CACA,MAAM;EACF,MAAM,EAAE,aAAa,sEAAsE;EAC3F,UAAU,EAAE,QAAQ,qKAAqK;EACzL,QAAQ,CAAC;EACT,MAAM;CACV;AACJ"}
1
+ {"version":3,"file":"no-composable-in-head-getter.js","names":[],"sources":["../../../src/_internals/rules/no-composable-in-head-getter.ts"],"sourcesContent":["import type { Rule } from 'eslint';\nimport ts from 'typescript';\n\nimport type { ParserServices } from './utils';\nimport { composablePattern } from './utils';\n\ntype CallNode = Extract<Rule.Node, { type: 'CallExpression' }>;\ntype FunctionNode = Extract<Rule.Node, { type: 'ArrowFunctionExpression' | 'FunctionExpression' }>;\n\nconst headComposables = new Set([\n 'useHead',\n 'useHeadSafe',\n 'useSeoMeta',\n 'useServerHead',\n 'useServerHeadSafe',\n 'useServerSeoMeta',\n]);\n\n// Functions nested in the body are skipped: calling the outer function does not run them.\nfunction findCalledComposable(bodies: readonly ts.Node[]): string | undefined {\n let composable: string | undefined;\n const visit = (node: ts.Node): void => {\n if (composable || ts.isFunctionLike(node)) return;\n if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && composablePattern.test(node.expression.text)) {\n composable = node.expression.text;\n return;\n }\n\n ts.forEachChild(node, visit);\n };\n\n for (const body of bodies) {\n visit(body);\n if (composable) return composable;\n }\n}\n\nfunction getBody(node: ts.Node | undefined): ts.Node | undefined {\n if (node && ts.isFunctionLike(node) && 'body' in node) return node.body;\n}\n\n// Uses the callee's own declaration, so an annotated value is judged by what it holds, not by its type.\nfunction getImplementationBodies(checker: ts.TypeChecker, call: ts.CallExpression): ts.Node[] {\n const callee = ts.isPropertyAccessExpression(call.expression) ? call.expression.name : call.expression;\n let symbol = checker.getSymbolAtLocation(callee);\n if (symbol && symbol.flags & ts.SymbolFlags.Alias) symbol = checker.getAliasedSymbol(symbol);\n const declarations = symbol?.declarations ?? [];\n const values = declarations.map((declaration) => {\n if (ts.isVariableDeclaration(declaration) || ts.isPropertyAssignment(declaration)) return declaration.initializer;\n return getBody(declaration) && declaration;\n });\n\n if (values.some(Boolean)) {\n return values\n .map((value) => getBody(value))\n .filter((body) => body !== undefined);\n }\n\n // Nuxt auto-import globals are ambient `typeof import('...')['fn']` constants; only their type leads to the source.\n const declaration = checker.getResolvedSignature(call)?.getDeclaration();\n // An overload signature has no body; the implementation shares its symbol.\n const name = declaration && ts.isFunctionDeclaration(declaration) ? declaration.name : undefined;\n const implementations = name ? checker.getSymbolAtLocation(name)?.declarations ?? [] : [declaration];\n return implementations\n .map((implementation) => getBody(implementation))\n .filter((body) => body !== undefined);\n}\n\nexport const noComposableInHeadGetter: Rule.RuleModule = {\n create(context) {\n // Type information is optional: without it, only composables called directly in a getter are reported.\n const services = context.sourceCode.parserServices as Partial<ParserServices> | undefined;\n const checker = services?.program?.getTypeChecker();\n const nodeMap = services?.esTreeNodeToTSNodeMap;\n const headCalls: Array<{ head: string; node: CallNode }> = [];\n const getters: Array<{ head: string; node: FunctionNode }> = [];\n\n // Functions in a head input run when the head is resolved after setup, except callbacks passed to other calls,\n // such as `.map()`, which run while the input is built; `computed()` getters are also evaluated later.\n function enterFunction(node: FunctionNode): void {\n const headCall = headCalls.at(-1);\n if (!headCall) return;\n const { parent } = node;\n if (\n parent.type === 'CallExpression'\n && parent !== headCall.node\n && (parent.callee.type !== 'Identifier' || parent.callee.name !== 'computed')\n ) return;\n\n getters.push({\n head: headCall.head,\n node,\n });\n }\n\n function exitFunction(node: FunctionNode): void {\n if (getters.at(-1)?.node === node) getters.pop();\n }\n\n function checkCall(node: CallNode, head: string): void {\n const { callee } = node;\n if (callee.type === 'Identifier' && composablePattern.test(callee.name)) {\n context.report({\n data: {\n composable: callee.name,\n head,\n },\n messageId: 'getter',\n node,\n });\n\n return;\n }\n\n if (!checker || !nodeMap) return;\n const composable = findCalledComposable(getImplementationBodies(checker, nodeMap.get(node) as ts.CallExpression));\n if (!composable) return;\n context.report({\n data: {\n composable,\n function: context.sourceCode.getText(callee),\n head,\n },\n messageId: 'indirectGetter',\n node,\n });\n }\n\n return {\n 'ArrowFunctionExpression': enterFunction,\n 'ArrowFunctionExpression:exit': exitFunction,\n CallExpression(node) {\n const getter = getters.at(-1);\n if (getter) checkCall(node, getter.head);\n if (node.callee.type === 'Identifier' && headComposables.has(node.callee.name)) {\n headCalls.push({\n head: node.callee.name,\n node,\n });\n }\n },\n 'CallExpression:exit': (node) => {\n if (headCalls.at(-1)?.node === node) headCalls.pop();\n },\n 'FunctionExpression': enterFunction,\n 'FunctionExpression:exit': exitFunction,\n };\n },\n meta: {\n docs: { description: 'Disallow calling composables inside `useHead`/`useSeoMeta` getters.' },\n messages: {\n getter: '`{{ composable }}()` runs when the `{{ head }}` getter is evaluated after setup, outside the component context. Call it in setup and use its result in the getter.',\n indirectGetter: '`{{ function }}()` calls `{{ composable }}()`, which runs when the `{{ head }}` getter is evaluated after setup, outside the component context. Get what it needs in setup, such as a function returned by a composable, and call that in the getter.',\n },\n schema: [],\n type: 'problem',\n },\n};\n"],"mappings":";;;AASA,MAAM,kCAAkB,IAAI,IAAI;CAC5B;CACA;CACA;CACA;CACA;CACA;AACJ,CAAC;AAGD,SAAS,qBAAqB,QAAgD;CAC1E,IAAI;CACJ,MAAM,SAAS,SAAwB;EACnC,IAAI,cAAc,GAAG,eAAe,IAAI,GAAG;EAC3C,IAAI,GAAG,iBAAiB,IAAI,KAAK,GAAG,aAAa,KAAK,UAAU,KAAK,kBAAkB,KAAK,KAAK,WAAW,IAAI,GAAG;GAC/G,aAAa,KAAK,WAAW;GAC7B;EACJ;EAEA,GAAG,aAAa,MAAM,KAAK;CAC/B;CAEA,KAAK,MAAM,QAAQ,QAAQ;EACvB,MAAM,IAAI;EACV,IAAI,YAAY,OAAO;CAC3B;AACJ;AAEA,SAAS,QAAQ,MAAgD;CAC7D,IAAI,QAAQ,GAAG,eAAe,IAAI,KAAK,UAAU,MAAM,OAAO,KAAK;AACvE;AAGA,SAAS,wBAAwB,SAAyB,MAAoC;CAC1F,MAAM,SAAS,GAAG,2BAA2B,KAAK,UAAU,IAAI,KAAK,WAAW,OAAO,KAAK;CAC5F,IAAI,SAAS,QAAQ,oBAAoB,MAAM;CAC/C,IAAI,UAAU,OAAO,QAAQ,GAAG,YAAY,OAAO,SAAS,QAAQ,iBAAiB,MAAM;CAE3F,MAAM,UADe,QAAQ,gBAAgB,CAAC,EAAA,CAClB,KAAK,gBAAgB;EAC7C,IAAI,GAAG,sBAAsB,WAAW,KAAK,GAAG,qBAAqB,WAAW,GAAG,OAAO,YAAY;EACtG,OAAO,QAAQ,WAAW,KAAK;CACnC,CAAC;CAED,IAAI,OAAO,KAAK,OAAO,GACnB,OAAO,OACF,KAAK,UAAU,QA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I,IAAI,CAAsB,CAAC;GAChH,IAAI,CAAC,YAAY;GACjB,QAAQ,OAAO;IACX,MAAM;KACF;KACA,UAAU,QAAQ,WAAW,QAAQ,MAAM;KAC3C;IACJ;IACA,WAAW;IACX;GACJ,CAAC;EACL;EAEA,OAAO;GACH,2BAA2B;GAC3B,gCAAgC;GAChC,eAAe,MAAM;IACjB,MAAM,SAAS,QAAQ,GAAG,EAAE;IAC5B,IAAI,QAAQ,UAAU,MAAM,OAAO,IAAI;IACvC,IAAI,KAAK,OAAO,SAAS,gBAAgB,gBAAgB,IAAI,KAAK,OAAO,IAAI,GACzE,UAAU,KAAK;KACX,MAAM,KAAK,OAAO;KAClB;IACJ,CAAC;GAET;GACA,wBAAwB,SAAS;IAC7B,IAAI,UAAU,GAAG,EAAE,CAAC,EAAE,SAAS,MAAM,UAAU,IAAI;GACvD;GACA,sBAAsB;GACtB,2BAA2B;EAC/B;CACJ;CACA,MAAM;EACF,MAAM,EAAE,aAAa,sEAAsE;EAC3F,UAAU;GACN,QAAQ;GACR,gBAAgB;EACpB;EACA,QAAQ,CAAC;EACT,MAAM;CACV;AACJ"}
@@ -0,0 +1,3 @@
1
+ import { Rule } from "eslint";
2
+ export declare const noReactiveComposableReturn: Rule.RuleModule;
3
+ //# sourceMappingURL=no-reactive-composable-return.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-reactive-composable-return.d.ts","names":[],"sources":["../../../src/_internals/rules/no-reactive-composable-return.ts"],"mappings":";qBAsBa,4BAA4B,KAAK"}
@@ -0,0 +1,43 @@
1
+ import { composablePattern } from "./utils.js";
2
+ import { isReactiveProxy } from "./vue-reactivity.js";
3
+ // src/_internals/rules/no-reactive-composable-return.ts
4
+ function isExportedComposable(node) {
5
+ const { parent } = node;
6
+ if (parent.type === "ExportDefaultDeclaration") return true;
7
+ if (node.type === "FunctionDeclaration") return parent.type === "ExportNamedDeclaration" && !!node.id && composablePattern.test(node.id.name);
8
+ return parent.type === "VariableDeclarator" && parent.id.type === "Identifier" && composablePattern.test(parent.id.name) && parent.parent.parent?.type === "ExportNamedDeclaration";
9
+ }
10
+ const noReactiveComposableReturn = {
11
+ create(context) {
12
+ const services = context.sourceCode.parserServices;
13
+ if (!services?.program || !services.esTreeNodeToTSNodeMap) return {};
14
+ const checker = services.program.getTypeChecker();
15
+ const { esTreeNodeToTSNodeMap } = services;
16
+ function check(node) {
17
+ if (!isExportedComposable(node)) return;
18
+ const signature = checker.getSignatureFromDeclaration(esTreeNodeToTSNodeMap.get(node));
19
+ if (!signature || !isReactiveProxy(checker, checker.getReturnTypeOfSignature(signature))) return;
20
+ context.report({
21
+ messageId: "plainObject",
22
+ node: node.type === "FunctionDeclaration" && node.id ? node.id : node
23
+ });
24
+ }
25
+ return {
26
+ ArrowFunctionExpression: check,
27
+ FunctionDeclaration: check,
28
+ FunctionExpression: check
29
+ };
30
+ },
31
+ meta: {
32
+ docs: {
33
+ description: "Require exported composables to return a plain object of refs instead of a reactive proxy.",
34
+ requiresTypeChecking: true
35
+ },
36
+ messages: { plainObject: "Return a plain object of refs, as Vue recommends, so callers can destructure it without losing reactivity. A caller that wants property access can wrap the result in `reactive()`." },
37
+ schema: [],
38
+ type: "problem"
39
+ }
40
+ };
41
+ export { noReactiveComposableReturn };
42
+
43
+ //# sourceMappingURL=no-reactive-composable-return.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-reactive-composable-return.js","names":[],"sources":["../../../src/_internals/rules/no-reactive-composable-return.ts"],"sourcesContent":["import type { Rule } from 'eslint';\nimport type { SignatureDeclaration } from 'typescript';\n\nimport type { ParserServices } from './utils';\nimport { composablePattern } from './utils';\nimport { isReactiveProxy } from './vue-reactivity';\n\ntype FunctionNode = Extract<Rule.Node, { type: 'ArrowFunctionExpression' | 'FunctionDeclaration' | 'FunctionExpression' }>;\n\nfunction isExportedComposable(node: FunctionNode): boolean {\n const { parent } = node;\n if (parent.type === 'ExportDefaultDeclaration') return true;\n if (node.type === 'FunctionDeclaration') {\n return parent.type === 'ExportNamedDeclaration' && !!node.id && composablePattern.test(node.id.name);\n }\n\n return parent.type === 'VariableDeclarator'\n && parent.id.type === 'Identifier'\n && composablePattern.test(parent.id.name)\n && parent.parent.parent?.type === 'ExportNamedDeclaration';\n}\n\nexport const noReactiveComposableReturn: Rule.RuleModule = {\n create(context) {\n const services = context.sourceCode.parserServices as Partial<ParserServices> | undefined;\n if (!services?.program || !services.esTreeNodeToTSNodeMap) return {};\n const checker = services.program.getTypeChecker();\n const { esTreeNodeToTSNodeMap } = services;\n\n function check(node: FunctionNode): void {\n if (!isExportedComposable(node)) return;\n const signature = checker.getSignatureFromDeclaration(esTreeNodeToTSNodeMap.get(node) as SignatureDeclaration);\n if (!signature || !isReactiveProxy(checker, checker.getReturnTypeOfSignature(signature))) return;\n context.report({\n messageId: 'plainObject',\n node: node.type === 'FunctionDeclaration' && node.id ? node.id : node,\n });\n }\n\n return {\n ArrowFunctionExpression: check,\n FunctionDeclaration: check,\n FunctionExpression: check,\n };\n },\n meta: {\n docs: {\n description: 'Require exported composables to return a plain object of refs instead of a reactive proxy.',\n requiresTypeChecking: true,\n } as Rule.RuleMetaData['docs'],\n messages: { plainObject: 'Return a plain object of refs, as Vue recommends, so callers can destructure it without losing reactivity. A caller that wants property access can wrap the result in `reactive()`.' },\n schema: [],\n type: 'problem',\n },\n};\n"],"mappings":";;;AASA,SAAS,qBAAqB,MAA6B;CACvD,MAAM,EAAE,WAAW;CACnB,IAAI,OAAO,SAAS,4BAA4B,OAAO;CACvD,IAAI,KAAK,SAAS,uBACd,OAAO,OAAO,SAAS,4BAA4B,CAAC,CAAC,KAAK,MAAM,kBAAkB,KAAK,KAAK,GAAG,IAAI;CAGvG,OAAO,OAAO,SAAS,wBAClB,OAAO,GAAG,SAAS,gBACnB,kBAAkB,KAAK,OAAO,GAAG,IAAI,KACrC,OAAO,OAAO,QAAQ,SAAS;AACxC;AAEA,MAAa,6BAA8C;CACvD,OAAO,SAAS;EACZ,MAAM,WAAW,QAAQ,WAAW;EACpC,IAAI,CAAC,UAAU,WAAW,CAAC,SAAS,uBAAuB,OAAO,CAAC;EACnE,MAAM,UAAU,SAAS,QAAQ,eAAe;EAChD,MAAM,EAAE,0BAA0B;EAElC,SAAS,MAAM,MAA0B;GACrC,IAAI,CAAC,qBAAqB,IAAI,GAAG;GACjC,MAAM,YAAY,QAAQ,4BAA4B,sBAAsB,IAAI,IAAI,CAAyB;GAC7G,IAAI,CAAC,aAAa,CAAC,gBAAgB,SAAS,QAAQ,yBAAyB,SAAS,CAAC,GAAG;GAC1F,QAAQ,OAAO;IACX,WAAW;IACX,MAAM,KAAK,SAAS,yBAAyB,KAAK,KAAK,KAAK,KAAK;GACrE,CAAC;EACL;EAEA,OAAO;GACH,yBAAyB;GACzB,qBAAqB;GACrB,oBAAoB;EACxB;CACJ;CACA,MAAM;EACF,MAAM;GACF,aAAa;GACb,sBAAsB;EAC1B;EACA,UAAU,EAAE,aAAa,sLAAsL;EAC/M,QAAQ,CAAC;EACT,MAAM;CACV;AACJ"}
@@ -0,0 +1,3 @@
1
+ import { Rule } from "eslint";
2
+ export declare const noReactiveDestructure: Rule.RuleModule;
3
+ //# sourceMappingURL=no-reactive-destructure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-reactive-destructure.d.ts","names":[],"sources":["../../../src/_internals/rules/no-reactive-destructure.ts"],"mappings":";qBAkCa,uBAAuB,KAAK"}
@@ -0,0 +1,44 @@
1
+ import { composablePattern } from "./utils.js";
2
+ import { isReactiveProxy } from "./vue-reactivity.js";
3
+ // src/_internals/rules/no-reactive-destructure.ts
4
+ function runsOnce(node) {
5
+ let current = node.parent;
6
+ while (current) {
7
+ if (current.type === "ArrowFunctionExpression" || current.type === "FunctionDeclaration" || current.type === "FunctionExpression") {
8
+ const { parent } = current;
9
+ const name = current.type === "FunctionDeclaration" ? current.id?.name : parent.type === "VariableDeclarator" && parent.id.type === "Identifier" ? parent.id.name : parent.type === "Property" && parent.key.type === "Identifier" ? parent.key.name : void 0;
10
+ return !!name && (name === "setup" || composablePattern.test(name));
11
+ }
12
+ current = current.parent;
13
+ }
14
+ return true;
15
+ }
16
+ const noReactiveDestructure = {
17
+ create(context) {
18
+ const services = context.sourceCode.parserServices;
19
+ if (!services?.program || !services.esTreeNodeToTSNodeMap) return {};
20
+ const checker = services.program.getTypeChecker();
21
+ const { esTreeNodeToTSNodeMap } = services;
22
+ return { VariableDeclarator(node) {
23
+ if (!node.init || node.id.type !== "ObjectPattern" && node.id.type !== "ArrayPattern" || !runsOnce(node)) return;
24
+ if (node.init.type === "CallExpression" && node.init.callee.type === "Identifier" && node.init.callee.name === "toRaw") return;
25
+ if (!isReactiveProxy(checker, checker.getTypeAtLocation(esTreeNodeToTSNodeMap.get(node.init)))) return;
26
+ context.report({
27
+ messageId: "destructure",
28
+ node: node.id
29
+ });
30
+ } };
31
+ },
32
+ meta: {
33
+ docs: {
34
+ description: "Disallow destructuring values created by Vue's reactive(), shallowReactive(), readonly() and proxyRefs().",
35
+ requiresTypeChecking: true
36
+ },
37
+ messages: { destructure: "Destructuring a reactive object reads each property once and loses reactivity. Keep the object and access its properties where they are needed." },
38
+ schema: [],
39
+ type: "problem"
40
+ }
41
+ };
42
+ export { noReactiveDestructure };
43
+
44
+ //# sourceMappingURL=no-reactive-destructure.js.map