@tanstack/eslint-plugin-router 1.20.3-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/cjs/index.cjs +29 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +13 -0
- package/dist/cjs/rules/create-route-property-order/constants.cjs +40 -0
- package/dist/cjs/rules/create-route-property-order/constants.cjs.map +1 -0
- package/dist/cjs/rules/create-route-property-order/constants.d.cts +7 -0
- package/dist/cjs/rules/create-route-property-order/create-route-property-order.rule.cjs +103 -0
- package/dist/cjs/rules/create-route-property-order/create-route-property-order.rule.cjs.map +1 -0
- package/dist/cjs/rules/create-route-property-order/create-route-property-order.rule.d.cts +4 -0
- package/dist/cjs/rules/create-route-property-order/create-route-property-order.utils.cjs +51 -0
- package/dist/cjs/rules/create-route-property-order/create-route-property-order.utils.cjs.map +1 -0
- package/dist/cjs/rules/create-route-property-order/create-route-property-order.utils.d.cts +2 -0
- package/dist/cjs/rules.cjs +8 -0
- package/dist/cjs/rules.cjs.map +1 -0
- package/dist/cjs/rules.d.cts +3 -0
- package/dist/cjs/types.d.cts +3 -0
- package/dist/cjs/utils/detect-router-imports.cjs +54 -0
- package/dist/cjs/utils/detect-router-imports.cjs.map +1 -0
- package/dist/cjs/utils/detect-router-imports.d.cts +11 -0
- package/dist/cjs/utils/get-docs-url.cjs +5 -0
- package/dist/cjs/utils/get-docs-url.cjs.map +1 -0
- package/dist/cjs/utils/get-docs-url.d.cts +1 -0
- package/dist/esm/index.d.ts +13 -0
- package/dist/esm/index.js +30 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/rules/create-route-property-order/constants.d.ts +7 -0
- package/dist/esm/rules/create-route-property-order/constants.js +40 -0
- package/dist/esm/rules/create-route-property-order/constants.js.map +1 -0
- package/dist/esm/rules/create-route-property-order/create-route-property-order.rule.d.ts +4 -0
- package/dist/esm/rules/create-route-property-order/create-route-property-order.rule.js +103 -0
- package/dist/esm/rules/create-route-property-order/create-route-property-order.rule.js.map +1 -0
- package/dist/esm/rules/create-route-property-order/create-route-property-order.utils.d.ts +2 -0
- package/dist/esm/rules/create-route-property-order/create-route-property-order.utils.js +51 -0
- package/dist/esm/rules/create-route-property-order/create-route-property-order.utils.js.map +1 -0
- package/dist/esm/rules.d.ts +3 -0
- package/dist/esm/rules.js +8 -0
- package/dist/esm/rules.js.map +1 -0
- package/dist/esm/types.d.ts +3 -0
- package/dist/esm/utils/detect-router-imports.d.ts +11 -0
- package/dist/esm/utils/detect-router-imports.js +54 -0
- package/dist/esm/utils/detect-router-imports.js.map +1 -0
- package/dist/esm/utils/get-docs-url.d.ts +1 -0
- package/dist/esm/utils/get-docs-url.js +5 -0
- package/dist/esm/utils/get-docs-url.js.map +1 -0
- package/package.json +51 -0
- package/src/__tests__/create-route-property-order.rule.test.ts +199 -0
- package/src/__tests__/create-route-property-order.utils.test.ts +179 -0
- package/src/__tests__/test-utils.test.ts +104 -0
- package/src/__tests__/test-utils.ts +108 -0
- package/src/index.ts +43 -0
- package/src/rules/create-route-property-order/constants.ts +40 -0
- package/src/rules/create-route-property-order/create-route-property-order.rule.ts +124 -0
- package/src/rules/create-route-property-order/create-route-property-order.utils.ts +73 -0
- package/src/rules.ts +15 -0
- package/src/types.ts +3 -0
- package/src/utils/detect-router-imports.ts +94 -0
- package/src/utils/get-docs-url.ts +2 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { ESLintUtils, AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
2
|
+
import { getDocsUrl } from "../../utils/get-docs-url.js";
|
|
3
|
+
import { detectTanstackRouterImports } from "../../utils/detect-router-imports.js";
|
|
4
|
+
import { sortDataByOrder } from "./create-route-property-order.utils.js";
|
|
5
|
+
import { createRouteFunctions, createRouteFunctionsIndirect, sortRules } from "./constants.js";
|
|
6
|
+
const createRule = ESLintUtils.RuleCreator(getDocsUrl);
|
|
7
|
+
const createRouteFunctionSet = new Set(createRouteFunctions);
|
|
8
|
+
function isCreateRouteFunction(node) {
|
|
9
|
+
return createRouteFunctionSet.has(node);
|
|
10
|
+
}
|
|
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
|
+
})
|
|
98
|
+
});
|
|
99
|
+
export {
|
|
100
|
+
name,
|
|
101
|
+
rule
|
|
102
|
+
};
|
|
103
|
+
//# sourceMappingURL=create-route-property-order.rule.js.map
|
|
@@ -0,0 +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;AAC9D,SAAA,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,IACf;AAAA,IACA,UAAU;AAAA,MACR,cAAc;AAAA,IAChB;AAAA,IACA,QAAQ,CAAC;AAAA,IACT,gBAAgB;AAAA,IAChB,SAAS;AAAA,EACX;AAAA,EACA,gBAAgB,CAAC;AAAA,EAEjB,QAAQ,4BAA4B,CAAC,YAAY;AACxC,WAAA;AAAA,MACL,eAAe,MAAM;AACnB,YAAI,KAAK,OAAO,SAAS,eAAe,YAAY;AAClD;AAAA,QAAA;AAEI,cAAA,sBAAsB,KAAK,OAAO;AACpC,YAAA,CAAC,sBAAsB,mBAAmB,GAAG;AAC/C;AAAA,QAAA;AAEF,YAAI,OAAO,KAAK;AACZ,YAAA,6BAA6B,SAAS,mBAA0B,GAAG;AACrE,cAAI,KAAK,OAAO,SAAS,eAAe,gBAAgB;AACtD,mBAAO,KAAK,OAAO;AAAA,UAAA,OACd;AACL;AAAA,UAAA;AAAA,QACF;AAGI,cAAA,WAAW,KAAK,CAAC;AACvB,YAAI,aAAa,UAAa,SAAS,SAAS,oBAAoB;AAClE;AAAA,QAAA;AAGF,cAAM,gBAAgB,SAAS;AAE3B,YAAA,cAAc,SAAS,GAAG;AAC5B;AAAA,QAAA;AAGF,cAAM,aAAa,cAAc,QAAQ,CAAC,MAAM;AAE5C,cAAA,EAAE,SAAS,eAAe,YAC1B,EAAE,IAAI,SAAS,eAAe,YAC9B;AACA,mBAAO,EAAE,MAAM,EAAE,IAAI,MAAM,UAAU,EAAE;AAAA,UAC9B,WAAA,EAAE,SAAS,eAAe,eAAe;AAClD,gBAAI,EAAE,SAAS,SAAS,eAAe,YAAY;AACjD,qBAAO,EAAE,MAAM,EAAE,SAAS,MAAM,UAAU,EAAE;AAAA,YAAA,OACvC;AACC,oBAAA,IAAI,MAAM,4BAA4B;AAAA,YAAA;AAAA,UAC9C;AAEF,iBAAO,CAAC;AAAA,QAAA,CACT;AAED,cAAM,mBAAmB,gBAAgB,YAAY,WAAW,MAAM;AACtE,YAAI,qBAAqB,MAAM;AAC7B;AAAA,QAAA;AAEF,gBAAQ,OAAO;AAAA,UACb,MAAM;AAAA,UACN,MAAM,EAAE,UAAU,KAAK,OAAO,KAAK;AAAA,UACnC,WAAW;AAAA,UACX,IAAI,OAAO;AACT,kBAAM,aAAa,QAAQ;AAE3B,kBAAM,OAAO,iBAAiB;AAAA,cAC5B,CAAC,YAAY,WAAW,UAAU;AAChC,oBAAIA,QAAO;AACP,oBAAA,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,kBACnC;AAAA,gBAAA;AAEJ,uBACE,aAAa,WAAW,QAAQ,UAAU,QAAQ,IAAIA;AAAAA,cAE1D;AAAA,cACA;AAAA,YACF;AACA,mBAAO,MAAM;AAAA,cACX,CAAC,cAAc,CAAC,EAAG,MAAM,CAAC,GAAG,cAAc,GAAG,EAAE,EAAG,MAAM,CAAC,CAAC;AAAA,cAC3D;AAAA,YACF;AAAA,UAAA;AAAA,QACF,CACD;AAAA,MAAA;AAAA,IAEL;AAAA,EACD,CAAA;AACH,CAAC;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare function sortDataByOrder<T, TKey extends keyof T>(data: Array<T> | ReadonlyArray<T>, orderRules: ReadonlyArray<Readonly<[ReadonlyArray<T[TKey]>, ReadonlyArray<T[TKey]>]>>, key: TKey): Array<T> | null;
|
|
2
|
+
export declare function getCheckedProperties<T>(orderRules: ReadonlyArray<ReadonlyArray<ReadonlyArray<T>>>): ReadonlyArray<T>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
function sortDataByOrder(data, orderRules, key) {
|
|
2
|
+
const getSubsetIndex = (item, subsets) => {
|
|
3
|
+
var _a;
|
|
4
|
+
for (let i = 0; i < subsets.length; i++) {
|
|
5
|
+
if ((_a = subsets[i]) == null ? void 0 : _a.includes(item)) {
|
|
6
|
+
return i;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return null;
|
|
10
|
+
};
|
|
11
|
+
const orderSets = orderRules.reduce(
|
|
12
|
+
(sets, [A, B]) => [...sets, A, B],
|
|
13
|
+
[]
|
|
14
|
+
);
|
|
15
|
+
const inOrderArray = data.filter(
|
|
16
|
+
(item) => getSubsetIndex(item[key], orderSets) !== null
|
|
17
|
+
);
|
|
18
|
+
let wasResorted = false;
|
|
19
|
+
const sortedArray = inOrderArray.sort((a, b) => {
|
|
20
|
+
const aKey = a[key], bKey = b[key];
|
|
21
|
+
const aSubsetIndex = getSubsetIndex(aKey, orderSets);
|
|
22
|
+
const bSubsetIndex = getSubsetIndex(bKey, orderSets);
|
|
23
|
+
if (aSubsetIndex !== null && bSubsetIndex !== null && aSubsetIndex !== bSubsetIndex) {
|
|
24
|
+
return aSubsetIndex - bSubsetIndex;
|
|
25
|
+
}
|
|
26
|
+
return 0;
|
|
27
|
+
});
|
|
28
|
+
const inOrderIterator = sortedArray.values();
|
|
29
|
+
const result = data.map((item) => {
|
|
30
|
+
if (getSubsetIndex(item[key], orderSets) !== null) {
|
|
31
|
+
const sortedItem = inOrderIterator.next().value;
|
|
32
|
+
if (sortedItem[key] !== item[key]) {
|
|
33
|
+
wasResorted = true;
|
|
34
|
+
}
|
|
35
|
+
return sortedItem;
|
|
36
|
+
}
|
|
37
|
+
return item;
|
|
38
|
+
});
|
|
39
|
+
if (!wasResorted) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
function getCheckedProperties(orderRules) {
|
|
45
|
+
return [...new Set(orderRules.flat(2))];
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
getCheckedProperties,
|
|
49
|
+
sortDataByOrder
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=create-route-property-order.utils.js.map
|
|
@@ -0,0 +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":"AAAgB,SAAA,gBACd,MACA,YAGA,KACiB;AACX,QAAA,iBAAiB,CACrB,MACA,YACkB;AAVN;AAWZ,aAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,WAAI,aAAQ,CAAC,MAAT,mBAAY,SAAS,OAAO;AACvB,eAAA;AAAA,MAAA;AAAA,IACT;AAEK,WAAA;AAAA,EACT;AAEA,QAAM,YAAY,WAAW;AAAA,IAC3B,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,GAAG,CAAC;AAAA,IAChC,CAAA;AAAA,EACF;AAEA,QAAM,eAAe,KAAK;AAAA,IACxB,CAAC,SAAS,eAAe,KAAK,GAAG,GAAG,SAAS,MAAM;AAAA,EACrD;AAEA,MAAI,cAAc;AAGlB,QAAM,cAAc,aAAa,KAAK,CAAC,GAAG,MAAM;AAC9C,UAAM,OAAO,EAAE,GAAG,GAChB,OAAO,EAAE,GAAG;AACR,UAAA,eAAe,eAAe,MAAM,SAAS;AAC7C,UAAA,eAAe,eAAe,MAAM,SAAS;AAGnD,QACE,iBAAiB,QACjB,iBAAiB,QACjB,iBAAiB,cACjB;AACA,aAAO,eAAe;AAAA,IAAA;AAIjB,WAAA;AAAA,EAAA,CACR;AAEK,QAAA,kBAAkB,YAAY,OAAO;AAC3C,QAAM,SAAS,KAAK,IAAI,CAAC,SAAS;AAChC,QAAI,eAAe,KAAK,GAAG,GAAG,SAAS,MAAM,MAAM;AAC3C,YAAA,aAAa,gBAAgB,KAAA,EAAO;AAC1C,UAAI,WAAW,GAAG,MAAM,KAAK,GAAG,GAAG;AACnB,sBAAA;AAAA,MAAA;AAET,aAAA;AAAA,IAAA;AAEF,WAAA;AAAA,EAAA,CACR;AAED,MAAI,CAAC,aAAa;AACT,WAAA;AAAA,EAAA;AAEF,SAAA;AACT;AAEO,SAAS,qBACd,YACkB;AACX,SAAA,CAAC,GAAG,IAAI,IAAO,WAAW,KAAK,CAAC,CAAC,CAAC;AAC3C;"}
|
|
@@ -0,0 +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 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}\n"],"names":["createRoutePropertyOrder.name","createRoutePropertyOrder.rule"],"mappings":";AAIO,MAAM,QAQT;AAAA,EACF,CAACA,IAA6B,GAAGC;AACnC;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TSESTree, ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
+
type Create = Parameters<ReturnType<typeof ESLintUtils.RuleCreator>>[0]['create'];
|
|
3
|
+
type Context = Parameters<Create>[0];
|
|
4
|
+
type Options = Parameters<Create>[1];
|
|
5
|
+
type Helpers = {
|
|
6
|
+
isSpecificTanstackRouterImport: (node: TSESTree.Identifier, source: string) => boolean;
|
|
7
|
+
isTanstackRouterImport: (node: TSESTree.Identifier) => boolean;
|
|
8
|
+
};
|
|
9
|
+
type EnhancedCreate = (context: Context, options: Options, helpers: Helpers) => ReturnType<Create>;
|
|
10
|
+
export declare function detectTanstackRouterImports(create: EnhancedCreate): Create;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { TSESTree } from "@typescript-eslint/utils";
|
|
2
|
+
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 && node.importKind === "value" && node.source.value.startsWith("@tanstack/") && node.source.value.endsWith("-router")) {
|
|
26
|
+
tanstackRouterImportSpecifiers.push(...node.specifiers);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const ruleInstructions = create(context, optionsWithDefault, helpers);
|
|
31
|
+
const enhancedRuleInstructions = {};
|
|
32
|
+
const allKeys = new Set(
|
|
33
|
+
Object.keys(detectionInstructions).concat(Object.keys(ruleInstructions))
|
|
34
|
+
);
|
|
35
|
+
allKeys.forEach((instruction) => {
|
|
36
|
+
enhancedRuleInstructions[instruction] = (node) => {
|
|
37
|
+
var _a;
|
|
38
|
+
if (instruction in detectionInstructions) {
|
|
39
|
+
(_a = detectionInstructions[instruction]) == null ? void 0 : _a.call(detectionInstructions, 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
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
detectTanstackRouterImports
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=detect-router-imports.js.map
|
|
@@ -0,0 +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 node.importKind === 'value' &&\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;AACnE,SAAA,CAAC,SAAS,uBAAuB;AACtC,UAAM,iCAA+D,CAAC;AAEtE,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;AACO,mBAAA,KAAK,SAAS,UAAU,MAAM;AAAA,UAAA;AAGhC,iBAAA;AAAA,QAAA,CACR;AAAA,MACH;AAAA,MACA,uBAAuB,MAAM;AAC3B,eAAO,CAAC,CAAC,+BAA+B,KAAK,CAAC,cAAc;AAC1D,cAAI,UAAU,SAAS,SAAS,eAAe,iBAAiB;AACvD,mBAAA,KAAK,SAAS,UAAU,MAAM;AAAA,UAAA;AAGhC,iBAAA;AAAA,QAAA,CACR;AAAA,MAAA;AAAA,IAEL;AAEA,UAAM,wBAA+C;AAAA,MACnD,kBAAkB,MAAM;AACtB,YACE,KAAK,WAAW,SAAS,KACzB,KAAK,eAAe,WACpB,KAAK,OAAO,MAAM,WAAW,YAAY,KACzC,KAAK,OAAO,MAAM,SAAS,SAAS,GACpC;AAC+B,yCAAA,KAAK,GAAG,KAAK,UAAU;AAAA,QAAA;AAAA,MACxD;AAAA,IAEJ;AAGA,UAAM,mBAAmB,OAAO,SAAS,oBAAoB,OAAO;AACpE,UAAM,2BAAkD,CAAC;AAEzD,UAAM,UAAU,IAAI;AAAA,MAClB,OAAO,KAAK,qBAAqB,EAAE,OAAO,OAAO,KAAK,gBAAgB,CAAC;AAAA,IACzE;AAIQ,YAAA,QAAQ,CAAC,gBAAgB;AACN,+BAAA,WAAW,IAAI,CAAC,SAAS;;AAChD,YAAI,eAAe,uBAAuB;AAClB,sCAAA,iBAAA,+CAAe;AAAA,QAAI;AAGrC,cAAA,eAAe,iBAAiB,WAAW;AACjD,YAAI,iBAAiB,QAAW;AAC9B,iBAAO,aAAa,IAAI;AAAA,QAAA;AAGnB,eAAA;AAAA,MACT;AAAA,IAAA,CACD;AAEM,WAAA;AAAA,EACT;AACF;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getDocsUrl: (ruleName: string) => string;
|
|
@@ -0,0 +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;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tanstack/eslint-plugin-router",
|
|
3
|
+
"version": "1.20.3-alpha.1",
|
|
4
|
+
"description": "ESLint plugin for TanStack Router",
|
|
5
|
+
"author": "Manuel Schiller",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/TanStack/router.git",
|
|
10
|
+
"directory": "packages/eslint-plugin-router"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://tanstack.com/router",
|
|
13
|
+
"funding": {
|
|
14
|
+
"type": "github",
|
|
15
|
+
"url": "https://github.com/sponsors/tannerlinsley"
|
|
16
|
+
},
|
|
17
|
+
"type": "module",
|
|
18
|
+
"types": "dist/esm/index.d.ts",
|
|
19
|
+
"main": "dist/cjs/index.cjs",
|
|
20
|
+
"module": "dist/esm/index.js",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"import": {
|
|
24
|
+
"types": "./dist/esm/index.d.ts",
|
|
25
|
+
"default": "./dist/esm/index.js"
|
|
26
|
+
},
|
|
27
|
+
"require": {
|
|
28
|
+
"types": "./dist/cjs/index.d.cts",
|
|
29
|
+
"default": "./dist/cjs/index.cjs"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"./package.json": "./package.json"
|
|
33
|
+
},
|
|
34
|
+
"sideEffects": false,
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"src"
|
|
38
|
+
],
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@typescript-eslint/utils": "^8.23.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@typescript-eslint/rule-tester": "^8.23.0",
|
|
44
|
+
"combinate": "^1.1.11",
|
|
45
|
+
"eslint": "^9.22.0"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"eslint": "^8.57.0 || ^9.0.0"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {}
|
|
51
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { RuleTester } from '@typescript-eslint/rule-tester'
|
|
2
|
+
import combinate from 'combinate'
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
name,
|
|
6
|
+
rule,
|
|
7
|
+
} from '../rules/create-route-property-order/create-route-property-order.rule'
|
|
8
|
+
import {
|
|
9
|
+
checkedProperties,
|
|
10
|
+
createRouteFunctionsDirect,
|
|
11
|
+
createRouteFunctionsIndirect,
|
|
12
|
+
} from '../rules/create-route-property-order/constants'
|
|
13
|
+
import {
|
|
14
|
+
generateInterleavedCombinations,
|
|
15
|
+
generatePartialCombinations,
|
|
16
|
+
generatePermutations,
|
|
17
|
+
normalizeIndent,
|
|
18
|
+
} from './test-utils'
|
|
19
|
+
|
|
20
|
+
const ruleTester = new RuleTester()
|
|
21
|
+
|
|
22
|
+
// reduce the number of test cases by only testing a subset of the checked properties
|
|
23
|
+
const testedCheckedProperties = [
|
|
24
|
+
checkedProperties[0]!,
|
|
25
|
+
checkedProperties[1]!,
|
|
26
|
+
checkedProperties[2]!,
|
|
27
|
+
checkedProperties[3]!,
|
|
28
|
+
]
|
|
29
|
+
type TestedCheckedProperties = (typeof testedCheckedProperties)[number]
|
|
30
|
+
const orderIndependentProps = ['gcTime', '...foo'] as const
|
|
31
|
+
type OrderIndependentProps = (typeof orderIndependentProps)[number]
|
|
32
|
+
|
|
33
|
+
// reduce the number of test cases by only testing the first function of createRouteFunctionsDirect
|
|
34
|
+
const testedCreateRouteFunctions = [
|
|
35
|
+
...createRouteFunctionsIndirect,
|
|
36
|
+
createRouteFunctionsDirect[0],
|
|
37
|
+
]
|
|
38
|
+
type TestedCreateRouteFunction = (typeof testedCreateRouteFunctions)[number]
|
|
39
|
+
|
|
40
|
+
interface TestCase {
|
|
41
|
+
createRouteFunction: TestedCreateRouteFunction
|
|
42
|
+
properties: Array<TestedCheckedProperties | OrderIndependentProps>
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const validTestMatrix = combinate({
|
|
46
|
+
createRouteFunction: testedCreateRouteFunctions,
|
|
47
|
+
properties: generatePartialCombinations(testedCheckedProperties, 2),
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
export function generateInvalidPermutations(
|
|
51
|
+
arr: ReadonlyArray<TestedCheckedProperties>,
|
|
52
|
+
): Array<{
|
|
53
|
+
invalid: Array<TestedCheckedProperties>
|
|
54
|
+
valid: Array<TestedCheckedProperties>
|
|
55
|
+
}> {
|
|
56
|
+
const combinations = generatePartialCombinations(arr, 2)
|
|
57
|
+
const allPermutations: Array<{
|
|
58
|
+
invalid: Array<TestedCheckedProperties>
|
|
59
|
+
valid: Array<TestedCheckedProperties>
|
|
60
|
+
}> = []
|
|
61
|
+
|
|
62
|
+
for (const combination of combinations) {
|
|
63
|
+
const permutations = generatePermutations(combination)
|
|
64
|
+
// skip the first permutation as it matches the original combination
|
|
65
|
+
const invalidPermutations = permutations.slice(1)
|
|
66
|
+
|
|
67
|
+
if (
|
|
68
|
+
combination.includes('params') &&
|
|
69
|
+
combination.includes('validateSearch')
|
|
70
|
+
) {
|
|
71
|
+
if (
|
|
72
|
+
combination.indexOf('params') < combination.indexOf('validateSearch')
|
|
73
|
+
) {
|
|
74
|
+
// since we ignore the relative order of 'params' and 'validateSearch', we skip this combination (but keep the other one where `validateSearch` is before `params`)
|
|
75
|
+
continue
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
allPermutations.push(
|
|
80
|
+
...invalidPermutations.map((p) => {
|
|
81
|
+
// ignore the relative order of 'params' and 'validateSearch'
|
|
82
|
+
const correctedValid = [...combination].sort((a, b) => {
|
|
83
|
+
if (
|
|
84
|
+
(a === 'params' && b === 'validateSearch') ||
|
|
85
|
+
(a === 'validateSearch' && b === 'params')
|
|
86
|
+
) {
|
|
87
|
+
return p.indexOf(a) - p.indexOf(b)
|
|
88
|
+
}
|
|
89
|
+
return checkedProperties.indexOf(a) - checkedProperties.indexOf(b)
|
|
90
|
+
})
|
|
91
|
+
return { invalid: p, valid: correctedValid }
|
|
92
|
+
}),
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return allPermutations
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const invalidPermutations = generateInvalidPermutations(testedCheckedProperties)
|
|
100
|
+
|
|
101
|
+
type Interleaved = TestedCheckedProperties | OrderIndependentProps
|
|
102
|
+
const interleavedInvalidPermutations: Array<{
|
|
103
|
+
invalid: Array<Interleaved>
|
|
104
|
+
valid: Array<Interleaved>
|
|
105
|
+
}> = []
|
|
106
|
+
for (const invalidPermutation of invalidPermutations) {
|
|
107
|
+
const invalid = generateInterleavedCombinations(
|
|
108
|
+
invalidPermutation.invalid,
|
|
109
|
+
orderIndependentProps,
|
|
110
|
+
)
|
|
111
|
+
const valid = generateInterleavedCombinations(
|
|
112
|
+
invalidPermutation.valid,
|
|
113
|
+
orderIndependentProps,
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
for (let i = 0; i < invalid.length; i++) {
|
|
117
|
+
interleavedInvalidPermutations.push({
|
|
118
|
+
invalid: invalid[i]!,
|
|
119
|
+
valid: valid[i]!,
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const invalidTestMatrix = combinate({
|
|
125
|
+
createRouteFunction: testedCreateRouteFunctions,
|
|
126
|
+
properties: interleavedInvalidPermutations,
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
function getCode({ createRouteFunction, properties }: TestCase) {
|
|
130
|
+
let invocation = ''
|
|
131
|
+
switch (createRouteFunction) {
|
|
132
|
+
case 'createFileRoute': {
|
|
133
|
+
invocation = `('/_layout/hello/foo/$id')`
|
|
134
|
+
break
|
|
135
|
+
}
|
|
136
|
+
case 'createRootRouteWithContext': {
|
|
137
|
+
invocation = normalizeIndent`
|
|
138
|
+
<{
|
|
139
|
+
queryClient: QueryClient
|
|
140
|
+
}>()`
|
|
141
|
+
break
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function getPropertyCode(
|
|
145
|
+
property: TestedCheckedProperties | OrderIndependentProps,
|
|
146
|
+
) {
|
|
147
|
+
if (property.startsWith('...')) {
|
|
148
|
+
return property
|
|
149
|
+
}
|
|
150
|
+
return `${property}: () => null`
|
|
151
|
+
}
|
|
152
|
+
return `
|
|
153
|
+
import { ${createRouteFunction} } from '@tanstack/react-router'
|
|
154
|
+
|
|
155
|
+
const Route = ${createRouteFunction}${invocation}({
|
|
156
|
+
${properties.map(getPropertyCode).join(',\n ')}
|
|
157
|
+
})
|
|
158
|
+
`
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const validTestCases = validTestMatrix.map(
|
|
162
|
+
({ createRouteFunction, properties }) => ({
|
|
163
|
+
name: `should pass when order is correct for ${createRouteFunction} with order: ${properties.join(', ')}`,
|
|
164
|
+
code: getCode({ createRouteFunction, properties }),
|
|
165
|
+
}),
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
invalidTestMatrix.push({
|
|
169
|
+
createRouteFunction: 'createFileRoute',
|
|
170
|
+
properties: {
|
|
171
|
+
invalid: ['loader', 'loaderDeps'],
|
|
172
|
+
valid: ['loaderDeps', 'loader'],
|
|
173
|
+
},
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
invalidTestMatrix.push({
|
|
177
|
+
createRouteFunction: 'createFileRoute',
|
|
178
|
+
properties: { invalid: ['head', 'loader'], valid: ['loader', 'head'] },
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
const invalidTestCases = invalidTestMatrix.map(
|
|
182
|
+
({ createRouteFunction, properties }) => ({
|
|
183
|
+
name: `incorrect property order is detected for ${createRouteFunction} with order: ${properties.invalid.join(', ')}`,
|
|
184
|
+
code: getCode({
|
|
185
|
+
createRouteFunction,
|
|
186
|
+
properties: properties.invalid,
|
|
187
|
+
}),
|
|
188
|
+
errors: [{ messageId: 'invalidOrder' }],
|
|
189
|
+
output: getCode({
|
|
190
|
+
createRouteFunction,
|
|
191
|
+
properties: properties.valid,
|
|
192
|
+
}),
|
|
193
|
+
}),
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
ruleTester.run(name, rule, {
|
|
197
|
+
valid: validTestCases,
|
|
198
|
+
invalid: invalidTestCases,
|
|
199
|
+
})
|