@tanstack/eslint-plugin-router 1.161.5 → 1.161.6

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/dist/cjs/index.cjs +22 -27
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs/rules/create-route-property-order/constants.cjs +23 -36
  4. package/dist/cjs/rules/create-route-property-order/constants.cjs.map +1 -1
  5. package/dist/cjs/rules/create-route-property-order/create-route-property-order.rule.cjs +68 -98
  6. package/dist/cjs/rules/create-route-property-order/create-route-property-order.rule.cjs.map +1 -1
  7. package/dist/cjs/rules/create-route-property-order/create-route-property-order.utils.cjs +33 -44
  8. package/dist/cjs/rules/create-route-property-order/create-route-property-order.utils.cjs.map +1 -1
  9. package/dist/cjs/rules/route-param-names/constants.cjs +24 -9
  10. package/dist/cjs/rules/route-param-names/constants.cjs.map +1 -1
  11. package/dist/cjs/rules/route-param-names/route-param-names.rule.cjs +75 -95
  12. package/dist/cjs/rules/route-param-names/route-param-names.rule.cjs.map +1 -1
  13. package/dist/cjs/rules/route-param-names/route-param-names.utils.cjs +65 -54
  14. package/dist/cjs/rules/route-param-names/route-param-names.utils.cjs.map +1 -1
  15. package/dist/cjs/rules.cjs +9 -8
  16. package/dist/cjs/rules.cjs.map +1 -1
  17. package/dist/cjs/utils/detect-router-imports.cjs +35 -51
  18. package/dist/cjs/utils/detect-router-imports.cjs.map +1 -1
  19. package/dist/cjs/utils/get-docs-url.cjs +5 -4
  20. package/dist/cjs/utils/get-docs-url.cjs.map +1 -1
  21. package/dist/esm/index.js +23 -28
  22. package/dist/esm/index.js.map +1 -1
  23. package/dist/esm/rules/create-route-property-order/constants.js +22 -37
  24. package/dist/esm/rules/create-route-property-order/constants.js.map +1 -1
  25. package/dist/esm/rules/create-route-property-order/create-route-property-order.rule.js +65 -96
  26. package/dist/esm/rules/create-route-property-order/create-route-property-order.rule.js.map +1 -1
  27. package/dist/esm/rules/create-route-property-order/create-route-property-order.utils.js +34 -46
  28. package/dist/esm/rules/create-route-property-order/create-route-property-order.utils.js.map +1 -1
  29. package/dist/esm/rules/route-param-names/constants.js +25 -12
  30. package/dist/esm/rules/route-param-names/constants.js.map +1 -1
  31. package/dist/esm/rules/route-param-names/route-param-names.rule.js +73 -94
  32. package/dist/esm/rules/route-param-names/route-param-names.rule.js.map +1 -1
  33. package/dist/esm/rules/route-param-names/route-param-names.utils.js +65 -54
  34. package/dist/esm/rules/route-param-names/route-param-names.utils.js.map +1 -1
  35. package/dist/esm/rules.js +10 -9
  36. package/dist/esm/rules.js.map +1 -1
  37. package/dist/esm/utils/detect-router-imports.js +35 -51
  38. package/dist/esm/utils/detect-router-imports.js.map +1 -1
  39. package/dist/esm/utils/get-docs-url.js +6 -5
  40. package/dist/esm/utils/get-docs-url.js.map +1 -1
  41. package/package.json +1 -1
@@ -1,40 +1,25 @@
1
1
  import { getCheckedProperties } from "./create-route-property-order.utils.js";
2
- const createRouteFunctionsIndirect = [
3
- "createFileRoute",
4
- "createRootRouteWithContext"
5
- ];
6
- const createRouteFunctionsDirect = [
7
- "createRootRoute",
8
- "createRoute"
9
- ];
10
- const createRouteFunctions = [
11
- ...createRouteFunctionsDirect,
12
- ...createRouteFunctionsIndirect
13
- ];
14
- const sortRules = [
15
- [["params", "validateSearch"], ["search"]],
16
- [["search"], ["loaderDeps", "ssr"]],
17
- [["loaderDeps"], ["context"]],
18
- [["context"], ["beforeLoad"]],
19
- [["beforeLoad"], ["loader"]],
20
- [
21
- ["loader"],
22
- [
23
- "onEnter",
24
- "onStay",
25
- "onLeave",
26
- "head",
27
- "scripts",
28
- "headers",
29
- "remountDeps"
30
- ]
31
- ]
2
+ //#region src/rules/create-route-property-order/constants.ts
3
+ var createRouteFunctionsIndirect = ["createFileRoute", "createRootRouteWithContext"];
4
+ var createRouteFunctions = [...["createRootRoute", "createRoute"], ...createRouteFunctionsIndirect];
5
+ var sortRules = [
6
+ [["params", "validateSearch"], ["search"]],
7
+ [["search"], ["loaderDeps", "ssr"]],
8
+ [["loaderDeps"], ["context"]],
9
+ [["context"], ["beforeLoad"]],
10
+ [["beforeLoad"], ["loader"]],
11
+ [["loader"], [
12
+ "onEnter",
13
+ "onStay",
14
+ "onLeave",
15
+ "head",
16
+ "scripts",
17
+ "headers",
18
+ "remountDeps"
19
+ ]]
32
20
  ];
33
21
  getCheckedProperties(sortRules);
34
- export {
35
- createRouteFunctions,
36
- createRouteFunctionsDirect,
37
- createRouteFunctionsIndirect,
38
- sortRules
39
- };
40
- //# sourceMappingURL=constants.js.map
22
+ //#endregion
23
+ export { createRouteFunctions, createRouteFunctionsIndirect, sortRules };
24
+
25
+ //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sources":["../../../../src/rules/create-route-property-order/constants.ts"],"sourcesContent":["import { getCheckedProperties } from './create-route-property-order.utils'\n\nexport const createRouteFunctionsIndirect = [\n 'createFileRoute',\n 'createRootRouteWithContext',\n] as const\nexport const createRouteFunctionsDirect = [\n 'createRootRoute',\n 'createRoute',\n] as const\n\nexport const createRouteFunctions = [\n ...createRouteFunctionsDirect,\n ...createRouteFunctionsIndirect,\n] as const\n\nexport type CreateRouteFunction = (typeof createRouteFunctions)[number]\n\nexport const sortRules = [\n [['params', 'validateSearch'], ['search']],\n [['search'], ['loaderDeps', 'ssr']],\n [['loaderDeps'], ['context']],\n [['context'], ['beforeLoad']],\n [['beforeLoad'], ['loader']],\n [\n ['loader'],\n [\n 'onEnter',\n 'onStay',\n 'onLeave',\n 'head',\n 'scripts',\n 'headers',\n 'remountDeps',\n ],\n ],\n] as const\n\nexport type CheckedProperties = (typeof sortRules)[number][number][number]\nexport const checkedProperties = getCheckedProperties(sortRules)\n"],"names":[],"mappings":";AAEO,MAAM,+BAA+B;AAAA,EAC1C;AAAA,EACA;AACF;AACO,MAAM,6BAA6B;AAAA,EACxC;AAAA,EACA;AACF;AAEO,MAAM,uBAAuB;AAAA,EAClC,GAAG;AAAA,EACH,GAAG;AACL;AAIO,MAAM,YAAY;AAAA,EACvB,CAAC,CAAC,UAAU,gBAAgB,GAAG,CAAC,QAAQ,CAAC;AAAA,EACzC,CAAC,CAAC,QAAQ,GAAG,CAAC,cAAc,KAAK,CAAC;AAAA,EAClC,CAAC,CAAC,YAAY,GAAG,CAAC,SAAS,CAAC;AAAA,EAC5B,CAAC,CAAC,SAAS,GAAG,CAAC,YAAY,CAAC;AAAA,EAC5B,CAAC,CAAC,YAAY,GAAG,CAAC,QAAQ,CAAC;AAAA,EAC3B;AAAA,IACE,CAAC,QAAQ;AAAA,IACT;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA;AAAA,EACF;AAEJ;AAGiC,qBAAqB,SAAS;"}
1
+ {"version":3,"file":"constants.js","names":[],"sources":["../../../../src/rules/create-route-property-order/constants.ts"],"sourcesContent":["import { getCheckedProperties } from './create-route-property-order.utils'\n\nexport const createRouteFunctionsIndirect = [\n 'createFileRoute',\n 'createRootRouteWithContext',\n] as const\nexport const createRouteFunctionsDirect = [\n 'createRootRoute',\n 'createRoute',\n] as const\n\nexport const createRouteFunctions = [\n ...createRouteFunctionsDirect,\n ...createRouteFunctionsIndirect,\n] as const\n\nexport type CreateRouteFunction = (typeof createRouteFunctions)[number]\n\nexport const sortRules = [\n [['params', 'validateSearch'], ['search']],\n [['search'], ['loaderDeps', 'ssr']],\n [['loaderDeps'], ['context']],\n [['context'], ['beforeLoad']],\n [['beforeLoad'], ['loader']],\n [\n ['loader'],\n [\n 'onEnter',\n 'onStay',\n 'onLeave',\n 'head',\n 'scripts',\n 'headers',\n 'remountDeps',\n ],\n ],\n] as const\n\nexport type CheckedProperties = (typeof sortRules)[number][number][number]\nexport const checkedProperties = getCheckedProperties(sortRules)\n"],"mappings":";;AAEA,IAAa,+BAA+B,CAC1C,mBACA,6BACD;AAMD,IAAa,uBAAuB,CAClC,GANwC,CACxC,mBACA,cACD,EAIC,GAAG,6BACJ;AAID,IAAa,YAAY;CACvB,CAAC,CAAC,UAAU,iBAAiB,EAAE,CAAC,SAAS,CAAC;CAC1C,CAAC,CAAC,SAAS,EAAE,CAAC,cAAc,MAAM,CAAC;CACnC,CAAC,CAAC,aAAa,EAAE,CAAC,UAAU,CAAC;CAC7B,CAAC,CAAC,UAAU,EAAE,CAAC,aAAa,CAAC;CAC7B,CAAC,CAAC,aAAa,EAAE,CAAC,SAAS,CAAC;CAC5B,CACE,CAAC,SAAS,EACV;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CACF;CACF;AAGgC,qBAAqB,UAAU"}
@@ -1,103 +1,72 @@
1
- import { ESLintUtils, AST_NODE_TYPES } from "@typescript-eslint/utils";
2
1
  import { getDocsUrl } from "../../utils/get-docs-url.js";
3
2
  import { detectTanstackRouterImports } from "../../utils/detect-router-imports.js";
4
3
  import { sortDataByOrder } from "./create-route-property-order.utils.js";
5
4
  import { createRouteFunctions, createRouteFunctionsIndirect, sortRules } from "./constants.js";
6
- const createRule = ESLintUtils.RuleCreator(getDocsUrl);
7
- const createRouteFunctionSet = new Set(createRouteFunctions);
5
+ import { AST_NODE_TYPES, ESLintUtils } from "@typescript-eslint/utils";
6
+ //#region src/rules/create-route-property-order/create-route-property-order.rule.ts
7
+ var createRule = ESLintUtils.RuleCreator(getDocsUrl);
8
+ var createRouteFunctionSet = new Set(createRouteFunctions);
8
9
  function isCreateRouteFunction(node) {
9
- return createRouteFunctionSet.has(node);
10
+ return createRouteFunctionSet.has(node);
10
11
  }
11
- const name = "create-route-property-order";
12
- const rule = createRule({
13
- name,
14
- meta: {
15
- type: "problem",
16
- docs: {
17
- description: "Ensure correct order of inference sensitive properties for createRoute functions",
18
- recommended: "error"
19
- },
20
- messages: {
21
- invalidOrder: "Invalid order of properties for `{{function}}`."
22
- },
23
- schema: [],
24
- hasSuggestions: true,
25
- fixable: "code"
26
- },
27
- defaultOptions: [],
28
- create: detectTanstackRouterImports((context) => {
29
- return {
30
- CallExpression(node) {
31
- if (node.callee.type !== AST_NODE_TYPES.Identifier) {
32
- return;
33
- }
34
- const createRouteFunction = node.callee.name;
35
- if (!isCreateRouteFunction(createRouteFunction)) {
36
- return;
37
- }
38
- let args = node.arguments;
39
- if (createRouteFunctionsIndirect.includes(createRouteFunction)) {
40
- if (node.parent.type === AST_NODE_TYPES.CallExpression) {
41
- args = node.parent.arguments;
42
- } else {
43
- return;
44
- }
45
- }
46
- const argument = args[0];
47
- if (argument === void 0 || argument.type !== "ObjectExpression") {
48
- return;
49
- }
50
- const allProperties = argument.properties;
51
- if (allProperties.length < 2) {
52
- return;
53
- }
54
- const properties = allProperties.flatMap((p) => {
55
- if (p.type === AST_NODE_TYPES.Property && p.key.type === AST_NODE_TYPES.Identifier) {
56
- return { name: p.key.name, property: p };
57
- } else if (p.type === AST_NODE_TYPES.SpreadElement) {
58
- if (p.argument.type === AST_NODE_TYPES.Identifier) {
59
- return { name: p.argument.name, property: p };
60
- } else {
61
- throw new Error("Unsupported spread element");
62
- }
63
- }
64
- return [];
65
- });
66
- const sortedProperties = sortDataByOrder(properties, sortRules, "name");
67
- if (sortedProperties === null) {
68
- return;
69
- }
70
- context.report({
71
- node: argument,
72
- data: { function: node.callee.name },
73
- messageId: "invalidOrder",
74
- fix(fixer) {
75
- const sourceCode = context.sourceCode;
76
- const text = sortedProperties.reduce(
77
- (sourceText, specifier, index) => {
78
- let text2 = "";
79
- if (index < allProperties.length - 1) {
80
- text2 = sourceCode.getText().slice(
81
- allProperties[index].range[1],
82
- allProperties[index + 1].range[0]
83
- );
84
- }
85
- return sourceText + sourceCode.getText(specifier.property) + text2;
86
- },
87
- ""
88
- );
89
- return fixer.replaceTextRange(
90
- [allProperties[0].range[0], allProperties.at(-1).range[1]],
91
- text
92
- );
93
- }
94
- });
95
- }
96
- };
97
- })
12
+ var name = "create-route-property-order";
13
+ var rule = createRule({
14
+ name,
15
+ meta: {
16
+ type: "problem",
17
+ docs: {
18
+ description: "Ensure correct order of inference sensitive properties for createRoute functions",
19
+ recommended: "error"
20
+ },
21
+ messages: { invalidOrder: "Invalid order of properties for `{{function}}`." },
22
+ schema: [],
23
+ hasSuggestions: true,
24
+ fixable: "code"
25
+ },
26
+ defaultOptions: [],
27
+ create: detectTanstackRouterImports((context) => {
28
+ return { CallExpression(node) {
29
+ if (node.callee.type !== AST_NODE_TYPES.Identifier) return;
30
+ const createRouteFunction = node.callee.name;
31
+ if (!isCreateRouteFunction(createRouteFunction)) return;
32
+ let args = node.arguments;
33
+ if (createRouteFunctionsIndirect.includes(createRouteFunction)) if (node.parent.type === AST_NODE_TYPES.CallExpression) args = node.parent.arguments;
34
+ else return;
35
+ const argument = args[0];
36
+ if (argument === void 0 || argument.type !== "ObjectExpression") return;
37
+ const allProperties = argument.properties;
38
+ if (allProperties.length < 2) return;
39
+ const sortedProperties = sortDataByOrder(allProperties.flatMap((p) => {
40
+ if (p.type === AST_NODE_TYPES.Property && p.key.type === AST_NODE_TYPES.Identifier) return {
41
+ name: p.key.name,
42
+ property: p
43
+ };
44
+ else if (p.type === AST_NODE_TYPES.SpreadElement) if (p.argument.type === AST_NODE_TYPES.Identifier) return {
45
+ name: p.argument.name,
46
+ property: p
47
+ };
48
+ else throw new Error("Unsupported spread element");
49
+ return [];
50
+ }), sortRules, "name");
51
+ if (sortedProperties === null) return;
52
+ context.report({
53
+ node: argument,
54
+ data: { function: node.callee.name },
55
+ messageId: "invalidOrder",
56
+ fix(fixer) {
57
+ const sourceCode = context.sourceCode;
58
+ const text = sortedProperties.reduce((sourceText, specifier, index) => {
59
+ let text = "";
60
+ if (index < allProperties.length - 1) text = sourceCode.getText().slice(allProperties[index].range[1], allProperties[index + 1].range[0]);
61
+ return sourceText + sourceCode.getText(specifier.property) + text;
62
+ }, "");
63
+ return fixer.replaceTextRange([allProperties[0].range[0], allProperties.at(-1).range[1]], text);
64
+ }
65
+ });
66
+ } };
67
+ })
98
68
  });
99
- export {
100
- name,
101
- rule
102
- };
103
- //# sourceMappingURL=create-route-property-order.rule.js.map
69
+ //#endregion
70
+ export { name, rule };
71
+
72
+ //# sourceMappingURL=create-route-property-order.rule.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"create-route-property-order.rule.js","sources":["../../../../src/rules/create-route-property-order/create-route-property-order.rule.ts"],"sourcesContent":["import { AST_NODE_TYPES, ESLintUtils } from '@typescript-eslint/utils'\n\nimport { getDocsUrl } from '../../utils/get-docs-url'\nimport { detectTanstackRouterImports } from '../../utils/detect-router-imports'\nimport { sortDataByOrder } from './create-route-property-order.utils'\nimport {\n createRouteFunctions,\n createRouteFunctionsIndirect,\n sortRules,\n} from './constants'\nimport type { CreateRouteFunction } from './constants'\nimport type { ExtraRuleDocs } from '../../types'\n\nconst createRule = ESLintUtils.RuleCreator<ExtraRuleDocs>(getDocsUrl)\n\nconst createRouteFunctionSet = new Set(createRouteFunctions)\nfunction isCreateRouteFunction(node: any): node is CreateRouteFunction {\n return createRouteFunctionSet.has(node)\n}\n\nexport const name = 'create-route-property-order'\n\nexport const rule = createRule({\n name,\n meta: {\n type: 'problem',\n docs: {\n description:\n 'Ensure correct order of inference sensitive properties for createRoute functions',\n recommended: 'error',\n },\n messages: {\n invalidOrder: 'Invalid order of properties for `{{function}}`.',\n },\n schema: [],\n hasSuggestions: true,\n fixable: 'code',\n },\n defaultOptions: [],\n\n create: detectTanstackRouterImports((context) => {\n return {\n CallExpression(node) {\n if (node.callee.type !== AST_NODE_TYPES.Identifier) {\n return\n }\n const createRouteFunction = node.callee.name\n if (!isCreateRouteFunction(createRouteFunction)) {\n return\n }\n let args = node.arguments\n if (createRouteFunctionsIndirect.includes(createRouteFunction as any)) {\n if (node.parent.type === AST_NODE_TYPES.CallExpression) {\n args = node.parent.arguments\n } else {\n return\n }\n }\n\n const argument = args[0]\n if (argument === undefined || argument.type !== 'ObjectExpression') {\n return\n }\n\n const allProperties = argument.properties\n // no need to sort if there is at max 1 property\n if (allProperties.length < 2) {\n return\n }\n\n const properties = allProperties.flatMap((p) => {\n if (\n p.type === AST_NODE_TYPES.Property &&\n p.key.type === AST_NODE_TYPES.Identifier\n ) {\n return { name: p.key.name, property: p }\n } else if (p.type === AST_NODE_TYPES.SpreadElement) {\n if (p.argument.type === AST_NODE_TYPES.Identifier) {\n return { name: p.argument.name, property: p }\n } else {\n throw new Error('Unsupported spread element')\n }\n }\n return []\n })\n\n const sortedProperties = sortDataByOrder(properties, sortRules, 'name')\n if (sortedProperties === null) {\n return\n }\n context.report({\n node: argument,\n data: { function: node.callee.name },\n messageId: 'invalidOrder',\n fix(fixer) {\n const sourceCode = context.sourceCode\n\n const text = sortedProperties.reduce(\n (sourceText, specifier, index) => {\n let text = ''\n if (index < allProperties.length - 1) {\n text = sourceCode\n .getText()\n .slice(\n allProperties[index]!.range[1],\n allProperties[index + 1]!.range[0],\n )\n }\n return (\n sourceText + sourceCode.getText(specifier.property) + text\n )\n },\n '',\n )\n return fixer.replaceTextRange(\n [allProperties[0]!.range[0], allProperties.at(-1)!.range[1]],\n text,\n )\n },\n })\n },\n }\n }),\n})\n"],"names":["text"],"mappings":";;;;;AAaA,MAAM,aAAa,YAAY,YAA2B,UAAU;AAEpE,MAAM,yBAAyB,IAAI,IAAI,oBAAoB;AAC3D,SAAS,sBAAsB,MAAwC;AACrE,SAAO,uBAAuB,IAAI,IAAI;AACxC;AAEO,MAAM,OAAO;AAEb,MAAM,OAAO,WAAW;AAAA,EAC7B;AAAA,EACA,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,MAAM;AAAA,MACJ,aACE;AAAA,MACF,aAAa;AAAA,IAAA;AAAA,IAEf,UAAU;AAAA,MACR,cAAc;AAAA,IAAA;AAAA,IAEhB,QAAQ,CAAA;AAAA,IACR,gBAAgB;AAAA,IAChB,SAAS;AAAA,EAAA;AAAA,EAEX,gBAAgB,CAAA;AAAA,EAEhB,QAAQ,4BAA4B,CAAC,YAAY;AAC/C,WAAO;AAAA,MACL,eAAe,MAAM;AACnB,YAAI,KAAK,OAAO,SAAS,eAAe,YAAY;AAClD;AAAA,QACF;AACA,cAAM,sBAAsB,KAAK,OAAO;AACxC,YAAI,CAAC,sBAAsB,mBAAmB,GAAG;AAC/C;AAAA,QACF;AACA,YAAI,OAAO,KAAK;AAChB,YAAI,6BAA6B,SAAS,mBAA0B,GAAG;AACrE,cAAI,KAAK,OAAO,SAAS,eAAe,gBAAgB;AACtD,mBAAO,KAAK,OAAO;AAAA,UACrB,OAAO;AACL;AAAA,UACF;AAAA,QACF;AAEA,cAAM,WAAW,KAAK,CAAC;AACvB,YAAI,aAAa,UAAa,SAAS,SAAS,oBAAoB;AAClE;AAAA,QACF;AAEA,cAAM,gBAAgB,SAAS;AAE/B,YAAI,cAAc,SAAS,GAAG;AAC5B;AAAA,QACF;AAEA,cAAM,aAAa,cAAc,QAAQ,CAAC,MAAM;AAC9C,cACE,EAAE,SAAS,eAAe,YAC1B,EAAE,IAAI,SAAS,eAAe,YAC9B;AACA,mBAAO,EAAE,MAAM,EAAE,IAAI,MAAM,UAAU,EAAA;AAAA,UACvC,WAAW,EAAE,SAAS,eAAe,eAAe;AAClD,gBAAI,EAAE,SAAS,SAAS,eAAe,YAAY;AACjD,qBAAO,EAAE,MAAM,EAAE,SAAS,MAAM,UAAU,EAAA;AAAA,YAC5C,OAAO;AACL,oBAAM,IAAI,MAAM,4BAA4B;AAAA,YAC9C;AAAA,UACF;AACA,iBAAO,CAAA;AAAA,QACT,CAAC;AAED,cAAM,mBAAmB,gBAAgB,YAAY,WAAW,MAAM;AACtE,YAAI,qBAAqB,MAAM;AAC7B;AAAA,QACF;AACA,gBAAQ,OAAO;AAAA,UACb,MAAM;AAAA,UACN,MAAM,EAAE,UAAU,KAAK,OAAO,KAAA;AAAA,UAC9B,WAAW;AAAA,UACX,IAAI,OAAO;AACT,kBAAM,aAAa,QAAQ;AAE3B,kBAAM,OAAO,iBAAiB;AAAA,cAC5B,CAAC,YAAY,WAAW,UAAU;AAChC,oBAAIA,QAAO;AACX,oBAAI,QAAQ,cAAc,SAAS,GAAG;AACpCA,0BAAO,WACJ,QAAA,EACA;AAAA,oBACC,cAAc,KAAK,EAAG,MAAM,CAAC;AAAA,oBAC7B,cAAc,QAAQ,CAAC,EAAG,MAAM,CAAC;AAAA,kBAAA;AAAA,gBAEvC;AACA,uBACE,aAAa,WAAW,QAAQ,UAAU,QAAQ,IAAIA;AAAAA,cAE1D;AAAA,cACA;AAAA,YAAA;AAEF,mBAAO,MAAM;AAAA,cACX,CAAC,cAAc,CAAC,EAAG,MAAM,CAAC,GAAG,cAAc,GAAG,EAAE,EAAG,MAAM,CAAC,CAAC;AAAA,cAC3D;AAAA,YAAA;AAAA,UAEJ;AAAA,QAAA,CACD;AAAA,MACH;AAAA,IAAA;AAAA,EAEJ,CAAC;AACH,CAAC;"}
1
+ {"version":3,"file":"create-route-property-order.rule.js","names":[],"sources":["../../../../src/rules/create-route-property-order/create-route-property-order.rule.ts"],"sourcesContent":["import { AST_NODE_TYPES, ESLintUtils } from '@typescript-eslint/utils'\n\nimport { getDocsUrl } from '../../utils/get-docs-url'\nimport { detectTanstackRouterImports } from '../../utils/detect-router-imports'\nimport { sortDataByOrder } from './create-route-property-order.utils'\nimport {\n createRouteFunctions,\n createRouteFunctionsIndirect,\n sortRules,\n} from './constants'\nimport type { CreateRouteFunction } from './constants'\nimport type { ExtraRuleDocs } from '../../types'\n\nconst createRule = ESLintUtils.RuleCreator<ExtraRuleDocs>(getDocsUrl)\n\nconst createRouteFunctionSet = new Set(createRouteFunctions)\nfunction isCreateRouteFunction(node: any): node is CreateRouteFunction {\n return createRouteFunctionSet.has(node)\n}\n\nexport const name = 'create-route-property-order'\n\nexport const rule = createRule({\n name,\n meta: {\n type: 'problem',\n docs: {\n description:\n 'Ensure correct order of inference sensitive properties for createRoute functions',\n recommended: 'error',\n },\n messages: {\n invalidOrder: 'Invalid order of properties for `{{function}}`.',\n },\n schema: [],\n hasSuggestions: true,\n fixable: 'code',\n },\n defaultOptions: [],\n\n create: detectTanstackRouterImports((context) => {\n return {\n CallExpression(node) {\n if (node.callee.type !== AST_NODE_TYPES.Identifier) {\n return\n }\n const createRouteFunction = node.callee.name\n if (!isCreateRouteFunction(createRouteFunction)) {\n return\n }\n let args = node.arguments\n if (createRouteFunctionsIndirect.includes(createRouteFunction as any)) {\n if (node.parent.type === AST_NODE_TYPES.CallExpression) {\n args = node.parent.arguments\n } else {\n return\n }\n }\n\n const argument = args[0]\n if (argument === undefined || argument.type !== 'ObjectExpression') {\n return\n }\n\n const allProperties = argument.properties\n // no need to sort if there is at max 1 property\n if (allProperties.length < 2) {\n return\n }\n\n const properties = allProperties.flatMap((p) => {\n if (\n p.type === AST_NODE_TYPES.Property &&\n p.key.type === AST_NODE_TYPES.Identifier\n ) {\n return { name: p.key.name, property: p }\n } else if (p.type === AST_NODE_TYPES.SpreadElement) {\n if (p.argument.type === AST_NODE_TYPES.Identifier) {\n return { name: p.argument.name, property: p }\n } else {\n throw new Error('Unsupported spread element')\n }\n }\n return []\n })\n\n const sortedProperties = sortDataByOrder(properties, sortRules, 'name')\n if (sortedProperties === null) {\n return\n }\n context.report({\n node: argument,\n data: { function: node.callee.name },\n messageId: 'invalidOrder',\n fix(fixer) {\n const sourceCode = context.sourceCode\n\n const text = sortedProperties.reduce(\n (sourceText, specifier, index) => {\n let text = ''\n if (index < allProperties.length - 1) {\n text = sourceCode\n .getText()\n .slice(\n allProperties[index]!.range[1],\n allProperties[index + 1]!.range[0],\n )\n }\n return (\n sourceText + sourceCode.getText(specifier.property) + text\n )\n },\n '',\n )\n return fixer.replaceTextRange(\n [allProperties[0]!.range[0], allProperties.at(-1)!.range[1]],\n text,\n )\n },\n })\n },\n }\n }),\n})\n"],"mappings":";;;;;;AAaA,IAAM,aAAa,YAAY,YAA2B,WAAW;AAErE,IAAM,yBAAyB,IAAI,IAAI,qBAAqB;AAC5D,SAAS,sBAAsB,MAAwC;AACrE,QAAO,uBAAuB,IAAI,KAAK;;AAGzC,IAAa,OAAO;AAEpB,IAAa,OAAO,WAAW;CAC7B;CACA,MAAM;EACJ,MAAM;EACN,MAAM;GACJ,aACE;GACF,aAAa;GACd;EACD,UAAU,EACR,cAAc,mDACf;EACD,QAAQ,EAAE;EACV,gBAAgB;EAChB,SAAS;EACV;CACD,gBAAgB,EAAE;CAElB,QAAQ,6BAA6B,YAAY;AAC/C,SAAO,EACL,eAAe,MAAM;AACnB,OAAI,KAAK,OAAO,SAAS,eAAe,WACtC;GAEF,MAAM,sBAAsB,KAAK,OAAO;AACxC,OAAI,CAAC,sBAAsB,oBAAoB,CAC7C;GAEF,IAAI,OAAO,KAAK;AAChB,OAAI,6BAA6B,SAAS,oBAA2B,CACnE,KAAI,KAAK,OAAO,SAAS,eAAe,eACtC,QAAO,KAAK,OAAO;OAEnB;GAIJ,MAAM,WAAW,KAAK;AACtB,OAAI,aAAa,KAAA,KAAa,SAAS,SAAS,mBAC9C;GAGF,MAAM,gBAAgB,SAAS;AAE/B,OAAI,cAAc,SAAS,EACzB;GAmBF,MAAM,mBAAmB,gBAhBN,cAAc,SAAS,MAAM;AAC9C,QACE,EAAE,SAAS,eAAe,YAC1B,EAAE,IAAI,SAAS,eAAe,WAE9B,QAAO;KAAE,MAAM,EAAE,IAAI;KAAM,UAAU;KAAG;aAC/B,EAAE,SAAS,eAAe,cACnC,KAAI,EAAE,SAAS,SAAS,eAAe,WACrC,QAAO;KAAE,MAAM,EAAE,SAAS;KAAM,UAAU;KAAG;QAE7C,OAAM,IAAI,MAAM,6BAA6B;AAGjD,WAAO,EAAE;KACT,EAEmD,WAAW,OAAO;AACvE,OAAI,qBAAqB,KACvB;AAEF,WAAQ,OAAO;IACb,MAAM;IACN,MAAM,EAAE,UAAU,KAAK,OAAO,MAAM;IACpC,WAAW;IACX,IAAI,OAAO;KACT,MAAM,aAAa,QAAQ;KAE3B,MAAM,OAAO,iBAAiB,QAC3B,YAAY,WAAW,UAAU;MAChC,IAAI,OAAO;AACX,UAAI,QAAQ,cAAc,SAAS,EACjC,QAAO,WACJ,SAAS,CACT,MACC,cAAc,OAAQ,MAAM,IAC5B,cAAc,QAAQ,GAAI,MAAM,GACjC;AAEL,aACE,aAAa,WAAW,QAAQ,UAAU,SAAS,GAAG;QAG1D,GACD;AACD,YAAO,MAAM,iBACX,CAAC,cAAc,GAAI,MAAM,IAAI,cAAc,GAAG,GAAG,CAAE,MAAM,GAAG,EAC5D,KACD;;IAEJ,CAAC;KAEL;GACD;CACH,CAAC"}
@@ -1,50 +1,38 @@
1
+ //#region src/rules/create-route-property-order/create-route-property-order.utils.ts
1
2
  function sortDataByOrder(data, orderRules, key) {
2
- const getSubsetIndex = (item, subsets) => {
3
- for (let i = 0; i < subsets.length; i++) {
4
- if (subsets[i]?.includes(item)) {
5
- return i;
6
- }
7
- }
8
- return null;
9
- };
10
- const orderSets = orderRules.reduce(
11
- (sets, [A, B]) => [...sets, A, B],
12
- []
13
- );
14
- const inOrderArray = data.filter(
15
- (item) => getSubsetIndex(item[key], orderSets) !== null
16
- );
17
- let wasResorted = false;
18
- const sortedArray = inOrderArray.sort((a, b) => {
19
- const aKey = a[key], bKey = b[key];
20
- const aSubsetIndex = getSubsetIndex(aKey, orderSets);
21
- const bSubsetIndex = getSubsetIndex(bKey, orderSets);
22
- if (aSubsetIndex !== null && bSubsetIndex !== null && aSubsetIndex !== bSubsetIndex) {
23
- return aSubsetIndex - bSubsetIndex;
24
- }
25
- return 0;
26
- });
27
- const inOrderIterator = sortedArray.values();
28
- const result = data.map((item) => {
29
- if (getSubsetIndex(item[key], orderSets) !== null) {
30
- const sortedItem = inOrderIterator.next().value;
31
- if (sortedItem[key] !== item[key]) {
32
- wasResorted = true;
33
- }
34
- return sortedItem;
35
- }
36
- return item;
37
- });
38
- if (!wasResorted) {
39
- return null;
40
- }
41
- return result;
3
+ const getSubsetIndex = (item, subsets) => {
4
+ for (let i = 0; i < subsets.length; i++) if (subsets[i]?.includes(item)) return i;
5
+ return null;
6
+ };
7
+ const orderSets = orderRules.reduce((sets, [A, B]) => [
8
+ ...sets,
9
+ A,
10
+ B
11
+ ], []);
12
+ const inOrderArray = data.filter((item) => getSubsetIndex(item[key], orderSets) !== null);
13
+ let wasResorted = false;
14
+ const inOrderIterator = inOrderArray.sort((a, b) => {
15
+ const aKey = a[key], bKey = b[key];
16
+ const aSubsetIndex = getSubsetIndex(aKey, orderSets);
17
+ const bSubsetIndex = getSubsetIndex(bKey, orderSets);
18
+ if (aSubsetIndex !== null && bSubsetIndex !== null && aSubsetIndex !== bSubsetIndex) return aSubsetIndex - bSubsetIndex;
19
+ return 0;
20
+ }).values();
21
+ const result = data.map((item) => {
22
+ if (getSubsetIndex(item[key], orderSets) !== null) {
23
+ const sortedItem = inOrderIterator.next().value;
24
+ if (sortedItem[key] !== item[key]) wasResorted = true;
25
+ return sortedItem;
26
+ }
27
+ return item;
28
+ });
29
+ if (!wasResorted) return null;
30
+ return result;
42
31
  }
43
32
  function getCheckedProperties(orderRules) {
44
- return [...new Set(orderRules.flat(2))];
33
+ return [...new Set(orderRules.flat(2))];
45
34
  }
46
- export {
47
- getCheckedProperties,
48
- sortDataByOrder
49
- };
50
- //# sourceMappingURL=create-route-property-order.utils.js.map
35
+ //#endregion
36
+ export { getCheckedProperties, sortDataByOrder };
37
+
38
+ //# sourceMappingURL=create-route-property-order.utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"create-route-property-order.utils.js","sources":["../../../../src/rules/create-route-property-order/create-route-property-order.utils.ts"],"sourcesContent":["export function sortDataByOrder<T, TKey extends keyof T>(\n data: Array<T> | ReadonlyArray<T>,\n orderRules: ReadonlyArray<\n Readonly<[ReadonlyArray<T[TKey]>, ReadonlyArray<T[TKey]>]>\n >,\n key: TKey,\n): Array<T> | null {\n const getSubsetIndex = (\n item: T[TKey],\n subsets: ReadonlyArray<ReadonlyArray<T[TKey]> | Array<T[TKey]>>,\n ): number | null => {\n for (let i = 0; i < subsets.length; i++) {\n if (subsets[i]?.includes(item)) {\n return i\n }\n }\n return null\n }\n\n const orderSets = orderRules.reduce(\n (sets, [A, B]) => [...sets, A, B],\n [] as Array<ReadonlyArray<T[TKey]> | Array<T[TKey]>>,\n )\n\n const inOrderArray = data.filter(\n (item) => getSubsetIndex(item[key], orderSets) !== null,\n )\n\n let wasResorted = false as boolean\n\n // Sort by the relative order defined by the rules\n const sortedArray = inOrderArray.sort((a, b) => {\n const aKey = a[key],\n bKey = b[key]\n const aSubsetIndex = getSubsetIndex(aKey, orderSets)\n const bSubsetIndex = getSubsetIndex(bKey, orderSets)\n\n // If both items belong to different subsets, sort by their subset order\n if (\n aSubsetIndex !== null &&\n bSubsetIndex !== null &&\n aSubsetIndex !== bSubsetIndex\n ) {\n return aSubsetIndex - bSubsetIndex\n }\n\n // If both items belong to the same subset or neither is in the subset, keep their relative order\n return 0\n })\n\n const inOrderIterator = sortedArray.values()\n const result = data.map((item) => {\n if (getSubsetIndex(item[key], orderSets) !== null) {\n const sortedItem = inOrderIterator.next().value!\n if (sortedItem[key] !== item[key]) {\n wasResorted = true\n }\n return sortedItem\n }\n return item\n })\n\n if (!wasResorted) {\n return null\n }\n return result\n}\n\nexport function getCheckedProperties<T>(\n orderRules: ReadonlyArray<ReadonlyArray<ReadonlyArray<T>>>,\n): ReadonlyArray<T> {\n return [...new Set<T>(orderRules.flat(2))]\n}\n"],"names":[],"mappings":"AAAO,SAAS,gBACd,MACA,YAGA,KACiB;AACjB,QAAM,iBAAiB,CACrB,MACA,YACkB;AAClB,aAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,UAAI,QAAQ,CAAC,GAAG,SAAS,IAAI,GAAG;AAC9B,eAAO;AAAA,MACT;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,WAAW;AAAA,IAC3B,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,GAAG,CAAC;AAAA,IAChC,CAAA;AAAA,EAAC;AAGH,QAAM,eAAe,KAAK;AAAA,IACxB,CAAC,SAAS,eAAe,KAAK,GAAG,GAAG,SAAS,MAAM;AAAA,EAAA;AAGrD,MAAI,cAAc;AAGlB,QAAM,cAAc,aAAa,KAAK,CAAC,GAAG,MAAM;AAC9C,UAAM,OAAO,EAAE,GAAG,GAChB,OAAO,EAAE,GAAG;AACd,UAAM,eAAe,eAAe,MAAM,SAAS;AACnD,UAAM,eAAe,eAAe,MAAM,SAAS;AAGnD,QACE,iBAAiB,QACjB,iBAAiB,QACjB,iBAAiB,cACjB;AACA,aAAO,eAAe;AAAA,IACxB;AAGA,WAAO;AAAA,EACT,CAAC;AAED,QAAM,kBAAkB,YAAY,OAAA;AACpC,QAAM,SAAS,KAAK,IAAI,CAAC,SAAS;AAChC,QAAI,eAAe,KAAK,GAAG,GAAG,SAAS,MAAM,MAAM;AACjD,YAAM,aAAa,gBAAgB,KAAA,EAAO;AAC1C,UAAI,WAAW,GAAG,MAAM,KAAK,GAAG,GAAG;AACjC,sBAAc;AAAA,MAChB;AACA,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT,CAAC;AAED,MAAI,CAAC,aAAa;AAChB,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEO,SAAS,qBACd,YACkB;AAClB,SAAO,CAAC,GAAG,IAAI,IAAO,WAAW,KAAK,CAAC,CAAC,CAAC;AAC3C;"}
1
+ {"version":3,"file":"create-route-property-order.utils.js","names":[],"sources":["../../../../src/rules/create-route-property-order/create-route-property-order.utils.ts"],"sourcesContent":["export function sortDataByOrder<T, TKey extends keyof T>(\n data: Array<T> | ReadonlyArray<T>,\n orderRules: ReadonlyArray<\n Readonly<[ReadonlyArray<T[TKey]>, ReadonlyArray<T[TKey]>]>\n >,\n key: TKey,\n): Array<T> | null {\n const getSubsetIndex = (\n item: T[TKey],\n subsets: ReadonlyArray<ReadonlyArray<T[TKey]> | Array<T[TKey]>>,\n ): number | null => {\n for (let i = 0; i < subsets.length; i++) {\n if (subsets[i]?.includes(item)) {\n return i\n }\n }\n return null\n }\n\n const orderSets = orderRules.reduce(\n (sets, [A, B]) => [...sets, A, B],\n [] as Array<ReadonlyArray<T[TKey]> | Array<T[TKey]>>,\n )\n\n const inOrderArray = data.filter(\n (item) => getSubsetIndex(item[key], orderSets) !== null,\n )\n\n let wasResorted = false as boolean\n\n // Sort by the relative order defined by the rules\n const sortedArray = inOrderArray.sort((a, b) => {\n const aKey = a[key],\n bKey = b[key]\n const aSubsetIndex = getSubsetIndex(aKey, orderSets)\n const bSubsetIndex = getSubsetIndex(bKey, orderSets)\n\n // If both items belong to different subsets, sort by their subset order\n if (\n aSubsetIndex !== null &&\n bSubsetIndex !== null &&\n aSubsetIndex !== bSubsetIndex\n ) {\n return aSubsetIndex - bSubsetIndex\n }\n\n // If both items belong to the same subset or neither is in the subset, keep their relative order\n return 0\n })\n\n const inOrderIterator = sortedArray.values()\n const result = data.map((item) => {\n if (getSubsetIndex(item[key], orderSets) !== null) {\n const sortedItem = inOrderIterator.next().value!\n if (sortedItem[key] !== item[key]) {\n wasResorted = true\n }\n return sortedItem\n }\n return item\n })\n\n if (!wasResorted) {\n return null\n }\n return result\n}\n\nexport function getCheckedProperties<T>(\n orderRules: ReadonlyArray<ReadonlyArray<ReadonlyArray<T>>>,\n): ReadonlyArray<T> {\n return [...new Set<T>(orderRules.flat(2))]\n}\n"],"mappings":";AAAA,SAAgB,gBACd,MACA,YAGA,KACiB;CACjB,MAAM,kBACJ,MACA,YACkB;AAClB,OAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,QAAQ,IAClC,KAAI,QAAQ,IAAI,SAAS,KAAK,CAC5B,QAAO;AAGX,SAAO;;CAGT,MAAM,YAAY,WAAW,QAC1B,MAAM,CAAC,GAAG,OAAO;EAAC,GAAG;EAAM;EAAG;EAAE,EACjC,EAAE,CACH;CAED,MAAM,eAAe,KAAK,QACvB,SAAS,eAAe,KAAK,MAAM,UAAU,KAAK,KACpD;CAED,IAAI,cAAc;CAsBlB,MAAM,kBAnBc,aAAa,MAAM,GAAG,MAAM;EAC9C,MAAM,OAAO,EAAE,MACb,OAAO,EAAE;EACX,MAAM,eAAe,eAAe,MAAM,UAAU;EACpD,MAAM,eAAe,eAAe,MAAM,UAAU;AAGpD,MACE,iBAAiB,QACjB,iBAAiB,QACjB,iBAAiB,aAEjB,QAAO,eAAe;AAIxB,SAAO;GACP,CAEkC,QAAQ;CAC5C,MAAM,SAAS,KAAK,KAAK,SAAS;AAChC,MAAI,eAAe,KAAK,MAAM,UAAU,KAAK,MAAM;GACjD,MAAM,aAAa,gBAAgB,MAAM,CAAC;AAC1C,OAAI,WAAW,SAAS,KAAK,KAC3B,eAAc;AAEhB,UAAO;;AAET,SAAO;GACP;AAEF,KAAI,CAAC,YACH,QAAO;AAET,QAAO;;AAGT,SAAgB,qBACd,YACkB;AAClB,QAAO,CAAC,GAAG,IAAI,IAAO,WAAW,KAAK,EAAE,CAAC,CAAC"}
@@ -1,13 +1,26 @@
1
- const pathAsFirstArgFunctions = [
2
- "createFileRoute",
3
- "createLazyFileRoute",
4
- "createLazyRoute"
1
+ //#region src/rules/route-param-names/constants.ts
2
+ /**
3
+ * Functions where the path is passed as the first argument (string literal)
4
+ * e.g., createFileRoute('/path/$param')(...)
5
+ */
6
+ var pathAsFirstArgFunctions = [
7
+ "createFileRoute",
8
+ "createLazyFileRoute",
9
+ "createLazyRoute"
5
10
  ];
6
- const pathAsPropertyFunctions = ["createRoute"];
7
- const VALID_PARAM_NAME_REGEX = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
8
- export {
9
- VALID_PARAM_NAME_REGEX,
10
- pathAsFirstArgFunctions,
11
- pathAsPropertyFunctions
12
- };
13
- //# sourceMappingURL=constants.js.map
11
+ /**
12
+ * Functions where the path is a property in the options object
13
+ * e.g., createRoute({ path: '/path/$param' })
14
+ */
15
+ var pathAsPropertyFunctions = ["createRoute"];
16
+ [...pathAsFirstArgFunctions, ...pathAsPropertyFunctions];
17
+ /**
18
+ * Regex for valid JavaScript identifier (param name)
19
+ * Must start with letter, underscore, or dollar sign
20
+ * Can contain letters, numbers, underscores, or dollar signs
21
+ */
22
+ var VALID_PARAM_NAME_REGEX = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
23
+ //#endregion
24
+ export { VALID_PARAM_NAME_REGEX, pathAsFirstArgFunctions, pathAsPropertyFunctions };
25
+
26
+ //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sources":["../../../../src/rules/route-param-names/constants.ts"],"sourcesContent":["/**\n * Functions where the path is passed as the first argument (string literal)\n * e.g., createFileRoute('/path/$param')(...)\n */\nexport const pathAsFirstArgFunctions = [\n 'createFileRoute',\n 'createLazyFileRoute',\n 'createLazyRoute',\n] as const\n\nexport type PathAsFirstArgFunction = (typeof pathAsFirstArgFunctions)[number]\n\n/**\n * Functions where the path is a property in the options object\n * e.g., createRoute({ path: '/path/$param' })\n */\nexport const pathAsPropertyFunctions = ['createRoute'] as const\n\nexport type PathAsPropertyFunction = (typeof pathAsPropertyFunctions)[number]\n\n/**\n * All route functions that need param name validation\n */\nexport const allRouteFunctions = [\n ...pathAsFirstArgFunctions,\n ...pathAsPropertyFunctions,\n] as const\n\nexport type RouteFunction = (typeof allRouteFunctions)[number]\n\n/**\n * Regex for valid JavaScript identifier (param name)\n * Must start with letter, underscore, or dollar sign\n * Can contain letters, numbers, underscores, or dollar signs\n */\nexport const VALID_PARAM_NAME_REGEX = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/\n"],"names":[],"mappings":"AAIO,MAAM,0BAA0B;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AACF;AAQO,MAAM,0BAA0B,CAAC,aAAa;AAmB9C,MAAM,yBAAyB;"}
1
+ {"version":3,"file":"constants.js","names":[],"sources":["../../../../src/rules/route-param-names/constants.ts"],"sourcesContent":["/**\n * Functions where the path is passed as the first argument (string literal)\n * e.g., createFileRoute('/path/$param')(...)\n */\nexport const pathAsFirstArgFunctions = [\n 'createFileRoute',\n 'createLazyFileRoute',\n 'createLazyRoute',\n] as const\n\nexport type PathAsFirstArgFunction = (typeof pathAsFirstArgFunctions)[number]\n\n/**\n * Functions where the path is a property in the options object\n * e.g., createRoute({ path: '/path/$param' })\n */\nexport const pathAsPropertyFunctions = ['createRoute'] as const\n\nexport type PathAsPropertyFunction = (typeof pathAsPropertyFunctions)[number]\n\n/**\n * All route functions that need param name validation\n */\nexport const allRouteFunctions = [\n ...pathAsFirstArgFunctions,\n ...pathAsPropertyFunctions,\n] as const\n\nexport type RouteFunction = (typeof allRouteFunctions)[number]\n\n/**\n * Regex for valid JavaScript identifier (param name)\n * Must start with letter, underscore, or dollar sign\n * Can contain letters, numbers, underscores, or dollar signs\n */\nexport const VALID_PARAM_NAME_REGEX = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/\n"],"mappings":";;;;;AAIA,IAAa,0BAA0B;CACrC;CACA;CACA;CACD;;;;;AAQD,IAAa,0BAA0B,CAAC,cAAc;AAOrB,CAC/B,GAAG,yBACH,GAAG,wBACJ;;;;;;AASD,IAAa,yBAAyB"}
@@ -1,98 +1,77 @@
1
- import { ESLintUtils, AST_NODE_TYPES } from "@typescript-eslint/utils";
2
1
  import { getDocsUrl } from "../../utils/get-docs-url.js";
3
2
  import { detectTanstackRouterImports } from "../../utils/detect-router-imports.js";
4
- import { getInvalidParams } from "./route-param-names.utils.js";
5
3
  import { pathAsFirstArgFunctions, pathAsPropertyFunctions } from "./constants.js";
6
- const createRule = ESLintUtils.RuleCreator(getDocsUrl);
7
- const pathAsFirstArgSet = new Set(pathAsFirstArgFunctions);
8
- const pathAsPropertySet = new Set(pathAsPropertyFunctions);
9
- const name = "route-param-names";
10
- const rule = createRule({
11
- name,
12
- meta: {
13
- type: "problem",
14
- docs: {
15
- description: "Ensure route param names are valid JavaScript identifiers",
16
- recommended: "error"
17
- },
18
- messages: {
19
- invalidParamName: 'Invalid param name "{{paramName}}" in route path. Param names must be valid JavaScript identifiers (match /[a-zA-Z_$][a-zA-Z0-9_$]*/).'
20
- },
21
- schema: []
22
- },
23
- defaultOptions: [],
24
- create: detectTanstackRouterImports((context, _, helpers) => {
25
- function reportInvalidParams(node, path) {
26
- const invalidParams = getInvalidParams(path);
27
- for (const param of invalidParams) {
28
- context.report({
29
- node,
30
- messageId: "invalidParamName",
31
- data: { paramName: param.paramName }
32
- });
33
- }
34
- }
35
- function getStringLiteralValue(node) {
36
- if (node.type === AST_NODE_TYPES.Literal && typeof node.value === "string") {
37
- return node.value;
38
- }
39
- if (node.type === AST_NODE_TYPES.TemplateLiteral && node.quasis.length === 1) {
40
- const cooked = node.quasis[0]?.value.cooked;
41
- if (cooked != null) {
42
- return cooked;
43
- }
44
- }
45
- return null;
46
- }
47
- return {
48
- CallExpression(node) {
49
- if (node.callee.type === AST_NODE_TYPES.Identifier) {
50
- const funcName = node.callee.name;
51
- if (!helpers.isTanstackRouterImport(node.callee)) {
52
- return;
53
- }
54
- if (pathAsPropertySet.has(funcName)) {
55
- const arg = node.arguments[0];
56
- if (arg?.type === AST_NODE_TYPES.ObjectExpression) {
57
- for (const prop of arg.properties) {
58
- if (prop.type === AST_NODE_TYPES.Property) {
59
- const isPathKey = prop.key.type === AST_NODE_TYPES.Identifier && prop.key.name === "path" || prop.key.type === AST_NODE_TYPES.Literal && prop.key.value === "path";
60
- if (isPathKey) {
61
- const pathValue = getStringLiteralValue(prop.value);
62
- if (pathValue) {
63
- reportInvalidParams(prop.value, pathValue);
64
- }
65
- }
66
- }
67
- }
68
- }
69
- return;
70
- }
71
- }
72
- if (node.callee.type === AST_NODE_TYPES.CallExpression) {
73
- const innerCall = node.callee;
74
- if (innerCall.callee.type === AST_NODE_TYPES.Identifier) {
75
- const funcName = innerCall.callee.name;
76
- if (!helpers.isTanstackRouterImport(innerCall.callee)) {
77
- return;
78
- }
79
- if (pathAsFirstArgSet.has(funcName)) {
80
- const pathArg = innerCall.arguments[0];
81
- if (pathArg) {
82
- const pathValue = getStringLiteralValue(pathArg);
83
- if (pathValue) {
84
- reportInvalidParams(pathArg, pathValue);
85
- }
86
- }
87
- }
88
- }
89
- }
90
- }
91
- };
92
- })
4
+ import { getInvalidParams } from "./route-param-names.utils.js";
5
+ import { AST_NODE_TYPES, ESLintUtils } from "@typescript-eslint/utils";
6
+ //#region src/rules/route-param-names/route-param-names.rule.ts
7
+ var createRule = ESLintUtils.RuleCreator(getDocsUrl);
8
+ var pathAsFirstArgSet = new Set(pathAsFirstArgFunctions);
9
+ var pathAsPropertySet = new Set(pathAsPropertyFunctions);
10
+ var name = "route-param-names";
11
+ var rule = createRule({
12
+ name,
13
+ meta: {
14
+ type: "problem",
15
+ docs: {
16
+ description: "Ensure route param names are valid JavaScript identifiers",
17
+ recommended: "error"
18
+ },
19
+ messages: { invalidParamName: "Invalid param name \"{{paramName}}\" in route path. Param names must be valid JavaScript identifiers (match /[a-zA-Z_$][a-zA-Z0-9_$]*/)." },
20
+ schema: []
21
+ },
22
+ defaultOptions: [],
23
+ create: detectTanstackRouterImports((context, _, helpers) => {
24
+ function reportInvalidParams(node, path) {
25
+ const invalidParams = getInvalidParams(path);
26
+ for (const param of invalidParams) context.report({
27
+ node,
28
+ messageId: "invalidParamName",
29
+ data: { paramName: param.paramName }
30
+ });
31
+ }
32
+ function getStringLiteralValue(node) {
33
+ if (node.type === AST_NODE_TYPES.Literal && typeof node.value === "string") return node.value;
34
+ if (node.type === AST_NODE_TYPES.TemplateLiteral && node.quasis.length === 1) {
35
+ const cooked = node.quasis[0]?.value.cooked;
36
+ if (cooked != null) return cooked;
37
+ }
38
+ return null;
39
+ }
40
+ return { CallExpression(node) {
41
+ if (node.callee.type === AST_NODE_TYPES.Identifier) {
42
+ const funcName = node.callee.name;
43
+ if (!helpers.isTanstackRouterImport(node.callee)) return;
44
+ if (pathAsPropertySet.has(funcName)) {
45
+ const arg = node.arguments[0];
46
+ if (arg?.type === AST_NODE_TYPES.ObjectExpression) {
47
+ for (const prop of arg.properties) if (prop.type === AST_NODE_TYPES.Property) {
48
+ if (prop.key.type === AST_NODE_TYPES.Identifier && prop.key.name === "path" || prop.key.type === AST_NODE_TYPES.Literal && prop.key.value === "path") {
49
+ const pathValue = getStringLiteralValue(prop.value);
50
+ if (pathValue) reportInvalidParams(prop.value, pathValue);
51
+ }
52
+ }
53
+ }
54
+ return;
55
+ }
56
+ }
57
+ if (node.callee.type === AST_NODE_TYPES.CallExpression) {
58
+ const innerCall = node.callee;
59
+ if (innerCall.callee.type === AST_NODE_TYPES.Identifier) {
60
+ const funcName = innerCall.callee.name;
61
+ if (!helpers.isTanstackRouterImport(innerCall.callee)) return;
62
+ if (pathAsFirstArgSet.has(funcName)) {
63
+ const pathArg = innerCall.arguments[0];
64
+ if (pathArg) {
65
+ const pathValue = getStringLiteralValue(pathArg);
66
+ if (pathValue) reportInvalidParams(pathArg, pathValue);
67
+ }
68
+ }
69
+ }
70
+ }
71
+ } };
72
+ })
93
73
  });
94
- export {
95
- name,
96
- rule
97
- };
98
- //# sourceMappingURL=route-param-names.rule.js.map
74
+ //#endregion
75
+ export { name, rule };
76
+
77
+ //# sourceMappingURL=route-param-names.rule.js.map