@kikiutils/eslint-config 12.0.4 → 12.0.5

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 (41) hide show
  1. package/README.md +3 -3
  2. package/dist/_internals/rules/comment-indent.d.ts.map +1 -1
  3. package/dist/_internals/rules/comment-indent.js +36 -27
  4. package/dist/_internals/rules/comment-indent.js.map +1 -1
  5. package/dist/_internals/rules/compact-iteration-layout.js +1 -0
  6. package/dist/_internals/rules/compact-iteration-layout.js.map +1 -1
  7. package/dist/_internals/rules/consistent-parameter-layout.js +23 -36
  8. package/dist/_internals/rules/consistent-parameter-layout.js.map +1 -1
  9. package/dist/_internals/rules/no-composable-in-head-getter.d.ts.map +1 -1
  10. package/dist/_internals/rules/no-composable-in-head-getter.js +20 -27
  11. package/dist/_internals/rules/no-composable-in-head-getter.js.map +1 -1
  12. package/dist/_internals/rules/no-silent-catch.js +2 -2
  13. package/dist/_internals/rules/no-silent-catch.js.map +1 -1
  14. package/dist/_internals/rules/no-thenable-zod-refinement.d.ts.map +1 -1
  15. package/dist/_internals/rules/no-thenable-zod-refinement.js.map +1 -1
  16. package/dist/_internals/rules/prefer-enhanced-date.d.ts.map +1 -1
  17. package/dist/_internals/rules/prefer-enhanced-date.js +38 -42
  18. package/dist/_internals/rules/prefer-enhanced-date.js.map +1 -1
  19. package/dist/_internals/rules/statement-padding.js +1 -1
  20. package/dist/_internals/rules/statement-padding.js.map +1 -1
  21. package/dist/_internals/rules/utils.d.ts +1 -1
  22. package/dist/_internals/rules/utils.js.map +1 -1
  23. package/dist/base.js.map +1 -1
  24. package/dist/nuxt.js +1 -4
  25. package/dist/nuxt.js.map +1 -1
  26. package/dist/vue.d.ts.map +1 -1
  27. package/dist/vue.js +3 -2
  28. package/dist/vue.js.map +1 -1
  29. package/package.json +4 -4
  30. package/src/_internals/rules/comment-indent.ts +44 -52
  31. package/src/_internals/rules/compact-iteration-layout.ts +1 -0
  32. package/src/_internals/rules/consistent-parameter-layout.ts +41 -66
  33. package/src/_internals/rules/no-composable-in-head-getter.ts +23 -28
  34. package/src/_internals/rules/no-silent-catch.ts +2 -3
  35. package/src/_internals/rules/no-thenable-zod-refinement.ts +1 -2
  36. package/src/_internals/rules/prefer-enhanced-date.ts +58 -88
  37. package/src/_internals/rules/statement-padding.ts +1 -1
  38. package/src/_internals/rules/utils.ts +1 -1
  39. package/src/base.ts +0 -2
  40. package/src/nuxt.ts +2 -6
  41. package/src/vue.ts +4 -4
package/README.md CHANGED
@@ -46,10 +46,10 @@ export default antfu(
46
46
  );
47
47
  ```
48
48
 
49
- - Only `createBaseConfigs()` is required; the other presets cover Vue, Nuxt, and CSS/SCSS files (indented `.sass` is not supported).
50
- - `createNuxtConfigs()` turns off the SSR-only rules when `nuxt.config.*` sets `ssr: false`; pass `{ ssr }` to override.
49
+ - Start with `createBaseConfigs()` and add the presets for Vue, Nuxt, or CSS/SCSS as needed.
50
+ - `createNuxtConfigs()` detects a literal top-level `ssr: false` in the exported config in the working directory. Pass `{ ssr }` when your project computes the setting.
51
51
  - Type-aware checks use TypeScript's Project Service, so linted TypeScript and Vue files must belong to a discoverable `tsconfig.json`.
52
- - `kikiutils/prefer-enhanced-date` fixes code to `EnhancedDate` from `@kikiutils/shared` v24 or later; install it, or turn the rule off.
52
+ - Install `@kikiutils/shared` v24 or later for the imports added by `kikiutils/prefer-enhanced-date`, or disable the rule.
53
53
 
54
54
  ## License
55
55
 
@@ -1 +1 @@
1
- {"version":3,"file":"comment-indent.d.ts","names":[],"sources":["../../../src/_internals/rules/comment-indent.ts"],"mappings":";qBAmBa,eAAe,KAAK"}
1
+ {"version":3,"file":"comment-indent.d.ts","names":[],"sources":["../../../src/_internals/rules/comment-indent.ts"],"mappings":";qBAca,eAAe,KAAK"}
@@ -13,35 +13,44 @@ const commentIndent = {
13
13
  create(context) {
14
14
  const { sourceCode } = context;
15
15
  const getIndent = (line) => /^[\t ]*/.exec(sourceCode.lines[line - 1])[0];
16
- const startsLine = (token) => {
17
- const previous = sourceCode.getTokenBefore(token, { includeComments: true });
18
- return !previous || previous.loc.end.line < token.loc.start.line;
19
- };
20
16
  return { Program() {
21
- for (const comment of sourceCode.getAllComments()) {
22
- if (!startsLine(comment)) continue;
23
- let anchor = sourceCode.getTokenBefore(comment, { includeComments: true });
24
- while ((anchor?.type === "Block" || anchor?.type === "Line") && startsLine(anchor)) anchor = sourceCode.getTokenBefore(anchor, { includeComments: true });
25
- if (anchor?.type !== "Punctuator" || !openingPunctuators.has(anchor.value)) continue;
26
- const next = sourceCode.getTokenAfter(comment);
27
- if (!next || closingPunctuators.has(next.value) || !startsLine(next)) continue;
28
- const { end, start } = comment.loc;
29
- if (sourceCode.lines.slice(end.line, next.loc.start.line - 1).some((text) => !text.trim())) continue;
30
- const indent = getIndent(start.line);
17
+ const comments = sourceCode.getAllComments();
18
+ for (let index = 0; index < comments.length;) {
19
+ const firstIndex = index++;
20
+ const first = comments[firstIndex];
21
+ const opening = sourceCode.getTokenBefore(first, { includeComments: true });
22
+ if (opening?.type !== "Punctuator" || !openingPunctuators.has(opening.value)) continue;
23
+ const next = sourceCode.getTokenAfter(first);
24
+ if (!next) break;
25
+ while (index < comments.length && comments[index].range[0] < next.range[0]) index++;
26
+ if (closingPunctuators.has(next.value) || comments[index - 1].loc.end.line === next.loc.start.line) continue;
27
+ let lastBlank = next.loc.start.line - 1;
28
+ while (lastBlank > first.loc.end.line && sourceCode.lines[lastBlank - 1].trim()) lastBlank--;
31
29
  const expected = getIndent(next.loc.start.line);
32
- if (indent === expected) continue;
33
- const commentLines = Array.from({ length: end.line - start.line + 1 }, (_, index) => start.line + index);
34
- context.report({
35
- fix: (fixer) => commentLines.filter((line) => sourceCode.lines[line - 1].startsWith(indent)).map((line) => {
36
- const offset = sourceCode.getIndexFromLoc({
37
- column: 0,
38
- line
39
- });
40
- return fixer.replaceTextRange([offset, offset + indent.length], expected);
41
- }),
42
- loc: comment.loc,
43
- messageId: "align"
44
- });
30
+ let previousEnd = opening.loc.end.line;
31
+ for (let position = firstIndex; position < index; position++) {
32
+ const comment = comments[position];
33
+ const { end, start } = comment.loc;
34
+ if (start.line === previousEnd) break;
35
+ previousEnd = end.line;
36
+ if (end.line < lastBlank) continue;
37
+ const indent = getIndent(start.line);
38
+ if (indent === expected) continue;
39
+ context.report({
40
+ *fix(fixer) {
41
+ for (let line = start.line; line <= end.line; line++) {
42
+ if (!sourceCode.lines[line - 1].startsWith(indent)) continue;
43
+ const offset = sourceCode.getIndexFromLoc({
44
+ column: 0,
45
+ line
46
+ });
47
+ yield fixer.replaceTextRange([offset, offset + indent.length], expected);
48
+ }
49
+ },
50
+ loc: comment.loc,
51
+ messageId: "align"
52
+ });
53
+ }
45
54
  }
46
55
  } };
47
56
  },
@@ -1 +1 @@
1
- {"version":3,"file":"comment-indent.js","names":[],"sources":["../../../src/_internals/rules/comment-indent.ts"],"sourcesContent":["import type {\n AST,\n Rule,\n} from 'eslint';\n\ntype Comment = ReturnType<Rule.RuleContext['sourceCode']['getAllComments']>[number];\n\nconst closingPunctuators = new Set([\n ')',\n ']',\n '}',\n]);\n\nconst openingPunctuators = new Set([\n '(',\n '[',\n '{',\n]);\n\nexport const commentIndent: Rule.RuleModule = {\n create(context) {\n const { sourceCode } = context;\n const getIndent = (line: number) => /^[\\t ]*/.exec(sourceCode.lines[line - 1]!)![0];\n const startsLine = (token: AST.Token | Comment) => {\n const previous = sourceCode.getTokenBefore(token, { includeComments: true });\n return !previous || previous.loc!.end.line < token.loc!.start.line;\n };\n\n return {\n Program() {\n for (const comment of sourceCode.getAllComments()) {\n if (!startsLine(comment)) continue;\n // style/indent lets a comment align with the opening bracket before it, which leaves comments\n // at the outer depth after a fixer nests the bracket's contents one level deeper.\n let anchor = sourceCode.getTokenBefore(comment, { includeComments: true });\n while ((anchor?.type === 'Block' || anchor?.type === 'Line') && startsLine(anchor)) {\n anchor = sourceCode.getTokenBefore(anchor, { includeComments: true });\n }\n\n if (anchor?.type !== 'Punctuator' || !openingPunctuators.has(anchor.value)) continue;\n const next = sourceCode.getTokenAfter(comment);\n if (!next || closingPunctuators.has(next.value) || !startsLine(next)) continue;\n const { end, start } = comment.loc!;\n // style/indent only lets a comment follow the next code when no blank line separates them.\n const gapLines = sourceCode.lines.slice(end.line, next.loc.start.line - 1);\n if (gapLines.some((text) => !text.trim())) continue;\n const indent = getIndent(start.line);\n const expected = getIndent(next.loc.start.line);\n if (indent === expected) continue;\n const commentLines = Array.from(\n { length: end.line - start.line + 1 },\n (_, index) => start.line + index,\n );\n\n context.report({\n // Shift a multiline block comment as a whole so its continuation lines stay aligned.\n fix: (fixer) => commentLines\n .filter((line) => sourceCode.lines[line - 1]!.startsWith(indent))\n .map((line) => {\n const offset = sourceCode.getIndexFromLoc({\n column: 0,\n line,\n });\n\n return fixer.replaceTextRange(\n [\n offset,\n offset + indent.length,\n ],\n expected,\n );\n }),\n loc: comment.loc!,\n messageId: 'align',\n });\n }\n },\n };\n },\n meta: {\n docs: { description: 'Align comments after an opening bracket with the code that follows them.' },\n fixable: 'whitespace',\n messages: { align: 'Indent this comment like the code that follows it.' },\n schema: [],\n type: 'layout',\n },\n};\n"],"mappings":";AAOA,MAAM,qCAAqB,IAAI,IAAI;CAC/B;CACA;CACA;AACJ,CAAC;AAED,MAAM,qCAAqB,IAAI,IAAI;CAC/B;CACA;CACA;AACJ,CAAC;AAED,MAAa,gBAAiC;CAC1C,OAAO,SAAS;EACZ,MAAM,EAAE,eAAe;EACvB,MAAM,aAAa,SAAiB,UAAU,KAAK,WAAW,MAAM,OAAO,EAAG,CAAC,CAAE;EACjF,MAAM,cAAc,UAA+B;GAC/C,MAAM,WAAW,WAAW,eAAe,OAAO,EAAE,iBAAiB,KAAK,CAAC;GAC3E,OAAO,CAAC,YAAY,SAAS,IAAK,IAAI,OAAO,MAAM,IAAK,MAAM;EAClE;EAEA,OAAO,EACH,UAAU;GACN,KAAK,MAAM,WAAW,WAAW,eAAe,GAAG;IAC/C,IAAI,CAAC,WAAW,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
1
+ {"version":3,"file":"comment-indent.js","names":[],"sources":["../../../src/_internals/rules/comment-indent.ts"],"sourcesContent":["import type { Rule } from 'eslint';\n\nconst closingPunctuators = new Set([\n ')',\n ']',\n '}',\n]);\n\nconst openingPunctuators = new Set([\n '(',\n '[',\n '{',\n]);\n\nexport const commentIndent: Rule.RuleModule = {\n create(context) {\n const { sourceCode } = context;\n const getIndent = (line: number) => /^[\\t ]*/.exec(sourceCode.lines[line - 1]!)![0];\n\n return {\n Program() {\n const comments = sourceCode.getAllComments();\n for (let index = 0; index < comments.length;) {\n const firstIndex = index++;\n const first = comments[firstIndex]!;\n const opening = sourceCode.getTokenBefore(first, { includeComments: true });\n if (opening?.type !== 'Punctuator' || !openingPunctuators.has(opening.value)) continue;\n const next = sourceCode.getTokenAfter(first);\n if (!next) break;\n while (index < comments.length && comments[index]!.range![0] < next.range[0]) index++;\n if (closingPunctuators.has(next.value) || comments[index - 1]!.loc!.end.line === next.loc.start.line) continue;\n\n // Only comments after the last blank line can take the following code's indentation.\n let lastBlank = next.loc.start.line - 1;\n while (lastBlank > first.loc!.end.line && sourceCode.lines[lastBlank - 1]!.trim()) lastBlank--;\n const expected = getIndent(next.loc.start.line);\n let previousEnd = opening.loc.end.line;\n for (let position = firstIndex; position < index; position++) {\n const comment = comments[position]!;\n const { end, start } = comment.loc!;\n if (start.line === previousEnd) break;\n previousEnd = end.line;\n if (end.line < lastBlank) continue;\n const indent = getIndent(start.line);\n if (indent === expected) continue;\n context.report({\n * fix(fixer) {\n for (let line = start.line; line <= end.line; line++) {\n if (!sourceCode.lines[line - 1]!.startsWith(indent)) continue;\n const offset = sourceCode.getIndexFromLoc({\n column: 0,\n line,\n });\n\n yield fixer.replaceTextRange(\n [\n offset,\n offset + indent.length,\n ],\n expected,\n );\n }\n },\n loc: comment.loc!,\n messageId: 'align',\n });\n }\n }\n },\n };\n },\n meta: {\n docs: { description: 'Align comments after an opening bracket with the code that follows them.' },\n fixable: 'whitespace',\n messages: { align: 'Ind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,IAAI,IAAI,OAAO,WAAW;KAC1B,MAAM,SAAS,UAAU,MAAM,IAAI;KACnC,IAAI,WAAW,UAAU;KACzB,QAAQ,OAAO;MACX,CAAE,IAAI,OAAO;OACT,KAAK,IAAI,OAAO,MAAM,MAAM,QAAQ,IAAI,MAAM,QAAQ;QAClD,IAAI,CAAC,WAAW,MAAM,OAAO,EAAE,CAAE,WAAW,MAAM,GAAG;QACrD,MAAM,SAAS,WAAW,gBAAgB;SACtC,QAAQ;SACR;QACJ,CAAC;QAED,MAAM,MAAM,iBACR,CACI,QACA,SAAS,OAAO,MACpB,GACA,QACJ;OACJ;MACJ;MACA,KAAK,QAAQ;MACb,WAAW;KACf,CAAC;IACL;GACJ;EACJ,EACJ;CACJ;CACA,MAAM;EACF,MAAM,EAAE,aAAa,2EAA2E;EAChG,SAAS;EACT,UAAU,EAAE,OAAO,qDAAqD;EACxE,QAAQ,CAAC;EACT,MAAM;CACV;AACJ"}
@@ -3,6 +3,7 @@ const compactIterationLayout = {
3
3
  create(context) {
4
4
  const { sourceCode } = context;
5
5
  function checkParentheses(node) {
6
+ if (node.loc.start.line === node.body.loc.start.line) return;
6
7
  const openingParen = sourceCode.getFirstToken(node, (token) => token.value === "(");
7
8
  const closingParen = sourceCode.getTokenBefore(node.body);
8
9
  const next = sourceCode.getTokenAfter(openingParen);
@@ -1 +1 @@
1
- {"version":3,"file":"compact-iteration-layout.js","names":[],"sources":["../../../src/_internals/rules/compact-iteration-layout.ts"],"sourcesContent":["import type { Rule } from 'eslint';\n\ntype IterationNode = Extract<Rule.Node, { type: 'ForInStatement' | 'ForOfStatement' }>;\n\nexport const compactIterationLayout: Rule.RuleModule = {\n create(context) {\n const { sourceCode } = context;\n\n function checkParentheses(node: IterationNode): void {\n const openingParen = sourceCode.getFirstToken(node, (token) => token.value === '(')!;\n const closingParen = sourceCode.getTokenBefore(node.body)!;\n const next = sourceCode.getTokenAfter(openingParen)!;\n const previous = sourceCode.getTokenBefore(closingParen)!;\n const ranges: Array<[number, number]> = [];\n\n if (\n openingParen.loc.end.line !== next.loc.start.line\n && !sourceCode.commentsExistBetween(openingParen, next)\n ) {\n ranges.push([\n openingParen.range[1],\n next.range[0],\n ]);\n }\n\n if (\n previous.loc.end.line !== closingParen.loc.start.line\n && !sourceCode.commentsExistBetween(previous, closingParen)\n ) {\n ranges.push([\n previous.range[1],\n closingParen.range[0],\n ]);\n }\n\n if (ranges.length) {\n context.report({\n fix: (fixer) => ranges.map((range) => fixer.replaceTextRange(range, '')),\n messageId: 'compact',\n node,\n });\n }\n }\n\n return {\n ForInStatement: checkParentheses,\n ForOfStatement: checkParentheses,\n };\n },\n meta: {\n docs: { description: 'Keep for-in and for-of parentheses beside their header contents.' },\n fixable: 'whitespace',\n messages: { compact: 'Keep iteration parentheses on the same lines as their adjacent header contents.' },\n schema: [],\n type: 'layout',\n },\n};\n"],"mappings":";AAIA,MAAa,yBAA0C;CACnD,OAAO,SAAS;EACZ,MAAM,EAAE,eAAe;EAEvB,SAAS,iBAAiB,MAA2B;GACjD,MAAM,eAAe,WAAW,cAAc,OAAO,UAAU,MAAM,UAAU,GAAG;GAClF,MAAM,eAAe,WAAW,eAAe,KAAK,IAAI;GACxD,MAAM,OAAO,WAAW,cAAc,YAAY;GAClD,MAAM,WAAW,WAAW,eAAe,YAAY;GACvD,MAAM,SAAkC,CAAC;GAEzC,IACI,aAAa,IAAI,IAAI,SAAS,KAAK,IAAI,MAAM,QAC1C,CAAC,WAAW,qBAAqB,cAAc,IAAI,GAEtD,OAAO,KAAK,CACR,aAAa,MAAM,IACnB,KAAK,MAAM,EACf,CAAC;GAGL,IACI,SAAS,IAAI,IAAI,SAAS,aAAa,IAAI,MAAM,QAC9C,CAAC,WAAW,qBAAqB,UAAU,YAAY,GAE1D,OAAO,KAAK,CACR,SAAS,MAAM,IACf,aAAa,MAAM,EACvB,CAAC;GAGL,IAAI,OAAO,QACP,QAAQ,OAAO;IACX,MAAM,UAAU,OAAO,KAAK,UAAU,MAAM,iBAAiB,OAAO,EAAE,CAAC;IACvE,WAAW;IACX;GACJ,CAAC;EAET;EAEA,OAAO;GACH,gBAAgB;GAChB,gBAAgB;EACpB;CACJ;CACA,MAAM;EACF,MAAM,EAAE,aAAa,mEAAmE;EACxF,SAAS;EACT,UAAU,EAAE,SAAS,kFAAkF;EACvG,QAAQ,CAAC;EACT,MAAM;CACV;AACJ"}
1
+ {"version":3,"file":"compact-iteration-layout.js","names":[],"sources":["../../../src/_internals/rules/compact-iteration-layout.ts"],"sourcesContent":["import type { Rule } from 'eslint';\n\ntype IterationNode = Extract<Rule.Node, { type: 'ForInStatement' | 'ForOfStatement' }>;\n\nexport const compactIterationLayout: Rule.RuleModule = {\n create(context) {\n const { sourceCode } = context;\n\n function checkParentheses(node: IterationNode): void {\n if (node.loc!.start.line === node.body.loc!.start.line) return;\n const openingParen = sourceCode.getFirstToken(node, (token) => token.value === '(')!;\n const closingParen = sourceCode.getTokenBefore(node.body)!;\n const next = sourceCode.getTokenAfter(openingParen)!;\n const previous = sourceCode.getTokenBefore(closingParen)!;\n const ranges: Array<[number, number]> = [];\n\n if (\n openingParen.loc.end.line !== next.loc.start.line\n && !sourceCode.commentsExistBetween(openingParen, next)\n ) {\n ranges.push([\n openingParen.range[1],\n next.range[0],\n ]);\n }\n\n if (\n previous.loc.end.line !== closingParen.loc.start.line\n && !sourceCode.commentsExistBetween(previous, closingParen)\n ) {\n ranges.push([\n previous.range[1],\n closingParen.range[0],\n ]);\n }\n\n if (ranges.length) {\n context.report({\n fix: (fixer) => ranges.map((range) => fixer.replaceTextRange(range, '')),\n messageId: 'compact',\n node,\n });\n }\n }\n\n return {\n ForInStatement: checkParentheses,\n ForOfStatement: checkParentheses,\n };\n },\n meta: {\n docs: { description: 'Keep for-in and for-of parentheses beside their header contents.' },\n fixable: 'whitespace',\n messages: { compact: 'Keep iteration parentheses on the same lines as their adjacent header contents.' },\n schema: [],\n type: 'layout',\n },\n};\n"],"mappings":";AAIA,MAAa,yBAA0C;CACnD,OAAO,SAAS;EACZ,MAAM,EAAE,eAAe;EAEvB,SAAS,iBAAiB,MAA2B;GACjD,IAAI,KAAK,IAAK,MAAM,SAAS,KAAK,KAAK,IAAK,MAAM,MAAM;GACxD,MAAM,eAAe,WAAW,cAAc,OAAO,UAAU,MAAM,UAAU,GAAG;GAClF,MAAM,eAAe,WAAW,eAAe,KAAK,IAAI;GACxD,MAAM,OAAO,WAAW,cAAc,YAAY;GAClD,MAAM,WAAW,WAAW,eAAe,YAAY;GACvD,MAAM,SAAkC,CAAC;GAEzC,IACI,aAAa,IAAI,IAAI,SAAS,KAAK,IAAI,MAAM,QAC1C,CAAC,WAAW,qBAAqB,cAAc,IAAI,GAEtD,OAAO,KAAK,CACR,aAAa,MAAM,IACnB,KAAK,MAAM,EACf,CAAC;GAGL,IACI,SAAS,IAAI,IAAI,SAAS,aAAa,IAAI,MAAM,QAC9C,CAAC,WAAW,qBAAqB,UAAU,YAAY,GAE1D,OAAO,KAAK,CACR,SAAS,MAAM,IACf,aAAa,MAAM,EACvB,CAAC;GAGL,IAAI,OAAO,QACP,QAAQ,OAAO;IACX,MAAM,UAAU,OAAO,KAAK,UAAU,MAAM,iBAAiB,OAAO,EAAE,CAAC;IACvE,WAAW;IACX;GACJ,CAAC;EAET;EAEA,OAAO;GACH,gBAAgB;GAChB,gBAAgB;EACpB;CACJ;CACA,MAAM;EACF,MAAM,EAAE,aAAa,mEAAmE;EACxF,SAAS;EACT,UAAU,EAAE,SAAS,kFAAkF;EACvG,QAAQ,CAAC;EACT,MAAM;CACV;AACJ"}
@@ -17,47 +17,35 @@ const consistentParameterLayout = {
17
17
  function checkTestCallLayout(node) {
18
18
  const items = node.arguments;
19
19
  if (!items.length) return;
20
+ if (node.loc.start.line === items[0].loc.start.line && items.every((item, index) => item.loc.end.line === (items[index + 1]?.loc.start.line ?? node.loc.end.line))) return;
20
21
  const openingParen = getCallOpeningParen(node);
21
22
  const closingParen = tokenStore.getLastToken(node);
22
23
  const previous = tokenStore.getTokenBefore(closingParen);
23
- const gaps = [[
24
- openingParen,
25
- tokenStore.getTokenAfter(openingParen),
26
- ""
27
- ], [
28
- previous,
29
- closingParen,
30
- ""
31
- ]];
24
+ const fixes = [];
25
+ function collectGap(left, right, text) {
26
+ if (tokenStore.commentsExistBetween(left, right)) return false;
27
+ if (left.loc.end.line !== right.loc.start.line) fixes.push({
28
+ range: [left.range[1], right.range[0]],
29
+ text
30
+ });
31
+ return true;
32
+ }
33
+ if (!collectGap(openingParen, tokenStore.getTokenAfter(openingParen), "") || !collectGap(previous, closingParen, "")) return;
32
34
  for (let index = 1; index < items.length; index++) {
33
- const comma = tokenStore.getTokensBetween(items[index - 1], items[index]).find((token) => token.type === "Punctuator" && token.value === ",");
34
- gaps.push([
35
- tokenStore.getTokenBefore(comma),
36
- comma,
37
- ""
38
- ], [
39
- comma,
40
- tokenStore.getTokenAfter(comma),
41
- " "
42
- ]);
35
+ const comma = tokenStore.getFirstTokenBetween(items[index - 1], items[index], (token) => token.type === "Punctuator" && token.value === ",");
36
+ if (!collectGap(tokenStore.getTokenBefore(comma), comma, "") || !collectGap(comma, tokenStore.getTokenAfter(comma), " ")) return;
43
37
  }
44
- if (previous.value === ",") gaps.push([
45
- tokenStore.getTokenBefore(previous),
46
- previous,
47
- ""
48
- ]);
49
- if (gaps.some(([left, right]) => tokenStore.commentsExistBetween(left, right))) return;
50
- const multilineGaps = gaps.filter(([left, right]) => left.loc.end.line !== right.loc.start.line);
51
- if (!multilineGaps.length) return;
38
+ if (previous.value === "," && !collectGap(tokenStore.getTokenBefore(previous), previous, "")) return;
39
+ if (!fixes.length) return;
52
40
  context.report({
53
- fix: (fixer) => multilineGaps.map(([left, right, text]) => fixer.replaceTextRange([left.range[1], right.range[0]], text)),
41
+ fix: () => fixes,
54
42
  messageId: "compactTestCall",
55
43
  node
56
44
  });
57
45
  }
58
46
  function checkParameterLayout(node, items) {
59
47
  const first = items[0];
60
- if (!first) return;
48
+ if (!first || node.loc.start.line === node.loc.end.line) return;
61
49
  const isSingleParameter = items.length === 1;
62
50
  const firstType = first.type;
63
51
  if (isSingleParameter && (firstType === "JSXElement" || firstType === "JSXFragment")) return;
@@ -67,14 +55,14 @@ const consistentParameterLayout = {
67
55
  if (!openingParen || openingParen.value !== "(") return;
68
56
  if (openingParen.range[0] < node.range[0]) return;
69
57
  const closingParen = node.type === "CallExpression" || node.type === "NewExpression" ? tokenStore.getLastToken(node) : tokenStore.getTokenAfter(items.at(-1), (token) => token.value === ")");
58
+ if (!closingParen || openingParen.loc.start.line === closingParen.loc.end.line) return;
70
59
  const next = tokenStore.getTokenAfter(openingParen);
71
60
  if (isSingleParameter) {
72
- if (!closingParen || closingParen.value !== ")") return;
73
- let previous = tokenStore.getTokenBefore(closingParen);
74
- if (previous.value === ",") previous = tokenStore.getTokenBefore(previous);
75
- if (tokenStore.commentsExistBetween(openingParen, next) || tokenStore.commentsExistBetween(previous, closingParen)) return;
61
+ if (closingParen.value !== ")") return;
62
+ const previous = tokenStore.getTokenBefore(closingParen);
76
63
  const hasOpeningNewline = openingParen.loc.end.line !== next.loc.start.line;
77
- if (hasOpeningNewline === (tokenStore.getTokenBefore(closingParen).loc.end.line !== closingParen.loc.start.line)) return;
64
+ if (hasOpeningNewline === (previous.loc.end.line !== closingParen.loc.start.line)) return;
65
+ if (tokenStore.commentsExistBetween(openingParen, next) || tokenStore.commentsExistBetween(previous.value === "," ? tokenStore.getTokenBefore(previous) : previous, closingParen)) return;
78
66
  context.report({
79
67
  fix: (fixer) => hasOpeningNewline ? fixer.insertTextBefore(closingParen, "\n") : fixer.insertTextAfter(openingParen, "\n"),
80
68
  messageId: "singleBoundary",
@@ -82,13 +70,12 @@ const consistentParameterLayout = {
82
70
  });
83
71
  return;
84
72
  }
85
- if (!closingParen || openingParen.loc.start.line === closingParen.loc.end.line) return;
86
73
  if (isTemplate) {
87
74
  const newlineOffsets = [];
88
75
  if (openingParen.loc.end.line === next.loc.start.line) newlineOffsets.push(openingParen.range[1]);
89
76
  for (let index = 1; index < items.length; index++) {
90
77
  const item = items[index];
91
- const comma = tokenStore.getTokensBetween(items[index - 1], item).find((token) => token.value === ",");
78
+ const comma = tokenStore.getFirstTokenBetween(items[index - 1], item, (token) => token.value === ",");
92
79
  if (comma && comma.loc.end.line === tokenStore.getTokenAfter(comma).loc.start.line) newlineOffsets.push(comma.range[1]);
93
80
  }
94
81
  if (closingParen.value === ")" && tokenStore.getTokenBefore(closingParen).loc.end.line === closingParen.loc.start.line) newlineOffsets.push(closingParen.range[0]);
@@ -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 {\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,iBAAiB,KAAK,SAC1B,UAAU,MAAM,SAAS,gBAAgB,MAAM,UAAU,GAC9D;GAEA,SAAS,oBAAoB,MAAsB;IAC/C,MAAM,QAAQ,KAAK;IACnB,IAAI,CAAC,MAAM,QAAQ;IACnB,MAAM,eAAe,oBAAoB,IAAI;IAE7C,MAAM,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AAM,IAAI,IAAI,SAAS,WAAW,cAAc,KAAK,CAAC,CAAE,IAAI,MAAM,MAC3E,eAAe,KAAK,MAAM,MAAM,EAAE;KAE1C;KAEA,IACI,aAAa,UAAU,OACpB,WAAW,eAAe,YAAY,CAAC,CAAE,IAAI,IAAI,SAAS,aAAa,IAAI,MAAM,MACtF,eAAe,KAAK,aAAa,MAAM,EAAE;KAE3C,IAAI,eAAe,QACf,QAAQ,OAAO;MACX,KAAK,eAAe,cAAc;MAClC,WAAW;MACX,MAAM;KACV,CAAC;KAGL;IACJ;IAEA,IAAI,aAAa,IAAI,IAAI,SAAS,KAAK,IAAI,MAAM,MAAM;IAEvD,QAAQ,OAAO;KACX,MAAM,UAAU,MAAM,gBAAgB,cAAc,IAAI;KACxD,WAAW;KACX,MAAM;IACV,CAAC;GACL;GAEA,OAAO;IACH,0BAA0B,SAAS,qBAAqB,MAAM,KAAK,MAAM;IACzE,iBAAiB,SAAS;KACtB,IAAI,oBAAoB,WAAW,KAAK,MAAM,GAAG;MAC7C,oBAAoB,IAAI;MACxB;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 if (\n node.loc!.start.line === items[0]!.loc!.start.line\n && items.every((item, index) => item.loc!.end.line === (items[index + 1]?.loc!.start.line ?? node.loc!.end.line))\n ) return;\n\n const openingParen = getCallOpeningParen(node)!;\n\n const closingParen = tokenStore.getLastToken(node)!;\n const previous = tokenStore.getTokenBefore(closingParen)!;\n const fixes: Rule.Fix[] = [];\n\n function collectGap(left: AST.Token, right: AST.Token, text: string): boolean {\n // A boundary comment keeps the whole list in its original layout.\n if (tokenStore.commentsExistBetween(left, right)) return false;\n if (left.loc.end.line !== right.loc.start.line) {\n fixes.push({\n range: [\n left.range[1],\n right.range[0],\n ],\n text,\n });\n }\n\n return true;\n }\n\n if (!collectGap(openingParen, tokenStore.getTokenAfter(openingParen)!, '') || !collectGap(previous, closingParen, '')) return;\n for (let index = 1; index < items.length; index++) {\n const comma = tokenStore.getFirstTokenBetween(\n items[index - 1]!,\n items[index]!,\n (token) => token.type === 'Punctuator' && token.value === ',',\n )!;\n\n if (!collectGap(tokenStore.getTokenBefore(comma)!, comma, '') || !collectGap(comma, tokenStore.getTokenAfter(comma)!, ' ')) return;\n }\n\n if (previous.value === ',' && !collectGap(tokenStore.getTokenBefore(previous)!, previous, '')) return;\n if (!fixes.length) return;\n context.report({\n fix: () => fixes,\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 || node.loc!.start.line === node.loc!.end.line) 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 if (!closingParen || openingParen.loc.start.line === closingParen.loc.end.line) return;\n const next = tokenStore.getTokenAfter(openingParen)!;\n if (isSingleParameter) {\n if (closingParen.value !== ')') return;\n const previous = tokenStore.getTokenBefore(closingParen)!;\n const hasOpeningNewline = openingParen.loc.end.line !== next.loc.start.line;\n const hasClosingNewline = previous.loc.end.line !== closingParen.loc.start.line;\n if (hasOpeningNewline === hasClosingNewline) return;\n if (\n tokenStore.commentsExistBetween(openingParen, next)\n || tokenStore.commentsExistBetween(previous.value === ',' ? tokenStore.getTokenBefore(previous)! : previous, closingParen)\n ) 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 (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.getFirstTokenBetween(items[index - 1]!, item, (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,iBAAiB,KAAK,SAC1B,UAAU,MAAM,SAAS,gBAAgB,MAAM,UAAU,GAC9D;GAEA,SAAS,oBAAoB,MAAsB;IAC/C,MAAM,QAAQ,KAAK;IACnB,IAAI,CAAC,MAAM,QAAQ;IACnB,IACI,KAAK,IAAK,MAAM,SAAS,MAAM,EAAE,CAAE,IAAK,MAAM,QAC3C,MAAM,OAAO,MAAM,UAAU,KAAK,IAAK,IAAI,UAAU,MAAM,QAAQ,EAAE,EAAE,IAAK,MAAM,QAAQ,KAAK,IAAK,IAAI,KAAK,GAClH;IAEF,MAAM,eAAe,oBAAoB,IAAI;IAE7C,MAAM,eAAe,WAAW,aAAa,IAAI;IACjD,MAAM,WAAW,WAAW,eAAe,YAAY;IACvD,MAAM,QAAoB,CAAC;IAE3B,SAAS,WAAW,MAAiB,OAAkB,MAAuB;KAE1E,IAAI,WAAW,qBAAqB,MAAM,KAAK,GAAG,OAAO;KACzD,IAAI,KAAK,IAAI,IAAI,SAAS,MAAM,IAAI,MAAM,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ACX,KAAK,eAAe,cAAc;MAClC,WAAW;MACX,MAAM;KACV,CAAC;KAGL;IACJ;IAEA,IAAI,aAAa,IAAI,IAAI,SAAS,KAAK,IAAI,MAAM,MAAM;IAEvD,QAAQ,OAAO;KACX,MAAM,UAAU,MAAM,gBAAgB,cAAc,IAAI;KACxD,WAAW;KACX,MAAM;IACV,CAAC;GACL;GAEA,OAAO;IACH,0BAA0B,SAAS,qBAAqB,MAAM,KAAK,MAAM;IACzE,iBAAiB,SAAS;KACtB,IAAI,oBAAoB,WAAW,KAAK,MAAM,GAAG;MAC7C,oBAAoB,IAAI;MACxB;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 +1 @@
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
+ {"version":3,"file":"no-composable-in-head-getter.d.ts","names":[],"sources":["../../../src/_internals/rules/no-composable-in-head-getter.ts"],"mappings":";qBA2Da,0BAA0B,KAAK"}
@@ -9,20 +9,10 @@ const headComposables = /* @__PURE__ */ new Set([
9
9
  "useServerHeadSafe",
10
10
  "useServerSeoMeta"
11
11
  ]);
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
- }
12
+ function findCalledComposable(node) {
13
+ if (ts.isFunctionLike(node)) return;
14
+ if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && composablePattern.test(node.expression.text)) return node.expression.text;
15
+ return ts.forEachChild(node, findCalledComposable);
26
16
  }
27
17
  function getBody(node) {
28
18
  if (node && ts.isFunctionLike(node) && "body" in node) return node.body;
@@ -35,10 +25,10 @@ function getImplementationBodies(checker, call) {
35
25
  if (ts.isVariableDeclaration(declaration) || ts.isPropertyAssignment(declaration)) return declaration.initializer;
36
26
  return getBody(declaration) && declaration;
37
27
  });
38
- if (values.some(Boolean)) return values.map((value) => getBody(value)).filter((body) => body !== void 0);
28
+ if (values.some(Boolean)) return values.map(getBody).filter((body) => body !== void 0);
39
29
  const declaration = checker.getResolvedSignature(call)?.getDeclaration();
40
30
  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);
31
+ return (name ? checker.getSymbolAtLocation(name)?.declarations ?? [] : [declaration]).map(getBody).filter((body) => body !== void 0);
42
32
  }
43
33
  const noComposableInHeadGetter = {
44
34
  create(context) {
@@ -74,17 +64,20 @@ const noComposableInHeadGetter = {
74
64
  return;
75
65
  }
76
66
  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
- });
67
+ for (const body of getImplementationBodies(checker, nodeMap.get(node))) {
68
+ const composable = findCalledComposable(body);
69
+ if (!composable) continue;
70
+ context.report({
71
+ data: {
72
+ composable,
73
+ function: context.sourceCode.getText(callee),
74
+ head
75
+ },
76
+ messageId: "indirectGetter",
77
+ node
78
+ });
79
+ return;
80
+ }
88
81
  }
89
82
  return {
90
83
  "ArrowFunctionExpression": enterFunction,
@@ -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';\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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"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(node: ts.Node): string | undefined {\n if (ts.isFunctionLike(node)) return;\n if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && composablePattern.test(node.expression.text)) {\n return node.expression.text;\n }\n\n return ts.forEachChild(node, findCalledComposable);\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(getBody)\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(getBody)\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 for (const body of getImplementationBodies(checker, nodeMap.get(node) as ts.CallExpression)) {\n const composable = findCalledComposable(body);\n if (!composable) continue;\n context.report({\n data: {\n composable,\n function: context.sourceCode.getText(callee),\n head,\n },\n messageId: 'indirectGetter',\n node,\n });\n\n return;\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,MAAmC;CAC7D,IAAI,GAAG,eAAe,IAAI,GAAG;CAC7B,IAAI,GAAG,iBAAiB,IAAI,KAAK,GAAG,aAAa,KAAK,UAAU,KAAK,kBAAkB,KAAK,KAAK,WAAW,IAAI,GAC5G,OAAO,KAAK,WAAW;CAG3B,OAAO,GAAG,aAAa,MAAM,oBAAoB;AACrD;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,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I,CAAsB,GAAG;IACzF,MAAM,aAAa,qBAAqB,IAAI;IAC5C,IAAI,CAAC,YAAY;IACjB,QAAQ,OAAO;KACX,MAAM;MACF;MACA,UAAU,QAAQ,WAAW,QAAQ,MAAM;MAC3C;KACJ;KACA,WAAW;KACX;IACJ,CAAC;IAED;GACJ;EACJ;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"}
@@ -10,8 +10,8 @@ function isSilent(callback) {
10
10
  if (callback.type !== "ArrowFunctionExpression" && callback.type !== "FunctionExpression") return false;
11
11
  const { body } = callback;
12
12
  if (body.type !== "BlockStatement") return isNothing(body);
13
- const [statement, ...rest] = body.body;
14
- return !statement || !rest.length && statement.type === "ReturnStatement" && isNothing(statement.argument);
13
+ const [statement] = body.body;
14
+ return !statement || body.body.length === 1 && statement.type === "ReturnStatement" && isNothing(statement.argument);
15
15
  }
16
16
  const noSilentCatch = {
17
17
  create(context) {
@@ -1 +1 @@
1
- {"version":3,"file":"no-silent-catch.js","names":[],"sources":["../../../src/_internals/rules/no-silent-catch.ts"],"sourcesContent":["import type { Rule } from 'eslint';\n\nimport { isMemberNamed } from './utils';\n\ntype CallArgument = Extract<Rule.Node, { type: 'CallExpression' }>['arguments'][number];\ntype Expression = Exclude<CallArgument, { type: 'SpreadElement' }>;\n\nfunction isNothing(node: Expression | null | undefined): boolean {\n if (!node) return true;\n if (node.type === 'Identifier') return node.name === 'undefined';\n if (node.type === 'Literal') return node.raw === 'null';\n return node.type === 'UnaryExpression' && node.operator === 'void' && node.argument.type === 'Literal';\n}\n\nfunction isSilent(callback: CallArgument): boolean {\n if (callback.type !== 'ArrowFunctionExpression' && callback.type !== 'FunctionExpression') return false;\n const { body } = callback;\n if (body.type !== 'BlockStatement') return isNothing(body);\n const [statement, ...rest] = body.body;\n return !statement || (!rest.length && statement.type === 'ReturnStatement' && isNothing(statement.argument));\n}\n\nexport const noSilentCatch: Rule.RuleModule = {\n create(context) {\n return {\n CallExpression(node) {\n const { callee } = node;\n const callback = node.arguments[0];\n if (\n !isMemberNamed(callee, 'catch')\n || !callback\n || !isSilent(callback)\n ) return;\n\n // A comment right before or inside the callback is the reason the rejection can be ignored.\n const { sourceCode } = context;\n if (sourceCode.getCommentsBefore(callback).length || sourceCode.getCommentsInside(callback).length) return;\n\n context.report({\n messageId: 'silent',\n node: callback,\n });\n },\n };\n },\n meta: {\n docs: { description: 'Disallow `.catch()` callbacks that silently swallow the rejection.' },\n messages: { silent: 'Do not swallow the rejection silently: log it, or add a comment before or inside the callback explaining why it can be ignored.' },\n schema: [],\n type: 'problem',\n },\n};\n"],"mappings":";;AAOA,SAAS,UAAU,MAA8C;CAC7D,IAAI,CAAC,MAAM,OAAO;CAClB,IAAI,KAAK,SAAS,cAAc,OAAO,KAAK,SAAS;CACrD,IAAI,KAAK,SAAS,WAAW,OAAO,KAAK,QAAQ;CACjD,OAAO,KAAK,SAAS,qBAAqB,KAAK,aAAa,UAAU,KAAK,SAAS,SAAS;AACjG;AAEA,SAAS,SAAS,UAAiC;CAC/C,IAAI,SAAS,SAAS,6BAA6B,SAAS,SAAS,sBAAsB,OAAO;CAClG,MAAM,EAAE,SAAS;CACjB,IAAI,KAAK,SAAS,kBAAkB,OAAO,UAAU,IAAI;CACzD,MAAM,CAAC,WAAW,GAAG,QAAQ,KAAK;CAClC,OAAO,CAAC,aAAc,CAAC,KAAK,UAAU,UAAU,SAAS,qBAAqB,UAAU,UAAU,QAAQ;AAC9G;AAEA,MAAa,gBAAiC;CAC1C,OAAO,SAAS;EACZ,OAAO,EACH,eAAe,MAAM;GACjB,MAAM,EAAE,WAAW;GACnB,MAAM,WAAW,KAAK,UAAU;GAChC,IACI,CAAC,cAAc,QAAQ,OAAO,KAC3B,CAAC,YACD,CAAC,SAAS,QAAQ,GACvB;GAGF,MAAM,EAAE,eAAe;GACvB,IAAI,WAAW,kBAAkB,QAAQ,CAAC,CAAC,UAAU,WAAW,kBAAkB,QAAQ,CAAC,CAAC,QAAQ;GAEpG,QAAQ,OAAO;IACX,WAAW;IACX,MAAM;GACV,CAAC;EACL,EACJ;CACJ;CACA,MAAM;EACF,MAAM,EAAE,aAAa,qEAAqE;EAC1F,UAAU,EAAE,QAAQ,kIAAkI;EACtJ,QAAQ,CAAC;EACT,MAAM;CACV;AACJ"}
1
+ {"version":3,"file":"no-silent-catch.js","names":[],"sources":["../../../src/_internals/rules/no-silent-catch.ts"],"sourcesContent":["import type { Rule } from 'eslint';\n\nimport { isMemberNamed } from './utils';\n\ntype CallArgument = Extract<Rule.Node, { type: 'CallExpression' }>['arguments'][number];\ntype Expression = Exclude<CallArgument, { type: 'SpreadElement' }>;\n\nfunction isNothing(node: Expression | null | undefined): boolean {\n if (!node) return true;\n if (node.type === 'Identifier') return node.name === 'undefined';\n if (node.type === 'Literal') return node.raw === 'null';\n return node.type === 'UnaryExpression' && node.operator === 'void' && node.argument.type === 'Literal';\n}\n\nfunction isSilent(callback: CallArgument): boolean {\n if (callback.type !== 'ArrowFunctionExpression' && callback.type !== 'FunctionExpression') return false;\n const { body } = callback;\n if (body.type !== 'BlockStatement') return isNothing(body);\n const [statement] = body.body;\n return !statement || (body.body.length === 1 && statement.type === 'ReturnStatement' && isNothing(statement.argument));\n}\n\nexport const noSilentCatch: Rule.RuleModule = {\n create(context) {\n return {\n CallExpression(node) {\n const { callee } = node;\n const callback = node.arguments[0];\n if (\n !isMemberNamed(callee, 'catch')\n || !callback\n || !isSilent(callback)\n ) return;\n\n const { sourceCode } = context;\n if (sourceCode.getCommentsBefore(callback).length || sourceCode.getCommentsInside(callback).length) return;\n\n context.report({\n messageId: 'silent',\n node: callback,\n });\n },\n };\n },\n meta: {\n docs: { description: 'Disallow `.catch()` callbacks that silently swallow the rejection.' },\n messages: { silent: 'Do not swallow the rejection silently: log it, or add a comment before or inside the callback explaining why it can be ignored.' },\n schema: [],\n type: 'problem',\n },\n};\n"],"mappings":";;AAOA,SAAS,UAAU,MAA8C;CAC7D,IAAI,CAAC,MAAM,OAAO;CAClB,IAAI,KAAK,SAAS,cAAc,OAAO,KAAK,SAAS;CACrD,IAAI,KAAK,SAAS,WAAW,OAAO,KAAK,QAAQ;CACjD,OAAO,KAAK,SAAS,qBAAqB,KAAK,aAAa,UAAU,KAAK,SAAS,SAAS;AACjG;AAEA,SAAS,SAAS,UAAiC;CAC/C,IAAI,SAAS,SAAS,6BAA6B,SAAS,SAAS,sBAAsB,OAAO;CAClG,MAAM,EAAE,SAAS;CACjB,IAAI,KAAK,SAAS,kBAAkB,OAAO,UAAU,IAAI;CACzD,MAAM,CAAC,aAAa,KAAK;CACzB,OAAO,CAAC,aAAc,KAAK,KAAK,WAAW,KAAK,UAAU,SAAS,qBAAqB,UAAU,UAAU,QAAQ;AACxH;AAEA,MAAa,gBAAiC;CAC1C,OAAO,SAAS;EACZ,OAAO,EACH,eAAe,MAAM;GACjB,MAAM,EAAE,WAAW;GACnB,MAAM,WAAW,KAAK,UAAU;GAChC,IACI,CAAC,cAAc,QAAQ,OAAO,KAC3B,CAAC,YACD,CAAC,SAAS,QAAQ,GACvB;GAEF,MAAM,EAAE,eAAe;GACvB,IAAI,WAAW,kBAAkB,QAAQ,CAAC,CAAC,UAAU,WAAW,kBAAkB,QAAQ,CAAC,CAAC,QAAQ;GAEpG,QAAQ,OAAO;IACX,WAAW;IACX,MAAM;GACV,CAAC;EACL,EACJ;CACJ;CACA,MAAM;EACF,MAAM,EAAE,aAAa,qEAAqE;EAC1F,UAAU,EAAE,QAAQ,kIAAkI;EACtJ,QAAQ,CAAC;EACT,MAAM;CACV;AACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"no-thenable-zod-refinement.d.ts","names":[],"sources":["../../../src/_internals/rules/no-thenable-zod-refinement.ts"],"mappings":";qBA8Ba,yBAAyB,KAAK"}
1
+ {"version":3,"file":"no-thenable-zod-refinement.d.ts","names":[],"sources":["../../../src/_internals/rules/no-thenable-zod-refinement.ts"],"mappings":";qBA6Ba,yBAAyB,KAAK"}
@@ -1 +1 @@
1
- {"version":3,"file":"no-thenable-zod-refinement.js","names":[],"sources":["../../../src/_internals/rules/no-thenable-zod-refinement.ts"],"sourcesContent":["import type { Rule } from 'eslint';\nimport type {\n Type,\n TypeChecker,\n TypeReference,\n} from 'typescript';\n\nimport type { ParserServices } from './utils';\n\nconst refinementMethods = new Set([\n 'check',\n 'refine',\n 'superRefine',\n]);\n\nfunction isNonPromiseThenable(checker: TypeChecker, type: Type): boolean {\n return (type.isUnion() ? type.types : [type]).some(\n (part) => part.getProperty('then') && !isPromise(checker, part),\n );\n}\n\n// Zod awaits a refinement only when it returns a native Promise (`instanceof Promise`, so subtypes and branded\n// intersections such as `SafePromise` count); any other thenable counts as a truthy result.\nfunction isPromise(checker: TypeChecker, type: Type): boolean {\n if (type.isIntersection()) return type.types.some((part) => isPromise(checker, part));\n if (type.getSymbol()?.getName() === 'Promise') return true;\n const target = (type as TypeReference).target ?? type;\n return target.isClassOrInterface() && checker.getBaseTypes(target).some((base) => isPromise(checker, base));\n}\n\nexport const noThenableZodRefinement: Rule.RuleModule = {\n create(context) {\n const services = context.sourceCode.parserServices as ParserServices;\n const checker = services.program.getTypeChecker();\n const getType = (node: unknown) => checker.getTypeAtLocation(services.esTreeNodeToTSNodeMap.get(node));\n\n return {\n CallExpression(node) {\n const { callee } = node;\n if (\n callee.type !== 'MemberExpression'\n || callee.computed\n || callee.property.type !== 'Identifier'\n || !refinementMethods.has(callee.property.name)\n // Covers schema methods such as `z.objectId().refine()` and standalone checks such as `z.refine()`.\n || !getType(node).getProperty('_zod')\n ) return;\n\n const method = callee.property.name;\n // `.check()` takes several checks; non-function checks have no call signatures.\n for (const callback of node.arguments) {\n const returnsThenable = getType(callback)\n .getCallSignatures()\n .some((signature) => isNonPromiseThenable(checker, checker.getReturnTypeOfSignature(signature)));\n\n if (!returnsThenable) continue;\n context.report({\n data: { method },\n messageId: 'thenable',\n node: callback,\n });\n }\n },\n };\n },\n meta: {\n docs: {\n description: 'Disallow Zod refinements and checks that return a thenable other than a Promise.',\n requiresTypeChecking: true,\n } as Rule.RuleMetaData['docs'],\n messages: { thenable: 'Zod only awaits a native Promise, so this `{{ method }}()` callback\\'s thenable (such as a Mongoose Query) counts as a passing check. Make the callback `async` and `await` the value.' },\n schema: [],\n type: 'problem',\n },\n};\n"],"mappings":";AASA,MAAM,oCAAoB,IAAI,IAAI;CAC9B;CACA;CACA;AACJ,CAAC;AAED,SAAS,qBAAqB,SAAsB,MAAqB;CACrE,QAAQ,KAAK,QAAQ,IAAI,KAAK,QAAQ,CAAC,IAAI,EAAA,CAAG,MACzC,SAAS,KAAK,YAAY,MAAM,KAAK,CAAC,UAAU,SAAS,IAAI,CAClE;AACJ;AAIA,SAAS,UAAU,SAAsB,MAAqB;CAC1D,IAAI,KAAK,eAAe,GAAG,OAAO,KAAK,MAAM,MAAM,SAAS,UAAU,SAAS,IAAI,CAAC;CACpF,IAAI,KAAK,UAAU,CAAC,EAAE,QAAQ,MAAM,WAAW,OAAO;CACtD,MAAM,SAAU,KAAuB,UAAU;CACjD,OAAO,OAAO,mBAAmB,KAAK,QAAQ,aAAa,MAAM,CAAC,CAAC,MAAM,SAAS,UAAU,SAAS,IAAI,CAAC;AAC9G;AAEA,MAAa,0BAA2C;CACpD,OAAO,SAAS;EACZ,MAAM,WAAW,QAAQ,WAAW;EACpC,MAAM,UAAU,SAAS,QAAQ,eAAe;EAChD,MAAM,WAAW,SAAkB,QAAQ,kBAAkB,SAAS,sBAAsB,IAAI,IAAI,CAAC;EAErG,OAAO,EACH,eAAe,MAAM;GACjB,MAAM,EAAE,WAAW;GACnB,IACI,OAAO,SAAS,sBACb,OAAO,YACP,OAAO,SAAS,SAAS,gBACzB,CAAC,kBAAkB,IAAI,OAAO,SAAS,IAAI,KAE3C,CAAC,QAAQ,IAAI,CAAC,CAAC,YAAY,MAAM,GACtC;GAEF,MAAM,SAAS,OAAO,SAAS;GAE/B,KAAK,MAAM,YAAY,KAAK,WAAW;IAKnC,IAAI,CAJoB,QAAQ,QAAQ,CAAC,CACpC,kBAAkB,CAAC,CACnB,MAAM,cAAc,qBAAqB,SAAS,QAAQ,yBAAyB,SAAS,CAAC,CAE/E,GAAG;IACtB,QAAQ,OAAO;KACX,MAAM,EAAE,OAAO;KACf,WAAW;KACX,MAAM;IACV,CAAC;GACL;EACJ,EACJ;CACJ;CACA,MAAM;EACF,MAAM;GACF,aAAa;GACb,sBAAsB;EAC1B;EACA,UAAU,EAAE,UAAU,wLAAyL;EAC/M,QAAQ,CAAC;EACT,MAAM;CACV;AACJ"}
1
+ {"version":3,"file":"no-thenable-zod-refinement.js","names":[],"sources":["../../../src/_internals/rules/no-thenable-zod-refinement.ts"],"sourcesContent":["import type { Rule } from 'eslint';\nimport type {\n Type,\n TypeChecker,\n TypeReference,\n} from 'typescript';\n\nimport type { ParserServices } from './utils';\n\nconst refinementMethods = new Set([\n 'check',\n 'refine',\n 'superRefine',\n]);\n\nfunction isNonPromiseThenable(checker: TypeChecker, type: Type): boolean {\n return (type.isUnion() ? type.types : [type]).some(\n (part) => part.getProperty('then') && !isPromise(checker, part),\n );\n}\n\n// Zod uses `instanceof Promise`, which also accepts subclasses and branded Promise values.\nfunction isPromise(checker: TypeChecker, type: Type): boolean {\n if (type.isIntersection()) return type.types.some((part) => isPromise(checker, part));\n if (type.getSymbol()?.getName() === 'Promise') return true;\n const target = (type as TypeReference).target ?? type;\n return target.isClassOrInterface() && checker.getBaseTypes(target).some((base) => isPromise(checker, base));\n}\n\nexport const noThenableZodRefinement: Rule.RuleModule = {\n create(context) {\n const services = context.sourceCode.parserServices as ParserServices;\n const checker = services.program.getTypeChecker();\n const getType = (node: unknown) => checker.getTypeAtLocation(services.esTreeNodeToTSNodeMap.get(node));\n\n return {\n CallExpression(node) {\n const { callee } = node;\n if (\n callee.type !== 'MemberExpression'\n || callee.computed\n || callee.property.type !== 'Identifier'\n || !refinementMethods.has(callee.property.name)\n // Covers schema methods such as `z.objectId().refine()` and standalone checks such as `z.refine()`.\n || !getType(node).getProperty('_zod')\n ) return;\n\n const method = callee.property.name;\n // `.check()` takes several checks; non-function checks have no call signatures.\n for (const callback of node.arguments) {\n const returnsThenable = getType(callback)\n .getCallSignatures()\n .some((signature) => isNonPromiseThenable(checker, checker.getReturnTypeOfSignature(signature)));\n\n if (!returnsThenable) continue;\n context.report({\n data: { method },\n messageId: 'thenable',\n node: callback,\n });\n }\n },\n };\n },\n meta: {\n docs: {\n description: 'Disallow Zod refinements and checks that return a thenable other than a Promise.',\n requiresTypeChecking: true,\n } as Rule.RuleMetaData['docs'],\n messages: { thenable: 'Zod only awaits a native Promise, so this `{{ method }}()` callback\\'s thenable (such as a Mongoose Query) counts as a passing check. Make the callback `async` and `await` the value.' },\n schema: [],\n type: 'problem',\n },\n};\n"],"mappings":";AASA,MAAM,oCAAoB,IAAI,IAAI;CAC9B;CACA;CACA;AACJ,CAAC;AAED,SAAS,qBAAqB,SAAsB,MAAqB;CACrE,QAAQ,KAAK,QAAQ,IAAI,KAAK,QAAQ,CAAC,IAAI,EAAA,CAAG,MACzC,SAAS,KAAK,YAAY,MAAM,KAAK,CAAC,UAAU,SAAS,IAAI,CAClE;AACJ;AAGA,SAAS,UAAU,SAAsB,MAAqB;CAC1D,IAAI,KAAK,eAAe,GAAG,OAAO,KAAK,MAAM,MAAM,SAAS,UAAU,SAAS,IAAI,CAAC;CACpF,IAAI,KAAK,UAAU,CAAC,EAAE,QAAQ,MAAM,WAAW,OAAO;CACtD,MAAM,SAAU,KAAuB,UAAU;CACjD,OAAO,OAAO,mBAAmB,KAAK,QAAQ,aAAa,MAAM,CAAC,CAAC,MAAM,SAAS,UAAU,SAAS,IAAI,CAAC;AAC9G;AAEA,MAAa,0BAA2C;CACpD,OAAO,SAAS;EACZ,MAAM,WAAW,QAAQ,WAAW;EACpC,MAAM,UAAU,SAAS,QAAQ,eAAe;EAChD,MAAM,WAAW,SAAkB,QAAQ,kBAAkB,SAAS,sBAAsB,IAAI,IAAI,CAAC;EAErG,OAAO,EACH,eAAe,MAAM;GACjB,MAAM,EAAE,WAAW;GACnB,IACI,OAAO,SAAS,sBACb,OAAO,YACP,OAAO,SAAS,SAAS,gBACzB,CAAC,kBAAkB,IAAI,OAAO,SAAS,IAAI,KAE3C,CAAC,QAAQ,IAAI,CAAC,CAAC,YAAY,MAAM,GACtC;GAEF,MAAM,SAAS,OAAO,SAAS;GAE/B,KAAK,MAAM,YAAY,KAAK,WAAW;IAKnC,IAAI,CAJoB,QAAQ,QAAQ,CAAC,CACpC,kBAAkB,CAAC,CACnB,MAAM,cAAc,qBAAqB,SAAS,QAAQ,yBAAyB,SAAS,CAAC,CAE/E,GAAG;IACtB,QAAQ,OAAO;KACX,MAAM,EAAE,OAAO;KACf,WAAW;KACX,MAAM;IACV,CAAC;GACL;EACJ,EACJ;CACJ;CACA,MAAM;EACF,MAAM;GACF,aAAa;GACb,sBAAsB;EAC1B;EACA,UAAU,EAAE,UAAU,wLAAyL;EAC/M,QAAQ,CAAC;EACT,MAAM;CACV;AACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"prefer-enhanced-date.d.ts","names":[],"sources":["../../../src/_internals/rules/prefer-enhanced-date.ts"],"mappings":";qBAqHa,oBAAoB,KAAK"}
1
+ {"version":3,"file":"prefer-enhanced-date.d.ts","names":[],"sources":["../../../src/_internals/rules/prefer-enhanced-date.ts"],"mappings":";qBAmHa,oBAAoB,KAAK"}