@tanstack/eslint-plugin-router 1.161.4 → 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 +1 @@
1
- {"version":3,"file":"route-param-names.rule.js","sources":["../../../../src/rules/route-param-names/route-param-names.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 { getInvalidParams } from './route-param-names.utils'\nimport { pathAsFirstArgFunctions, pathAsPropertyFunctions } from './constants'\nimport type { TSESTree } from '@typescript-eslint/utils'\nimport type { ExtraRuleDocs } from '../../types'\n\nconst createRule = ESLintUtils.RuleCreator<ExtraRuleDocs>(getDocsUrl)\n\nconst pathAsFirstArgSet = new Set<string>(pathAsFirstArgFunctions)\nconst pathAsPropertySet = new Set<string>(pathAsPropertyFunctions)\n\nexport const name = 'route-param-names'\n\nexport const rule = createRule({\n name,\n meta: {\n type: 'problem',\n docs: {\n description: 'Ensure route param names are valid JavaScript identifiers',\n recommended: 'error',\n },\n messages: {\n invalidParamName:\n 'Invalid param name \"{{paramName}}\" in route path. Param names must be valid JavaScript identifiers (match /[a-zA-Z_$][a-zA-Z0-9_$]*/).',\n },\n schema: [],\n },\n defaultOptions: [],\n\n create: detectTanstackRouterImports((context, _, helpers) => {\n function reportInvalidParams(node: TSESTree.Node, path: string) {\n const invalidParams = getInvalidParams(path)\n\n for (const param of invalidParams) {\n context.report({\n node,\n messageId: 'invalidParamName',\n data: { paramName: param.paramName },\n })\n }\n }\n\n function getStringLiteralValue(node: TSESTree.Node): string | null {\n if (\n node.type === AST_NODE_TYPES.Literal &&\n typeof node.value === 'string'\n ) {\n return node.value\n }\n if (\n node.type === AST_NODE_TYPES.TemplateLiteral &&\n node.quasis.length === 1\n ) {\n const cooked = node.quasis[0]?.value.cooked\n if (cooked != null) {\n return cooked\n }\n }\n return null\n }\n\n return {\n CallExpression(node) {\n // Handle direct function call: createRoute({ path: '...' })\n if (node.callee.type === AST_NODE_TYPES.Identifier) {\n const funcName = node.callee.name\n\n // Skip if not imported from TanStack Router\n if (!helpers.isTanstackRouterImport(node.callee)) {\n return\n }\n\n // Case: createRoute({ path: '/path/$param' }) or createRoute({ 'path': '/path/$param' })\n if (pathAsPropertySet.has(funcName)) {\n const arg = node.arguments[0]\n if (arg?.type === AST_NODE_TYPES.ObjectExpression) {\n for (const prop of arg.properties) {\n if (prop.type === AST_NODE_TYPES.Property) {\n const isPathKey =\n (prop.key.type === AST_NODE_TYPES.Identifier &&\n prop.key.name === 'path') ||\n (prop.key.type === AST_NODE_TYPES.Literal &&\n prop.key.value === 'path')\n if (isPathKey) {\n const pathValue = getStringLiteralValue(prop.value)\n if (pathValue) {\n reportInvalidParams(prop.value, pathValue)\n }\n }\n }\n }\n }\n return\n }\n }\n\n // Handle curried function call: createFileRoute('/path')({ ... })\n if (node.callee.type === AST_NODE_TYPES.CallExpression) {\n const innerCall = node.callee\n\n if (innerCall.callee.type === AST_NODE_TYPES.Identifier) {\n const funcName = innerCall.callee.name\n\n // Skip if not imported from TanStack Router\n if (!helpers.isTanstackRouterImport(innerCall.callee)) {\n return\n }\n\n // Case: createFileRoute('/path/$param')(...) or similar\n if (pathAsFirstArgSet.has(funcName)) {\n const pathArg = innerCall.arguments[0]\n if (pathArg) {\n const pathValue = getStringLiteralValue(pathArg)\n if (pathValue) {\n reportInvalidParams(pathArg, pathValue)\n }\n }\n }\n }\n }\n },\n }\n }),\n})\n"],"names":[],"mappings":";;;;;AASA,MAAM,aAAa,YAAY,YAA2B,UAAU;AAEpE,MAAM,oBAAoB,IAAI,IAAY,uBAAuB;AACjE,MAAM,oBAAoB,IAAI,IAAY,uBAAuB;AAE1D,MAAM,OAAO;AAEb,MAAM,OAAO,WAAW;AAAA,EAC7B;AAAA,EACA,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,MAAM;AAAA,MACJ,aAAa;AAAA,MACb,aAAa;AAAA,IAAA;AAAA,IAEf,UAAU;AAAA,MACR,kBACE;AAAA,IAAA;AAAA,IAEJ,QAAQ,CAAA;AAAA,EAAC;AAAA,EAEX,gBAAgB,CAAA;AAAA,EAEhB,QAAQ,4BAA4B,CAAC,SAAS,GAAG,YAAY;AAC3D,aAAS,oBAAoB,MAAqB,MAAc;AAC9D,YAAM,gBAAgB,iBAAiB,IAAI;AAE3C,iBAAW,SAAS,eAAe;AACjC,gBAAQ,OAAO;AAAA,UACb;AAAA,UACA,WAAW;AAAA,UACX,MAAM,EAAE,WAAW,MAAM,UAAA;AAAA,QAAU,CACpC;AAAA,MACH;AAAA,IACF;AAEA,aAAS,sBAAsB,MAAoC;AACjE,UACE,KAAK,SAAS,eAAe,WAC7B,OAAO,KAAK,UAAU,UACtB;AACA,eAAO,KAAK;AAAA,MACd;AACA,UACE,KAAK,SAAS,eAAe,mBAC7B,KAAK,OAAO,WAAW,GACvB;AACA,cAAM,SAAS,KAAK,OAAO,CAAC,GAAG,MAAM;AACrC,YAAI,UAAU,MAAM;AAClB,iBAAO;AAAA,QACT;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,MACL,eAAe,MAAM;AAEnB,YAAI,KAAK,OAAO,SAAS,eAAe,YAAY;AAClD,gBAAM,WAAW,KAAK,OAAO;AAG7B,cAAI,CAAC,QAAQ,uBAAuB,KAAK,MAAM,GAAG;AAChD;AAAA,UACF;AAGA,cAAI,kBAAkB,IAAI,QAAQ,GAAG;AACnC,kBAAM,MAAM,KAAK,UAAU,CAAC;AAC5B,gBAAI,KAAK,SAAS,eAAe,kBAAkB;AACjD,yBAAW,QAAQ,IAAI,YAAY;AACjC,oBAAI,KAAK,SAAS,eAAe,UAAU;AACzC,wBAAM,YACH,KAAK,IAAI,SAAS,eAAe,cAChC,KAAK,IAAI,SAAS,UACnB,KAAK,IAAI,SAAS,eAAe,WAChC,KAAK,IAAI,UAAU;AACvB,sBAAI,WAAW;AACb,0BAAM,YAAY,sBAAsB,KAAK,KAAK;AAClD,wBAAI,WAAW;AACb,0CAAoB,KAAK,OAAO,SAAS;AAAA,oBAC3C;AAAA,kBACF;AAAA,gBACF;AAAA,cACF;AAAA,YACF;AACA;AAAA,UACF;AAAA,QACF;AAGA,YAAI,KAAK,OAAO,SAAS,eAAe,gBAAgB;AACtD,gBAAM,YAAY,KAAK;AAEvB,cAAI,UAAU,OAAO,SAAS,eAAe,YAAY;AACvD,kBAAM,WAAW,UAAU,OAAO;AAGlC,gBAAI,CAAC,QAAQ,uBAAuB,UAAU,MAAM,GAAG;AACrD;AAAA,YACF;AAGA,gBAAI,kBAAkB,IAAI,QAAQ,GAAG;AACnC,oBAAM,UAAU,UAAU,UAAU,CAAC;AACrC,kBAAI,SAAS;AACX,sBAAM,YAAY,sBAAsB,OAAO;AAC/C,oBAAI,WAAW;AACb,sCAAoB,SAAS,SAAS;AAAA,gBACxC;AAAA,cACF;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IAAA;AAAA,EAEJ,CAAC;AACH,CAAC;"}
1
+ {"version":3,"file":"route-param-names.rule.js","names":[],"sources":["../../../../src/rules/route-param-names/route-param-names.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 { getInvalidParams } from './route-param-names.utils'\nimport { pathAsFirstArgFunctions, pathAsPropertyFunctions } from './constants'\nimport type { TSESTree } from '@typescript-eslint/utils'\nimport type { ExtraRuleDocs } from '../../types'\n\nconst createRule = ESLintUtils.RuleCreator<ExtraRuleDocs>(getDocsUrl)\n\nconst pathAsFirstArgSet = new Set<string>(pathAsFirstArgFunctions)\nconst pathAsPropertySet = new Set<string>(pathAsPropertyFunctions)\n\nexport const name = 'route-param-names'\n\nexport const rule = createRule({\n name,\n meta: {\n type: 'problem',\n docs: {\n description: 'Ensure route param names are valid JavaScript identifiers',\n recommended: 'error',\n },\n messages: {\n invalidParamName:\n 'Invalid param name \"{{paramName}}\" in route path. Param names must be valid JavaScript identifiers (match /[a-zA-Z_$][a-zA-Z0-9_$]*/).',\n },\n schema: [],\n },\n defaultOptions: [],\n\n create: detectTanstackRouterImports((context, _, helpers) => {\n function reportInvalidParams(node: TSESTree.Node, path: string) {\n const invalidParams = getInvalidParams(path)\n\n for (const param of invalidParams) {\n context.report({\n node,\n messageId: 'invalidParamName',\n data: { paramName: param.paramName },\n })\n }\n }\n\n function getStringLiteralValue(node: TSESTree.Node): string | null {\n if (\n node.type === AST_NODE_TYPES.Literal &&\n typeof node.value === 'string'\n ) {\n return node.value\n }\n if (\n node.type === AST_NODE_TYPES.TemplateLiteral &&\n node.quasis.length === 1\n ) {\n const cooked = node.quasis[0]?.value.cooked\n if (cooked != null) {\n return cooked\n }\n }\n return null\n }\n\n return {\n CallExpression(node) {\n // Handle direct function call: createRoute({ path: '...' })\n if (node.callee.type === AST_NODE_TYPES.Identifier) {\n const funcName = node.callee.name\n\n // Skip if not imported from TanStack Router\n if (!helpers.isTanstackRouterImport(node.callee)) {\n return\n }\n\n // Case: createRoute({ path: '/path/$param' }) or createRoute({ 'path': '/path/$param' })\n if (pathAsPropertySet.has(funcName)) {\n const arg = node.arguments[0]\n if (arg?.type === AST_NODE_TYPES.ObjectExpression) {\n for (const prop of arg.properties) {\n if (prop.type === AST_NODE_TYPES.Property) {\n const isPathKey =\n (prop.key.type === AST_NODE_TYPES.Identifier &&\n prop.key.name === 'path') ||\n (prop.key.type === AST_NODE_TYPES.Literal &&\n prop.key.value === 'path')\n if (isPathKey) {\n const pathValue = getStringLiteralValue(prop.value)\n if (pathValue) {\n reportInvalidParams(prop.value, pathValue)\n }\n }\n }\n }\n }\n return\n }\n }\n\n // Handle curried function call: createFileRoute('/path')({ ... })\n if (node.callee.type === AST_NODE_TYPES.CallExpression) {\n const innerCall = node.callee\n\n if (innerCall.callee.type === AST_NODE_TYPES.Identifier) {\n const funcName = innerCall.callee.name\n\n // Skip if not imported from TanStack Router\n if (!helpers.isTanstackRouterImport(innerCall.callee)) {\n return\n }\n\n // Case: createFileRoute('/path/$param')(...) or similar\n if (pathAsFirstArgSet.has(funcName)) {\n const pathArg = innerCall.arguments[0]\n if (pathArg) {\n const pathValue = getStringLiteralValue(pathArg)\n if (pathValue) {\n reportInvalidParams(pathArg, pathValue)\n }\n }\n }\n }\n }\n },\n }\n }),\n})\n"],"mappings":";;;;;;AASA,IAAM,aAAa,YAAY,YAA2B,WAAW;AAErE,IAAM,oBAAoB,IAAI,IAAY,wBAAwB;AAClE,IAAM,oBAAoB,IAAI,IAAY,wBAAwB;AAElE,IAAa,OAAO;AAEpB,IAAa,OAAO,WAAW;CAC7B;CACA,MAAM;EACJ,MAAM;EACN,MAAM;GACJ,aAAa;GACb,aAAa;GACd;EACD,UAAU,EACR,kBACE,4IACH;EACD,QAAQ,EAAE;EACX;CACD,gBAAgB,EAAE;CAElB,QAAQ,6BAA6B,SAAS,GAAG,YAAY;EAC3D,SAAS,oBAAoB,MAAqB,MAAc;GAC9D,MAAM,gBAAgB,iBAAiB,KAAK;AAE5C,QAAK,MAAM,SAAS,cAClB,SAAQ,OAAO;IACb;IACA,WAAW;IACX,MAAM,EAAE,WAAW,MAAM,WAAW;IACrC,CAAC;;EAIN,SAAS,sBAAsB,MAAoC;AACjE,OACE,KAAK,SAAS,eAAe,WAC7B,OAAO,KAAK,UAAU,SAEtB,QAAO,KAAK;AAEd,OACE,KAAK,SAAS,eAAe,mBAC7B,KAAK,OAAO,WAAW,GACvB;IACA,MAAM,SAAS,KAAK,OAAO,IAAI,MAAM;AACrC,QAAI,UAAU,KACZ,QAAO;;AAGX,UAAO;;AAGT,SAAO,EACL,eAAe,MAAM;AAEnB,OAAI,KAAK,OAAO,SAAS,eAAe,YAAY;IAClD,MAAM,WAAW,KAAK,OAAO;AAG7B,QAAI,CAAC,QAAQ,uBAAuB,KAAK,OAAO,CAC9C;AAIF,QAAI,kBAAkB,IAAI,SAAS,EAAE;KACnC,MAAM,MAAM,KAAK,UAAU;AAC3B,SAAI,KAAK,SAAS,eAAe;WAC1B,MAAM,QAAQ,IAAI,WACrB,KAAI,KAAK,SAAS,eAAe;WAE5B,KAAK,IAAI,SAAS,eAAe,cAChC,KAAK,IAAI,SAAS,UACnB,KAAK,IAAI,SAAS,eAAe,WAChC,KAAK,IAAI,UAAU,QACR;QACb,MAAM,YAAY,sBAAsB,KAAK,MAAM;AACnD,YAAI,UACF,qBAAoB,KAAK,OAAO,UAAU;;;;AAMpD;;;AAKJ,OAAI,KAAK,OAAO,SAAS,eAAe,gBAAgB;IACtD,MAAM,YAAY,KAAK;AAEvB,QAAI,UAAU,OAAO,SAAS,eAAe,YAAY;KACvD,MAAM,WAAW,UAAU,OAAO;AAGlC,SAAI,CAAC,QAAQ,uBAAuB,UAAU,OAAO,CACnD;AAIF,SAAI,kBAAkB,IAAI,SAAS,EAAE;MACnC,MAAM,UAAU,UAAU,UAAU;AACpC,UAAI,SAAS;OACX,MAAM,YAAY,sBAAsB,QAAQ;AAChD,WAAI,UACF,qBAAoB,SAAS,UAAU;;;;;KAOpD;GACD;CACH,CAAC"}
@@ -1,61 +1,72 @@
1
1
  import { VALID_PARAM_NAME_REGEX } from "./constants.js";
2
+ //#region src/rules/route-param-names/route-param-names.utils.ts
3
+ /**
4
+ * Extracts param names from a route path segment.
5
+ *
6
+ * Handles these patterns:
7
+ * - $paramName -> extract "paramName"
8
+ * - {$paramName} -> extract "paramName"
9
+ * - prefix{$paramName}suffix -> extract "paramName"
10
+ * - {-$paramName} -> extract "paramName" (optional)
11
+ * - prefix{-$paramName}suffix -> extract "paramName" (optional)
12
+ * - $ or {$} -> wildcard, skip validation
13
+ */
2
14
  function extractParamsFromSegment(segment) {
3
- const params = [];
4
- if (!segment || !segment.includes("$")) {
5
- return params;
6
- }
7
- if (segment === "$" || segment === "{$}") {
8
- return params;
9
- }
10
- if (segment.startsWith("$") && !segment.includes("{")) {
11
- const paramName = segment.slice(1);
12
- if (paramName) {
13
- params.push({
14
- fullParam: segment,
15
- paramName,
16
- isOptional: false,
17
- isValid: VALID_PARAM_NAME_REGEX.test(paramName)
18
- });
19
- }
20
- return params;
21
- }
22
- const bracePattern = /\{(-?\$)([^}]*)\}/g;
23
- let match;
24
- while ((match = bracePattern.exec(segment)) !== null) {
25
- const prefix = match[1];
26
- const paramName = match[2];
27
- if (!paramName) {
28
- continue;
29
- }
30
- const isOptional = prefix === "-$";
31
- params.push({
32
- fullParam: `${prefix}${paramName}`,
33
- paramName,
34
- isOptional,
35
- isValid: VALID_PARAM_NAME_REGEX.test(paramName)
36
- });
37
- }
38
- return params;
15
+ const params = [];
16
+ if (!segment || !segment.includes("$")) return params;
17
+ if (segment === "$" || segment === "{$}") return params;
18
+ if (segment.startsWith("$") && !segment.includes("{")) {
19
+ const paramName = segment.slice(1);
20
+ if (paramName) params.push({
21
+ fullParam: segment,
22
+ paramName,
23
+ isOptional: false,
24
+ isValid: VALID_PARAM_NAME_REGEX.test(paramName)
25
+ });
26
+ return params;
27
+ }
28
+ const bracePattern = /\{(-?\$)([^}]*)\}/g;
29
+ let match;
30
+ while ((match = bracePattern.exec(segment)) !== null) {
31
+ const prefix = match[1];
32
+ const paramName = match[2];
33
+ if (!paramName) continue;
34
+ const isOptional = prefix === "-$";
35
+ params.push({
36
+ fullParam: `${prefix}${paramName}`,
37
+ paramName,
38
+ isOptional,
39
+ isValid: VALID_PARAM_NAME_REGEX.test(paramName)
40
+ });
41
+ }
42
+ return params;
39
43
  }
44
+ /**
45
+ * Extracts all params from a route path.
46
+ *
47
+ * @param path - The route path (e.g., "/users/$userId/posts/$postId")
48
+ * @returns Array of extracted params with validation info
49
+ */
40
50
  function extractParamsFromPath(path) {
41
- if (!path || !path.includes("$")) {
42
- return [];
43
- }
44
- const segments = path.split("/");
45
- const allParams = [];
46
- for (const segment of segments) {
47
- const params = extractParamsFromSegment(segment);
48
- allParams.push(...params);
49
- }
50
- return allParams;
51
+ if (!path || !path.includes("$")) return [];
52
+ const segments = path.split("/");
53
+ const allParams = [];
54
+ for (const segment of segments) {
55
+ const params = extractParamsFromSegment(segment);
56
+ allParams.push(...params);
57
+ }
58
+ return allParams;
51
59
  }
60
+ /**
61
+ * Gets all invalid params from a route path.
62
+ *
63
+ * @param path - The route path
64
+ * @returns Array of invalid param info
65
+ */
52
66
  function getInvalidParams(path) {
53
- const params = extractParamsFromPath(path);
54
- return params.filter((p) => !p.isValid);
67
+ return extractParamsFromPath(path).filter((p) => !p.isValid);
55
68
  }
56
- export {
57
- extractParamsFromPath,
58
- extractParamsFromSegment,
59
- getInvalidParams
60
- };
61
- //# sourceMappingURL=route-param-names.utils.js.map
69
+ //#endregion
70
+ export { getInvalidParams };
71
+
72
+ //# sourceMappingURL=route-param-names.utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"route-param-names.utils.js","sources":["../../../../src/rules/route-param-names/route-param-names.utils.ts"],"sourcesContent":["import { VALID_PARAM_NAME_REGEX } from './constants'\n\nexport interface ExtractedParam {\n /** The full param string including $ prefix (e.g., \"$userId\", \"-$optional\") */\n fullParam: string\n /** The param name without $ prefix (e.g., \"userId\", \"optional\") */\n paramName: string\n /** Whether this is an optional param (prefixed with -$) */\n isOptional: boolean\n /** Whether this param name is valid */\n isValid: boolean\n}\n\n/**\n * Extracts param names from a route path segment.\n *\n * Handles these patterns:\n * - $paramName -> extract \"paramName\"\n * - {$paramName} -> extract \"paramName\"\n * - prefix{$paramName}suffix -> extract \"paramName\"\n * - {-$paramName} -> extract \"paramName\" (optional)\n * - prefix{-$paramName}suffix -> extract \"paramName\" (optional)\n * - $ or {$} -> wildcard, skip validation\n */\nexport function extractParamsFromSegment(\n segment: string,\n): Array<ExtractedParam> {\n const params: Array<ExtractedParam> = []\n\n // Skip empty segments\n if (!segment || !segment.includes('$')) {\n return params\n }\n\n // Check for wildcard ($ alone or {$})\n if (segment === '$' || segment === '{$}') {\n return params // Wildcard, no param name to validate\n }\n\n // Pattern 1: Simple $paramName (entire segment starts with $)\n if (segment.startsWith('$') && !segment.includes('{')) {\n const paramName = segment.slice(1)\n if (paramName) {\n params.push({\n fullParam: segment,\n paramName,\n isOptional: false,\n isValid: VALID_PARAM_NAME_REGEX.test(paramName),\n })\n }\n return params\n }\n\n // Pattern 2: Braces pattern {$paramName} or {-$paramName} with optional prefix/suffix\n // Match patterns like: prefix{$param}suffix, {$param}, {-$param}\n const bracePattern = /\\{(-?\\$)([^}]*)\\}/g\n let match\n\n while ((match = bracePattern.exec(segment)) !== null) {\n const prefix = match[1] // \"$\" or \"-$\"\n const paramName = match[2] // The param name after $ or -$\n\n if (!paramName) {\n // This is a wildcard {$} or {-$}, skip\n continue\n }\n\n const isOptional = prefix === '-$'\n\n params.push({\n fullParam: `${prefix}${paramName}`,\n paramName,\n isOptional,\n isValid: VALID_PARAM_NAME_REGEX.test(paramName),\n })\n }\n\n return params\n}\n\n/**\n * Extracts all params from a route path.\n *\n * @param path - The route path (e.g., \"/users/$userId/posts/$postId\")\n * @returns Array of extracted params with validation info\n */\nexport function extractParamsFromPath(path: string): Array<ExtractedParam> {\n if (!path || !path.includes('$')) {\n return []\n }\n\n const segments = path.split('/')\n const allParams: Array<ExtractedParam> = []\n\n for (const segment of segments) {\n const params = extractParamsFromSegment(segment)\n allParams.push(...params)\n }\n\n return allParams\n}\n\n/**\n * Validates a single param name.\n *\n * @param paramName - The param name to validate (without $ prefix)\n * @returns Whether the param name is valid\n */\nexport function isValidParamName(paramName: string): boolean {\n return VALID_PARAM_NAME_REGEX.test(paramName)\n}\n\n/**\n * Gets all invalid params from a route path.\n *\n * @param path - The route path\n * @returns Array of invalid param info\n */\nexport function getInvalidParams(path: string): Array<ExtractedParam> {\n const params = extractParamsFromPath(path)\n return params.filter((p) => !p.isValid)\n}\n"],"names":[],"mappings":";AAwBO,SAAS,yBACd,SACuB;AACvB,QAAM,SAAgC,CAAA;AAGtC,MAAI,CAAC,WAAW,CAAC,QAAQ,SAAS,GAAG,GAAG;AACtC,WAAO;AAAA,EACT;AAGA,MAAI,YAAY,OAAO,YAAY,OAAO;AACxC,WAAO;AAAA,EACT;AAGA,MAAI,QAAQ,WAAW,GAAG,KAAK,CAAC,QAAQ,SAAS,GAAG,GAAG;AACrD,UAAM,YAAY,QAAQ,MAAM,CAAC;AACjC,QAAI,WAAW;AACb,aAAO,KAAK;AAAA,QACV,WAAW;AAAA,QACX;AAAA,QACA,YAAY;AAAA,QACZ,SAAS,uBAAuB,KAAK,SAAS;AAAA,MAAA,CAC/C;AAAA,IACH;AACA,WAAO;AAAA,EACT;AAIA,QAAM,eAAe;AACrB,MAAI;AAEJ,UAAQ,QAAQ,aAAa,KAAK,OAAO,OAAO,MAAM;AACpD,UAAM,SAAS,MAAM,CAAC;AACtB,UAAM,YAAY,MAAM,CAAC;AAEzB,QAAI,CAAC,WAAW;AAEd;AAAA,IACF;AAEA,UAAM,aAAa,WAAW;AAE9B,WAAO,KAAK;AAAA,MACV,WAAW,GAAG,MAAM,GAAG,SAAS;AAAA,MAChC;AAAA,MACA;AAAA,MACA,SAAS,uBAAuB,KAAK,SAAS;AAAA,IAAA,CAC/C;AAAA,EACH;AAEA,SAAO;AACT;AAQO,SAAS,sBAAsB,MAAqC;AACzE,MAAI,CAAC,QAAQ,CAAC,KAAK,SAAS,GAAG,GAAG;AAChC,WAAO,CAAA;AAAA,EACT;AAEA,QAAM,WAAW,KAAK,MAAM,GAAG;AAC/B,QAAM,YAAmC,CAAA;AAEzC,aAAW,WAAW,UAAU;AAC9B,UAAM,SAAS,yBAAyB,OAAO;AAC/C,cAAU,KAAK,GAAG,MAAM;AAAA,EAC1B;AAEA,SAAO;AACT;AAkBO,SAAS,iBAAiB,MAAqC;AACpE,QAAM,SAAS,sBAAsB,IAAI;AACzC,SAAO,OAAO,OAAO,CAAC,MAAM,CAAC,EAAE,OAAO;AACxC;"}
1
+ {"version":3,"file":"route-param-names.utils.js","names":[],"sources":["../../../../src/rules/route-param-names/route-param-names.utils.ts"],"sourcesContent":["import { VALID_PARAM_NAME_REGEX } from './constants'\n\nexport interface ExtractedParam {\n /** The full param string including $ prefix (e.g., \"$userId\", \"-$optional\") */\n fullParam: string\n /** The param name without $ prefix (e.g., \"userId\", \"optional\") */\n paramName: string\n /** Whether this is an optional param (prefixed with -$) */\n isOptional: boolean\n /** Whether this param name is valid */\n isValid: boolean\n}\n\n/**\n * Extracts param names from a route path segment.\n *\n * Handles these patterns:\n * - $paramName -> extract \"paramName\"\n * - {$paramName} -> extract \"paramName\"\n * - prefix{$paramName}suffix -> extract \"paramName\"\n * - {-$paramName} -> extract \"paramName\" (optional)\n * - prefix{-$paramName}suffix -> extract \"paramName\" (optional)\n * - $ or {$} -> wildcard, skip validation\n */\nexport function extractParamsFromSegment(\n segment: string,\n): Array<ExtractedParam> {\n const params: Array<ExtractedParam> = []\n\n // Skip empty segments\n if (!segment || !segment.includes('$')) {\n return params\n }\n\n // Check for wildcard ($ alone or {$})\n if (segment === '$' || segment === '{$}') {\n return params // Wildcard, no param name to validate\n }\n\n // Pattern 1: Simple $paramName (entire segment starts with $)\n if (segment.startsWith('$') && !segment.includes('{')) {\n const paramName = segment.slice(1)\n if (paramName) {\n params.push({\n fullParam: segment,\n paramName,\n isOptional: false,\n isValid: VALID_PARAM_NAME_REGEX.test(paramName),\n })\n }\n return params\n }\n\n // Pattern 2: Braces pattern {$paramName} or {-$paramName} with optional prefix/suffix\n // Match patterns like: prefix{$param}suffix, {$param}, {-$param}\n const bracePattern = /\\{(-?\\$)([^}]*)\\}/g\n let match\n\n while ((match = bracePattern.exec(segment)) !== null) {\n const prefix = match[1] // \"$\" or \"-$\"\n const paramName = match[2] // The param name after $ or -$\n\n if (!paramName) {\n // This is a wildcard {$} or {-$}, skip\n continue\n }\n\n const isOptional = prefix === '-$'\n\n params.push({\n fullParam: `${prefix}${paramName}`,\n paramName,\n isOptional,\n isValid: VALID_PARAM_NAME_REGEX.test(paramName),\n })\n }\n\n return params\n}\n\n/**\n * Extracts all params from a route path.\n *\n * @param path - The route path (e.g., \"/users/$userId/posts/$postId\")\n * @returns Array of extracted params with validation info\n */\nexport function extractParamsFromPath(path: string): Array<ExtractedParam> {\n if (!path || !path.includes('$')) {\n return []\n }\n\n const segments = path.split('/')\n const allParams: Array<ExtractedParam> = []\n\n for (const segment of segments) {\n const params = extractParamsFromSegment(segment)\n allParams.push(...params)\n }\n\n return allParams\n}\n\n/**\n * Validates a single param name.\n *\n * @param paramName - The param name to validate (without $ prefix)\n * @returns Whether the param name is valid\n */\nexport function isValidParamName(paramName: string): boolean {\n return VALID_PARAM_NAME_REGEX.test(paramName)\n}\n\n/**\n * Gets all invalid params from a route path.\n *\n * @param path - The route path\n * @returns Array of invalid param info\n */\nexport function getInvalidParams(path: string): Array<ExtractedParam> {\n const params = extractParamsFromPath(path)\n return params.filter((p) => !p.isValid)\n}\n"],"mappings":";;;;;;;;;;;;;AAwBA,SAAgB,yBACd,SACuB;CACvB,MAAM,SAAgC,EAAE;AAGxC,KAAI,CAAC,WAAW,CAAC,QAAQ,SAAS,IAAI,CACpC,QAAO;AAIT,KAAI,YAAY,OAAO,YAAY,MACjC,QAAO;AAIT,KAAI,QAAQ,WAAW,IAAI,IAAI,CAAC,QAAQ,SAAS,IAAI,EAAE;EACrD,MAAM,YAAY,QAAQ,MAAM,EAAE;AAClC,MAAI,UACF,QAAO,KAAK;GACV,WAAW;GACX;GACA,YAAY;GACZ,SAAS,uBAAuB,KAAK,UAAU;GAChD,CAAC;AAEJ,SAAO;;CAKT,MAAM,eAAe;CACrB,IAAI;AAEJ,SAAQ,QAAQ,aAAa,KAAK,QAAQ,MAAM,MAAM;EACpD,MAAM,SAAS,MAAM;EACrB,MAAM,YAAY,MAAM;AAExB,MAAI,CAAC,UAEH;EAGF,MAAM,aAAa,WAAW;AAE9B,SAAO,KAAK;GACV,WAAW,GAAG,SAAS;GACvB;GACA;GACA,SAAS,uBAAuB,KAAK,UAAU;GAChD,CAAC;;AAGJ,QAAO;;;;;;;;AAST,SAAgB,sBAAsB,MAAqC;AACzE,KAAI,CAAC,QAAQ,CAAC,KAAK,SAAS,IAAI,CAC9B,QAAO,EAAE;CAGX,MAAM,WAAW,KAAK,MAAM,IAAI;CAChC,MAAM,YAAmC,EAAE;AAE3C,MAAK,MAAM,WAAW,UAAU;EAC9B,MAAM,SAAS,yBAAyB,QAAQ;AAChD,YAAU,KAAK,GAAG,OAAO;;AAG3B,QAAO;;;;;;;;AAmBT,SAAgB,iBAAiB,MAAqC;AAEpE,QADe,sBAAsB,KAAK,CAC5B,QAAQ,MAAM,CAAC,EAAE,QAAQ"}
package/dist/esm/rules.js CHANGED
@@ -1,10 +1,11 @@
1
- import { rule as rule$1, name as name$1 } from "./rules/create-route-property-order/create-route-property-order.rule.js";
2
- import { rule, name } from "./rules/route-param-names/route-param-names.rule.js";
3
- const rules = {
4
- [name$1]: rule$1,
5
- [name]: rule
1
+ import { name, rule } from "./rules/create-route-property-order/create-route-property-order.rule.js";
2
+ import { name as name$1, rule as rule$1 } from "./rules/route-param-names/route-param-names.rule.js";
3
+ //#region src/rules.ts
4
+ var rules = {
5
+ [name]: rule,
6
+ [name$1]: rule$1
6
7
  };
7
- export {
8
- rules
9
- };
10
- //# sourceMappingURL=rules.js.map
8
+ //#endregion
9
+ export { rules };
10
+
11
+ //# sourceMappingURL=rules.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"rules.js","sources":["../../src/rules.ts"],"sourcesContent":["import * as createRoutePropertyOrder from './rules/create-route-property-order/create-route-property-order.rule'\nimport * as routeParamNames from './rules/route-param-names/route-param-names.rule'\nimport type { ESLintUtils } from '@typescript-eslint/utils'\nimport type { ExtraRuleDocs } from './types'\n\nexport const rules: Record<\n string,\n ESLintUtils.RuleModule<\n string,\n ReadonlyArray<unknown>,\n ExtraRuleDocs,\n ESLintUtils.RuleListener\n >\n> = {\n [createRoutePropertyOrder.name]: createRoutePropertyOrder.rule,\n [routeParamNames.name]: routeParamNames.rule,\n}\n"],"names":["createRoutePropertyOrder.name","createRoutePropertyOrder.rule","routeParamNames.name","routeParamNames.rule"],"mappings":";;AAKO,MAAM,QAQT;AAAA,EACF,CAACA,MAA6B,GAAGC;AAAAA,EACjC,CAACC,IAAoB,GAAGC;AAC1B;"}
1
+ {"version":3,"file":"rules.js","names":[],"sources":["../../src/rules.ts"],"sourcesContent":["import * as createRoutePropertyOrder from './rules/create-route-property-order/create-route-property-order.rule'\nimport * as routeParamNames from './rules/route-param-names/route-param-names.rule'\nimport type { ESLintUtils } from '@typescript-eslint/utils'\nimport type { ExtraRuleDocs } from './types'\n\nexport const rules: Record<\n string,\n ESLintUtils.RuleModule<\n string,\n ReadonlyArray<unknown>,\n ExtraRuleDocs,\n ESLintUtils.RuleListener\n >\n> = {\n [createRoutePropertyOrder.name]: createRoutePropertyOrder.rule,\n [routeParamNames.name]: routeParamNames.rule,\n}\n"],"mappings":";;;AAKA,IAAa,QAQT;EACD,OAAgC;EAChC,SAAuB;CACzB"}
@@ -1,54 +1,38 @@
1
1
  import { TSESTree } from "@typescript-eslint/utils";
2
+ //#region src/utils/detect-router-imports.ts
2
3
  function detectTanstackRouterImports(create) {
3
- return (context, optionsWithDefault) => {
4
- const tanstackRouterImportSpecifiers = [];
5
- const helpers = {
6
- isSpecificTanstackRouterImport(node, source) {
7
- return !!tanstackRouterImportSpecifiers.find((specifier) => {
8
- if (specifier.type === TSESTree.AST_NODE_TYPES.ImportSpecifier && specifier.parent.type === TSESTree.AST_NODE_TYPES.ImportDeclaration && specifier.parent.source.value === source) {
9
- return node.name === specifier.local.name;
10
- }
11
- return false;
12
- });
13
- },
14
- isTanstackRouterImport(node) {
15
- return !!tanstackRouterImportSpecifiers.find((specifier) => {
16
- if (specifier.type === TSESTree.AST_NODE_TYPES.ImportSpecifier) {
17
- return node.name === specifier.local.name;
18
- }
19
- return false;
20
- });
21
- }
22
- };
23
- const detectionInstructions = {
24
- ImportDeclaration(node) {
25
- if (node.specifiers.length > 0 && // `importKind` is parser-dependent and can be undefined (eg. Espree)
26
- node.importKind !== "type" && node.source.value.startsWith("@tanstack/") && node.source.value.endsWith("-router")) {
27
- tanstackRouterImportSpecifiers.push(...node.specifiers);
28
- }
29
- }
30
- };
31
- const ruleInstructions = create(context, optionsWithDefault, helpers);
32
- const enhancedRuleInstructions = {};
33
- const allKeys = new Set(
34
- Object.keys(detectionInstructions).concat(Object.keys(ruleInstructions))
35
- );
36
- allKeys.forEach((instruction) => {
37
- enhancedRuleInstructions[instruction] = (node) => {
38
- if (instruction in detectionInstructions) {
39
- detectionInstructions[instruction]?.(node);
40
- }
41
- const ruleFunction = ruleInstructions[instruction];
42
- if (ruleFunction !== void 0) {
43
- return ruleFunction(node);
44
- }
45
- return void 0;
46
- };
47
- });
48
- return enhancedRuleInstructions;
49
- };
4
+ return (context, optionsWithDefault) => {
5
+ const tanstackRouterImportSpecifiers = [];
6
+ const helpers = {
7
+ isSpecificTanstackRouterImport(node, source) {
8
+ return !!tanstackRouterImportSpecifiers.find((specifier) => {
9
+ if (specifier.type === TSESTree.AST_NODE_TYPES.ImportSpecifier && specifier.parent.type === TSESTree.AST_NODE_TYPES.ImportDeclaration && specifier.parent.source.value === source) return node.name === specifier.local.name;
10
+ return false;
11
+ });
12
+ },
13
+ isTanstackRouterImport(node) {
14
+ return !!tanstackRouterImportSpecifiers.find((specifier) => {
15
+ if (specifier.type === TSESTree.AST_NODE_TYPES.ImportSpecifier) return node.name === specifier.local.name;
16
+ return false;
17
+ });
18
+ }
19
+ };
20
+ const detectionInstructions = { ImportDeclaration(node) {
21
+ if (node.specifiers.length > 0 && node.importKind !== "type" && node.source.value.startsWith("@tanstack/") && node.source.value.endsWith("-router")) tanstackRouterImportSpecifiers.push(...node.specifiers);
22
+ } };
23
+ const ruleInstructions = create(context, optionsWithDefault, helpers);
24
+ const enhancedRuleInstructions = {};
25
+ new Set(Object.keys(detectionInstructions).concat(Object.keys(ruleInstructions))).forEach((instruction) => {
26
+ enhancedRuleInstructions[instruction] = (node) => {
27
+ if (instruction in detectionInstructions) detectionInstructions[instruction]?.(node);
28
+ const ruleFunction = ruleInstructions[instruction];
29
+ if (ruleFunction !== void 0) return ruleFunction(node);
30
+ };
31
+ });
32
+ return enhancedRuleInstructions;
33
+ };
50
34
  }
51
- export {
52
- detectTanstackRouterImports
53
- };
54
- //# sourceMappingURL=detect-router-imports.js.map
35
+ //#endregion
36
+ export { detectTanstackRouterImports };
37
+
38
+ //# sourceMappingURL=detect-router-imports.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"detect-router-imports.js","sources":["../../../src/utils/detect-router-imports.ts"],"sourcesContent":["import { TSESTree } from '@typescript-eslint/utils'\nimport type { ESLintUtils, TSESLint } from '@typescript-eslint/utils'\n\ntype Create = Parameters<\n ReturnType<typeof ESLintUtils.RuleCreator>\n>[0]['create']\n\ntype Context = Parameters<Create>[0]\ntype Options = Parameters<Create>[1]\ntype Helpers = {\n isSpecificTanstackRouterImport: (\n node: TSESTree.Identifier,\n source: string,\n ) => boolean\n isTanstackRouterImport: (node: TSESTree.Identifier) => boolean\n}\n\ntype EnhancedCreate = (\n context: Context,\n options: Options,\n helpers: Helpers,\n) => ReturnType<Create>\n\nexport function detectTanstackRouterImports(create: EnhancedCreate): Create {\n return (context, optionsWithDefault) => {\n const tanstackRouterImportSpecifiers: Array<TSESTree.ImportClause> = []\n\n const helpers: Helpers = {\n isSpecificTanstackRouterImport(node, source) {\n return !!tanstackRouterImportSpecifiers.find((specifier) => {\n if (\n specifier.type === TSESTree.AST_NODE_TYPES.ImportSpecifier &&\n specifier.parent.type ===\n TSESTree.AST_NODE_TYPES.ImportDeclaration &&\n specifier.parent.source.value === source\n ) {\n return node.name === specifier.local.name\n }\n\n return false\n })\n },\n isTanstackRouterImport(node) {\n return !!tanstackRouterImportSpecifiers.find((specifier) => {\n if (specifier.type === TSESTree.AST_NODE_TYPES.ImportSpecifier) {\n return node.name === specifier.local.name\n }\n\n return false\n })\n },\n }\n\n const detectionInstructions: TSESLint.RuleListener = {\n ImportDeclaration(node) {\n if (\n node.specifiers.length > 0 &&\n // `importKind` is parser-dependent and can be undefined (eg. Espree)\n node.importKind !== 'type' &&\n node.source.value.startsWith('@tanstack/') &&\n node.source.value.endsWith('-router')\n ) {\n tanstackRouterImportSpecifiers.push(...node.specifiers)\n }\n },\n }\n\n // Call original rule definition\n const ruleInstructions = create(context, optionsWithDefault, helpers)\n const enhancedRuleInstructions: TSESLint.RuleListener = {}\n\n const allKeys = new Set(\n Object.keys(detectionInstructions).concat(Object.keys(ruleInstructions)),\n )\n\n // Iterate over ALL instructions keys so we can override original rule instructions\n // to prevent their execution if conditions to report errors are not met.\n allKeys.forEach((instruction) => {\n enhancedRuleInstructions[instruction] = (node) => {\n if (instruction in detectionInstructions) {\n detectionInstructions[instruction]?.(node)\n }\n\n const ruleFunction = ruleInstructions[instruction]\n if (ruleFunction !== undefined) {\n return ruleFunction(node)\n }\n\n return undefined\n }\n })\n\n return enhancedRuleInstructions\n }\n}\n"],"names":[],"mappings":";AAuBO,SAAS,4BAA4B,QAAgC;AAC1E,SAAO,CAAC,SAAS,uBAAuB;AACtC,UAAM,iCAA+D,CAAA;AAErE,UAAM,UAAmB;AAAA,MACvB,+BAA+B,MAAM,QAAQ;AAC3C,eAAO,CAAC,CAAC,+BAA+B,KAAK,CAAC,cAAc;AAC1D,cACE,UAAU,SAAS,SAAS,eAAe,mBAC3C,UAAU,OAAO,SACf,SAAS,eAAe,qBAC1B,UAAU,OAAO,OAAO,UAAU,QAClC;AACA,mBAAO,KAAK,SAAS,UAAU,MAAM;AAAA,UACvC;AAEA,iBAAO;AAAA,QACT,CAAC;AAAA,MACH;AAAA,MACA,uBAAuB,MAAM;AAC3B,eAAO,CAAC,CAAC,+BAA+B,KAAK,CAAC,cAAc;AAC1D,cAAI,UAAU,SAAS,SAAS,eAAe,iBAAiB;AAC9D,mBAAO,KAAK,SAAS,UAAU,MAAM;AAAA,UACvC;AAEA,iBAAO;AAAA,QACT,CAAC;AAAA,MACH;AAAA,IAAA;AAGF,UAAM,wBAA+C;AAAA,MACnD,kBAAkB,MAAM;AACtB,YACE,KAAK,WAAW,SAAS;AAAA,QAEzB,KAAK,eAAe,UACpB,KAAK,OAAO,MAAM,WAAW,YAAY,KACzC,KAAK,OAAO,MAAM,SAAS,SAAS,GACpC;AACA,yCAA+B,KAAK,GAAG,KAAK,UAAU;AAAA,QACxD;AAAA,MACF;AAAA,IAAA;AAIF,UAAM,mBAAmB,OAAO,SAAS,oBAAoB,OAAO;AACpE,UAAM,2BAAkD,CAAA;AAExD,UAAM,UAAU,IAAI;AAAA,MAClB,OAAO,KAAK,qBAAqB,EAAE,OAAO,OAAO,KAAK,gBAAgB,CAAC;AAAA,IAAA;AAKzE,YAAQ,QAAQ,CAAC,gBAAgB;AAC/B,+BAAyB,WAAW,IAAI,CAAC,SAAS;AAChD,YAAI,eAAe,uBAAuB;AACxC,gCAAsB,WAAW,IAAI,IAAI;AAAA,QAC3C;AAEA,cAAM,eAAe,iBAAiB,WAAW;AACjD,YAAI,iBAAiB,QAAW;AAC9B,iBAAO,aAAa,IAAI;AAAA,QAC1B;AAEA,eAAO;AAAA,MACT;AAAA,IACF,CAAC;AAED,WAAO;AAAA,EACT;AACF;"}
1
+ {"version":3,"file":"detect-router-imports.js","names":[],"sources":["../../../src/utils/detect-router-imports.ts"],"sourcesContent":["import { TSESTree } from '@typescript-eslint/utils'\nimport type { ESLintUtils, TSESLint } from '@typescript-eslint/utils'\n\ntype Create = Parameters<\n ReturnType<typeof ESLintUtils.RuleCreator>\n>[0]['create']\n\ntype Context = Parameters<Create>[0]\ntype Options = Parameters<Create>[1]\ntype Helpers = {\n isSpecificTanstackRouterImport: (\n node: TSESTree.Identifier,\n source: string,\n ) => boolean\n isTanstackRouterImport: (node: TSESTree.Identifier) => boolean\n}\n\ntype EnhancedCreate = (\n context: Context,\n options: Options,\n helpers: Helpers,\n) => ReturnType<Create>\n\nexport function detectTanstackRouterImports(create: EnhancedCreate): Create {\n return (context, optionsWithDefault) => {\n const tanstackRouterImportSpecifiers: Array<TSESTree.ImportClause> = []\n\n const helpers: Helpers = {\n isSpecificTanstackRouterImport(node, source) {\n return !!tanstackRouterImportSpecifiers.find((specifier) => {\n if (\n specifier.type === TSESTree.AST_NODE_TYPES.ImportSpecifier &&\n specifier.parent.type ===\n TSESTree.AST_NODE_TYPES.ImportDeclaration &&\n specifier.parent.source.value === source\n ) {\n return node.name === specifier.local.name\n }\n\n return false\n })\n },\n isTanstackRouterImport(node) {\n return !!tanstackRouterImportSpecifiers.find((specifier) => {\n if (specifier.type === TSESTree.AST_NODE_TYPES.ImportSpecifier) {\n return node.name === specifier.local.name\n }\n\n return false\n })\n },\n }\n\n const detectionInstructions: TSESLint.RuleListener = {\n ImportDeclaration(node) {\n if (\n node.specifiers.length > 0 &&\n // `importKind` is parser-dependent and can be undefined (eg. Espree)\n node.importKind !== 'type' &&\n node.source.value.startsWith('@tanstack/') &&\n node.source.value.endsWith('-router')\n ) {\n tanstackRouterImportSpecifiers.push(...node.specifiers)\n }\n },\n }\n\n // Call original rule definition\n const ruleInstructions = create(context, optionsWithDefault, helpers)\n const enhancedRuleInstructions: TSESLint.RuleListener = {}\n\n const allKeys = new Set(\n Object.keys(detectionInstructions).concat(Object.keys(ruleInstructions)),\n )\n\n // Iterate over ALL instructions keys so we can override original rule instructions\n // to prevent their execution if conditions to report errors are not met.\n allKeys.forEach((instruction) => {\n enhancedRuleInstructions[instruction] = (node) => {\n if (instruction in detectionInstructions) {\n detectionInstructions[instruction]?.(node)\n }\n\n const ruleFunction = ruleInstructions[instruction]\n if (ruleFunction !== undefined) {\n return ruleFunction(node)\n }\n\n return undefined\n }\n })\n\n return enhancedRuleInstructions\n }\n}\n"],"mappings":";;AAuBA,SAAgB,4BAA4B,QAAgC;AAC1E,SAAQ,SAAS,uBAAuB;EACtC,MAAM,iCAA+D,EAAE;EAEvE,MAAM,UAAmB;GACvB,+BAA+B,MAAM,QAAQ;AAC3C,WAAO,CAAC,CAAC,+BAA+B,MAAM,cAAc;AAC1D,SACE,UAAU,SAAS,SAAS,eAAe,mBAC3C,UAAU,OAAO,SACf,SAAS,eAAe,qBAC1B,UAAU,OAAO,OAAO,UAAU,OAElC,QAAO,KAAK,SAAS,UAAU,MAAM;AAGvC,YAAO;MACP;;GAEJ,uBAAuB,MAAM;AAC3B,WAAO,CAAC,CAAC,+BAA+B,MAAM,cAAc;AAC1D,SAAI,UAAU,SAAS,SAAS,eAAe,gBAC7C,QAAO,KAAK,SAAS,UAAU,MAAM;AAGvC,YAAO;MACP;;GAEL;EAED,MAAM,wBAA+C,EACnD,kBAAkB,MAAM;AACtB,OACE,KAAK,WAAW,SAAS,KAEzB,KAAK,eAAe,UACpB,KAAK,OAAO,MAAM,WAAW,aAAa,IAC1C,KAAK,OAAO,MAAM,SAAS,UAAU,CAErC,gCAA+B,KAAK,GAAG,KAAK,WAAW;KAG5D;EAGD,MAAM,mBAAmB,OAAO,SAAS,oBAAoB,QAAQ;EACrE,MAAM,2BAAkD,EAAE;AAE1C,MAAI,IAClB,OAAO,KAAK,sBAAsB,CAAC,OAAO,OAAO,KAAK,iBAAiB,CAAC,CACzE,CAIO,SAAS,gBAAgB;AAC/B,4BAAyB,gBAAgB,SAAS;AAChD,QAAI,eAAe,sBACjB,uBAAsB,eAAe,KAAK;IAG5C,MAAM,eAAe,iBAAiB;AACtC,QAAI,iBAAiB,KAAA,EACnB,QAAO,aAAa,KAAK;;IAK7B;AAEF,SAAO"}
@@ -1,5 +1,6 @@
1
- const getDocsUrl = (ruleName) => `https://tanstack.com/router/latest/docs/eslint/${ruleName}`;
2
- export {
3
- getDocsUrl
4
- };
5
- //# sourceMappingURL=get-docs-url.js.map
1
+ //#region src/utils/get-docs-url.ts
2
+ var getDocsUrl = (ruleName) => `https://tanstack.com/router/latest/docs/eslint/${ruleName}`;
3
+ //#endregion
4
+ export { getDocsUrl };
5
+
6
+ //# sourceMappingURL=get-docs-url.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-docs-url.js","sources":["../../../src/utils/get-docs-url.ts"],"sourcesContent":["export const getDocsUrl = (ruleName: string): string =>\n `https://tanstack.com/router/latest/docs/eslint/${ruleName}`\n"],"names":[],"mappings":"AAAO,MAAM,aAAa,CAAC,aACzB,kDAAkD,QAAQ;"}
1
+ {"version":3,"file":"get-docs-url.js","names":[],"sources":["../../../src/utils/get-docs-url.ts"],"sourcesContent":["export const getDocsUrl = (ruleName: string): string =>\n `https://tanstack.com/router/latest/docs/eslint/${ruleName}`\n"],"mappings":";AAAA,IAAa,cAAc,aACzB,kDAAkD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/eslint-plugin-router",
3
- "version": "1.161.4",
3
+ "version": "1.161.6",
4
4
  "description": "ESLint plugin for TanStack Router",
5
5
  "author": "Manuel Schiller",
6
6
  "license": "MIT",