@antebudimir/eslint-plugin-vanilla-extract 1.9.0 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +160 -32
- package/dist/css-rules/no-empty-blocks/empty-style-visitor-creator.d.ts +2 -3
- package/dist/css-rules/no-empty-blocks/empty-style-visitor-creator.js +101 -68
- package/dist/css-rules/no-unknown-unit/unknown-unit-visitor-creator.d.ts +2 -1
- package/dist/css-rules/no-unknown-unit/unknown-unit-visitor-creator.js +43 -18
- package/dist/css-rules/no-zero-unit/zero-unit-visitor-creator.d.ts +1 -6
- package/dist/css-rules/no-zero-unit/zero-unit-visitor-creator.js +42 -23
- package/dist/css-rules/shared-utils/order-strategy-visitor-creator.d.ts +3 -9
- package/dist/css-rules/shared-utils/order-strategy-visitor-creator.js +88 -63
- package/dist/css-rules/shared-utils/reference-based-visitor-creator.d.ts +19 -0
- package/dist/css-rules/shared-utils/reference-based-visitor-creator.js +108 -0
- package/dist/css-rules/shared-utils/reference-tracker.d.ts +85 -0
- package/dist/css-rules/shared-utils/reference-tracker.js +260 -0
- package/dist/index.d.ts +2 -12
- package/dist/index.js +15 -12
- package/package.json +2 -2
|
@@ -1,37 +1,62 @@
|
|
|
1
1
|
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';
|
|
2
2
|
import { processRecipeProperties } from '../shared-utils/recipe-property-processor.js';
|
|
3
|
+
import { ReferenceTracker, createReferenceTrackingVisitor } from '../shared-utils/reference-tracker.js';
|
|
3
4
|
import { processStyleNode } from '../shared-utils/style-node-processor.js';
|
|
4
5
|
import { processUnknownUnitInStyleObject } from './unknown-unit-processor.js';
|
|
5
6
|
/**
|
|
6
7
|
* Creates ESLint rule visitors for detecting and processing unknown CSS units
|
|
7
|
-
* in style-related function calls.
|
|
8
|
+
* in style-related function calls using reference tracking.
|
|
9
|
+
* This automatically detects vanilla-extract functions based on their import statements.
|
|
8
10
|
*/
|
|
9
11
|
export const createUnknownUnitVisitors = (context) => {
|
|
12
|
+
const tracker = new ReferenceTracker();
|
|
13
|
+
const trackingVisitor = createReferenceTrackingVisitor(tracker);
|
|
10
14
|
return {
|
|
15
|
+
// Include the import/variable tracking visitors
|
|
16
|
+
...trackingVisitor,
|
|
11
17
|
CallExpression(node) {
|
|
12
18
|
if (node.callee.type !== AST_NODE_TYPES.Identifier) {
|
|
13
19
|
return;
|
|
14
20
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
node.arguments[argumentIndex]?.type === AST_NODE_TYPES.ObjectExpression) {
|
|
19
|
-
processUnknownUnitInStyleObject(context, node.arguments[argumentIndex]);
|
|
20
|
-
}
|
|
21
|
+
const functionName = node.callee.name;
|
|
22
|
+
// Check if this function is tracked as a vanilla-extract function
|
|
23
|
+
if (!tracker.isTrackedFunction(functionName)) {
|
|
21
24
|
return;
|
|
22
25
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
if (['globalKeyframes', 'globalStyle'].includes(node.callee.name) && node.arguments.length >= 2) {
|
|
29
|
-
processStyleNode(context, node.arguments[1], processUnknownUnitInStyleObject);
|
|
26
|
+
const originalName = tracker.getOriginalName(functionName);
|
|
27
|
+
if (!originalName) {
|
|
28
|
+
return;
|
|
30
29
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
// Handle different function types based on their original imported name
|
|
31
|
+
switch (originalName) {
|
|
32
|
+
case 'fontFace':
|
|
33
|
+
if (node.arguments.length > 0 && node.arguments[0]?.type === AST_NODE_TYPES.ObjectExpression) {
|
|
34
|
+
processUnknownUnitInStyleObject(context, node.arguments[0]);
|
|
35
|
+
}
|
|
36
|
+
break;
|
|
37
|
+
case 'globalFontFace':
|
|
38
|
+
if (node.arguments.length > 1 && node.arguments[1]?.type === AST_NODE_TYPES.ObjectExpression) {
|
|
39
|
+
processUnknownUnitInStyleObject(context, node.arguments[1]);
|
|
40
|
+
}
|
|
41
|
+
break;
|
|
42
|
+
case 'style':
|
|
43
|
+
case 'styleVariants':
|
|
44
|
+
case 'keyframes':
|
|
45
|
+
if (node.arguments.length > 0) {
|
|
46
|
+
processStyleNode(context, node.arguments[0], processUnknownUnitInStyleObject);
|
|
47
|
+
}
|
|
48
|
+
break;
|
|
49
|
+
case 'globalStyle':
|
|
50
|
+
case 'globalKeyframes':
|
|
51
|
+
if (node.arguments.length >= 2) {
|
|
52
|
+
processStyleNode(context, node.arguments[1], processUnknownUnitInStyleObject);
|
|
53
|
+
}
|
|
54
|
+
break;
|
|
55
|
+
case 'recipe':
|
|
56
|
+
if (node.arguments.length > 0 && node.arguments[0]?.type === AST_NODE_TYPES.ObjectExpression) {
|
|
57
|
+
processRecipeProperties(context, node.arguments[0], processUnknownUnitInStyleObject);
|
|
58
|
+
}
|
|
59
|
+
break;
|
|
35
60
|
}
|
|
36
61
|
},
|
|
37
62
|
};
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import type { Rule } from 'eslint';
|
|
2
2
|
/**
|
|
3
3
|
* Creates ESLint rule visitors for detecting and processing zero values with units in style-related function calls.
|
|
4
|
+
* Uses reference tracking to automatically detect vanilla-extract functions based on their import statements.
|
|
4
5
|
*
|
|
5
6
|
* @param context The ESLint rule context.
|
|
6
7
|
* @returns An object with visitor functions for the ESLint rule.
|
|
7
|
-
*
|
|
8
|
-
* This function sets up visitors for the following cases:
|
|
9
|
-
* 1. The `fontFace` and `globalFontFace` functions, processing their object arguments.
|
|
10
|
-
* 2. Style-related functions: `keyframes`, `style`, `styleVariants`, processing their style objects.
|
|
11
|
-
* 3. The `globalKeyframes` and `globalStyle` functions, processing the second argument as style objects.
|
|
12
|
-
* 4. The `recipe` function, processing the first argument as the recipe object.
|
|
13
8
|
*/
|
|
14
9
|
export declare const createZeroUnitVisitors: (context: Rule.RuleContext) => Rule.RuleListener;
|
|
@@ -1,45 +1,64 @@
|
|
|
1
1
|
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';
|
|
2
2
|
import { processRecipeProperties } from '../shared-utils/recipe-property-processor.js';
|
|
3
|
+
import { ReferenceTracker, createReferenceTrackingVisitor } from '../shared-utils/reference-tracker.js';
|
|
3
4
|
import { processStyleNode } from '../shared-utils/style-node-processor.js';
|
|
4
5
|
import { processZeroUnitInStyleObject } from './zero-unit-processor.js';
|
|
5
6
|
/**
|
|
6
7
|
* Creates ESLint rule visitors for detecting and processing zero values with units in style-related function calls.
|
|
8
|
+
* Uses reference tracking to automatically detect vanilla-extract functions based on their import statements.
|
|
7
9
|
*
|
|
8
10
|
* @param context The ESLint rule context.
|
|
9
11
|
* @returns An object with visitor functions for the ESLint rule.
|
|
10
|
-
*
|
|
11
|
-
* This function sets up visitors for the following cases:
|
|
12
|
-
* 1. The `fontFace` and `globalFontFace` functions, processing their object arguments.
|
|
13
|
-
* 2. Style-related functions: `keyframes`, `style`, `styleVariants`, processing their style objects.
|
|
14
|
-
* 3. The `globalKeyframes` and `globalStyle` functions, processing the second argument as style objects.
|
|
15
|
-
* 4. The `recipe` function, processing the first argument as the recipe object.
|
|
16
12
|
*/
|
|
17
13
|
export const createZeroUnitVisitors = (context) => {
|
|
14
|
+
const tracker = new ReferenceTracker();
|
|
15
|
+
const trackingVisitor = createReferenceTrackingVisitor(tracker);
|
|
18
16
|
return {
|
|
17
|
+
// Include the reference tracking visitors
|
|
18
|
+
...trackingVisitor,
|
|
19
19
|
CallExpression(node) {
|
|
20
20
|
if (node.callee.type !== AST_NODE_TYPES.Identifier) {
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
node.arguments[argumentIndex]?.type === AST_NODE_TYPES.ObjectExpression) {
|
|
27
|
-
processZeroUnitInStyleObject(context, node.arguments[argumentIndex]);
|
|
28
|
-
}
|
|
23
|
+
const functionName = node.callee.name;
|
|
24
|
+
// Check if this function is tracked as a vanilla-extract function
|
|
25
|
+
if (!tracker.isTrackedFunction(functionName)) {
|
|
29
26
|
return;
|
|
30
27
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
if (['globalKeyframes', 'globalStyle'].includes(node.callee.name) && node.arguments.length >= 2) {
|
|
37
|
-
processStyleNode(context, node.arguments[1], processZeroUnitInStyleObject);
|
|
28
|
+
const originalName = tracker.getOriginalName(functionName);
|
|
29
|
+
if (!originalName) {
|
|
30
|
+
return;
|
|
38
31
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
32
|
+
// Handle different function types based on their original imported name
|
|
33
|
+
switch (originalName) {
|
|
34
|
+
case 'fontFace':
|
|
35
|
+
if (node.arguments.length > 0 && node.arguments[0]?.type === AST_NODE_TYPES.ObjectExpression) {
|
|
36
|
+
processZeroUnitInStyleObject(context, node.arguments[0]);
|
|
37
|
+
}
|
|
38
|
+
break;
|
|
39
|
+
case 'globalFontFace':
|
|
40
|
+
if (node.arguments.length > 1 && node.arguments[1]?.type === AST_NODE_TYPES.ObjectExpression) {
|
|
41
|
+
processZeroUnitInStyleObject(context, node.arguments[1]);
|
|
42
|
+
}
|
|
43
|
+
break;
|
|
44
|
+
case 'style':
|
|
45
|
+
case 'styleVariants':
|
|
46
|
+
case 'keyframes':
|
|
47
|
+
if (node.arguments.length > 0) {
|
|
48
|
+
processStyleNode(context, node.arguments[0], processZeroUnitInStyleObject);
|
|
49
|
+
}
|
|
50
|
+
break;
|
|
51
|
+
case 'globalStyle':
|
|
52
|
+
case 'globalKeyframes':
|
|
53
|
+
if (node.arguments.length >= 2) {
|
|
54
|
+
processStyleNode(context, node.arguments[1], processZeroUnitInStyleObject);
|
|
55
|
+
}
|
|
56
|
+
break;
|
|
57
|
+
case 'recipe':
|
|
58
|
+
if (node.arguments.length > 0 && node.arguments[0]?.type === AST_NODE_TYPES.ObjectExpression) {
|
|
59
|
+
processRecipeProperties(context, node.arguments[0], processZeroUnitInStyleObject);
|
|
60
|
+
}
|
|
61
|
+
break;
|
|
43
62
|
}
|
|
44
63
|
},
|
|
45
64
|
};
|
|
@@ -2,19 +2,13 @@ import type { Rule } from 'eslint';
|
|
|
2
2
|
import type { SortRemainingProperties } from '../concentric-order/types.js';
|
|
3
3
|
import type { OrderingStrategy } from '../types.js';
|
|
4
4
|
/**
|
|
5
|
-
* Creates an ESLint rule listener with visitors for style-related function calls.
|
|
5
|
+
* Creates an ESLint rule listener with visitors for style-related function calls using reference tracking.
|
|
6
|
+
* This automatically detects vanilla-extract functions based on their import statements.
|
|
7
|
+
*
|
|
6
8
|
* @param ruleContext The ESLint rule context.
|
|
7
9
|
* @param orderingStrategy The strategy to use for ordering CSS properties ('alphabetical', 'concentric', or 'userDefinedGroupOrder').
|
|
8
10
|
* @param userDefinedGroupOrder An optional array of property groups for the 'userDefinedGroupOrder' strategy.
|
|
9
11
|
* @param sortRemainingProperties An optional strategy for sorting properties not in user-defined groups.
|
|
10
12
|
* @returns An object with visitor functions for the ESLint rule.
|
|
11
|
-
*
|
|
12
|
-
* This function sets up visitors for the following cases:
|
|
13
|
-
* 1. The fontFace and globalFontFace functions.
|
|
14
|
-
* 2. Style-related functions: 'keyframes', 'style', 'styleVariants'.
|
|
15
|
-
* 3. The 'globalStyle' and 'globalKeyframes' function
|
|
16
|
-
* 4. The 'recipe' function
|
|
17
|
-
*
|
|
18
|
-
* Each visitor applies the appropriate ordering strategy to the style objects in these function calls.
|
|
19
13
|
*/
|
|
20
14
|
export declare const createNodeVisitors: (ruleContext: Rule.RuleContext, orderingStrategy: OrderingStrategy, userDefinedGroupOrder?: string[], sortRemainingProperties?: SortRemainingProperties) => Rule.RuleListener;
|
|
@@ -6,87 +6,112 @@ import { enforceConcentricCSSOrderInStyleObject } from '../concentric-order/styl
|
|
|
6
6
|
import { enforceUserDefinedGroupOrderInRecipe } from '../custom-order/recipe-order-enforcer.js';
|
|
7
7
|
import { enforceUserDefinedGroupOrderInStyleObject } from '../custom-order/style-object-processor.js';
|
|
8
8
|
import { enforceFontFaceOrder } from './font-face-property-order-enforcer.js';
|
|
9
|
+
import { ReferenceTracker, createReferenceTrackingVisitor } from './reference-tracker.js';
|
|
9
10
|
import { processStyleNode } from './style-node-processor.js';
|
|
10
11
|
/**
|
|
11
|
-
* Creates an ESLint rule listener with visitors for style-related function calls.
|
|
12
|
+
* Creates an ESLint rule listener with visitors for style-related function calls using reference tracking.
|
|
13
|
+
* This automatically detects vanilla-extract functions based on their import statements.
|
|
14
|
+
*
|
|
12
15
|
* @param ruleContext The ESLint rule context.
|
|
13
16
|
* @param orderingStrategy The strategy to use for ordering CSS properties ('alphabetical', 'concentric', or 'userDefinedGroupOrder').
|
|
14
17
|
* @param userDefinedGroupOrder An optional array of property groups for the 'userDefinedGroupOrder' strategy.
|
|
15
18
|
* @param sortRemainingProperties An optional strategy for sorting properties not in user-defined groups.
|
|
16
19
|
* @returns An object with visitor functions for the ESLint rule.
|
|
17
|
-
*
|
|
18
|
-
* This function sets up visitors for the following cases:
|
|
19
|
-
* 1. The fontFace and globalFontFace functions.
|
|
20
|
-
* 2. Style-related functions: 'keyframes', 'style', 'styleVariants'.
|
|
21
|
-
* 3. The 'globalStyle' and 'globalKeyframes' function
|
|
22
|
-
* 4. The 'recipe' function
|
|
23
|
-
*
|
|
24
|
-
* Each visitor applies the appropriate ordering strategy to the style objects in these function calls.
|
|
25
20
|
*/
|
|
26
21
|
export const createNodeVisitors = (ruleContext, orderingStrategy, userDefinedGroupOrder, sortRemainingProperties) => {
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
switch (orderingStrategy) {
|
|
30
|
-
case 'alphabetical':
|
|
31
|
-
return enforceAlphabeticalCSSOrderInStyleObject;
|
|
32
|
-
case 'concentric':
|
|
33
|
-
return enforceConcentricCSSOrderInStyleObject;
|
|
34
|
-
case 'userDefinedGroupOrder':
|
|
35
|
-
if (!userDefinedGroupOrder || userDefinedGroupOrder.length === 0) {
|
|
36
|
-
return enforceAlphabeticalCSSOrderInStyleObject;
|
|
37
|
-
}
|
|
38
|
-
return (ruleContext, node) => enforceUserDefinedGroupOrderInStyleObject(ruleContext, node, userDefinedGroupOrder, sortRemainingProperties);
|
|
39
|
-
default:
|
|
40
|
-
return enforceAlphabeticalCSSOrderInStyleObject;
|
|
41
|
-
}
|
|
42
|
-
})();
|
|
22
|
+
const tracker = new ReferenceTracker();
|
|
23
|
+
const trackingVisitor = createReferenceTrackingVisitor(tracker);
|
|
43
24
|
return {
|
|
25
|
+
// Include the import/variable tracking visitors
|
|
26
|
+
...trackingVisitor,
|
|
44
27
|
CallExpression(node) {
|
|
45
28
|
if (node.callee.type !== 'Identifier') {
|
|
46
29
|
return;
|
|
47
30
|
}
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
};
|
|
52
|
-
// Handle font face functions with special ordering
|
|
53
|
-
if (node.callee.name in fontFaceFunctionArgumentIndexMap &&
|
|
54
|
-
node.arguments.length >
|
|
55
|
-
fontFaceFunctionArgumentIndexMap[node.callee.name]) {
|
|
56
|
-
const argumentIndex = fontFaceFunctionArgumentIndexMap[node.callee.name];
|
|
57
|
-
const styleArguments = node.arguments[argumentIndex];
|
|
58
|
-
enforceFontFaceOrder(ruleContext, styleArguments);
|
|
31
|
+
const functionName = node.callee.name;
|
|
32
|
+
// Check if this function is tracked as a vanilla-extract function
|
|
33
|
+
if (!tracker.isTrackedFunction(functionName)) {
|
|
59
34
|
return;
|
|
60
35
|
}
|
|
61
|
-
|
|
62
|
-
if (
|
|
63
|
-
|
|
64
|
-
const styleArguments = node.arguments[0];
|
|
65
|
-
processStyleNode(ruleContext, styleArguments, processProperty);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
// Handle global functions
|
|
69
|
-
if ((node.callee.name === 'globalKeyframes' || node.callee.name === 'globalStyle') &&
|
|
70
|
-
node.arguments.length >= 2) {
|
|
71
|
-
const styleArguments = node.arguments[1];
|
|
72
|
-
processStyleNode(ruleContext, styleArguments, processProperty);
|
|
36
|
+
const originalName = tracker.getOriginalName(functionName);
|
|
37
|
+
if (!originalName) {
|
|
38
|
+
return;
|
|
73
39
|
}
|
|
74
|
-
// Handle
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
40
|
+
// Handle different function types based on their original imported name
|
|
41
|
+
switch (originalName) {
|
|
42
|
+
case 'fontFace':
|
|
43
|
+
processFontFaceOrdering(ruleContext, node, 0);
|
|
44
|
+
break;
|
|
45
|
+
case 'globalFontFace':
|
|
46
|
+
processFontFaceOrdering(ruleContext, node, 1);
|
|
47
|
+
break;
|
|
48
|
+
case 'style':
|
|
49
|
+
case 'styleVariants':
|
|
50
|
+
case 'keyframes':
|
|
51
|
+
// Check if this is a wrapper function
|
|
52
|
+
const wrapperInfo = tracker.getWrapperInfo(functionName);
|
|
53
|
+
const argumentIndex = wrapperInfo?.parameterMapping ?? 0;
|
|
54
|
+
processStyleOrdering(ruleContext, node, orderingStrategy, userDefinedGroupOrder, sortRemainingProperties, argumentIndex);
|
|
55
|
+
break;
|
|
56
|
+
case 'globalStyle':
|
|
57
|
+
case 'globalKeyframes':
|
|
58
|
+
processStyleOrdering(ruleContext, node, orderingStrategy, userDefinedGroupOrder, sortRemainingProperties, 1);
|
|
59
|
+
break;
|
|
60
|
+
case 'recipe':
|
|
61
|
+
processRecipeOrdering(ruleContext, node, orderingStrategy, userDefinedGroupOrder, sortRemainingProperties);
|
|
62
|
+
break;
|
|
89
63
|
}
|
|
90
64
|
},
|
|
91
65
|
};
|
|
92
66
|
};
|
|
67
|
+
/**
|
|
68
|
+
* Helper function to process style ordering for style-related functions
|
|
69
|
+
*/
|
|
70
|
+
const processStyleOrdering = (ruleContext, node, orderingStrategy, userDefinedGroupOrder, sortRemainingProperties, argumentIndex = 0) => {
|
|
71
|
+
if (node.arguments.length > argumentIndex) {
|
|
72
|
+
const processProperty = (() => {
|
|
73
|
+
switch (orderingStrategy) {
|
|
74
|
+
case 'alphabetical':
|
|
75
|
+
return enforceAlphabeticalCSSOrderInStyleObject;
|
|
76
|
+
case 'concentric':
|
|
77
|
+
return enforceConcentricCSSOrderInStyleObject;
|
|
78
|
+
case 'userDefinedGroupOrder':
|
|
79
|
+
if (!userDefinedGroupOrder || userDefinedGroupOrder.length === 0) {
|
|
80
|
+
return enforceAlphabeticalCSSOrderInStyleObject;
|
|
81
|
+
}
|
|
82
|
+
return (ruleContext, node) => enforceUserDefinedGroupOrderInStyleObject(ruleContext, node, userDefinedGroupOrder, sortRemainingProperties);
|
|
83
|
+
default:
|
|
84
|
+
return enforceAlphabeticalCSSOrderInStyleObject;
|
|
85
|
+
}
|
|
86
|
+
})();
|
|
87
|
+
processStyleNode(ruleContext, node.arguments[argumentIndex], processProperty);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Helper function to process font face ordering
|
|
92
|
+
*/
|
|
93
|
+
const processFontFaceOrdering = (ruleContext, node, argumentIndex) => {
|
|
94
|
+
if (node.arguments.length > argumentIndex) {
|
|
95
|
+
enforceFontFaceOrder(ruleContext, node.arguments[argumentIndex]);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Helper function to process recipe ordering
|
|
100
|
+
*/
|
|
101
|
+
const processRecipeOrdering = (ruleContext, node, orderingStrategy, userDefinedGroupOrder, sortRemainingProperties) => {
|
|
102
|
+
if (node.arguments.length > 0) {
|
|
103
|
+
switch (orderingStrategy) {
|
|
104
|
+
case 'alphabetical':
|
|
105
|
+
enforceAlphabeticalCSSOrderInRecipe(node, ruleContext);
|
|
106
|
+
break;
|
|
107
|
+
case 'concentric':
|
|
108
|
+
enforceConcentricCSSOrderInRecipe(ruleContext, node);
|
|
109
|
+
break;
|
|
110
|
+
case 'userDefinedGroupOrder':
|
|
111
|
+
if (userDefinedGroupOrder) {
|
|
112
|
+
enforceUserDefinedGroupOrderInRecipe(ruleContext, node, userDefinedGroupOrder, sortRemainingProperties);
|
|
113
|
+
}
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
import type { SortRemainingProperties } from '../concentric-order/types.js';
|
|
3
|
+
import type { OrderingStrategy } from '../types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Creates an ESLint rule listener with visitors for style-related function calls using reference tracking.
|
|
6
|
+
* This automatically detects vanilla-extract functions based on their import statements.
|
|
7
|
+
*
|
|
8
|
+
* @param ruleContext The ESLint rule context.
|
|
9
|
+
* @param orderingStrategy The strategy to use for ordering CSS properties.
|
|
10
|
+
* @param userDefinedGroupOrder An optional array of property groups for the 'userDefinedGroupOrder' strategy.
|
|
11
|
+
* @param sortRemainingProperties An optional strategy for sorting properties not in user-defined groups.
|
|
12
|
+
* @returns An object with visitor functions for the ESLint rule.
|
|
13
|
+
*/
|
|
14
|
+
export declare const createReferenceBasedNodeVisitors: (ruleContext: Rule.RuleContext, orderingStrategy: OrderingStrategy, userDefinedGroupOrder?: string[], sortRemainingProperties?: SortRemainingProperties) => Rule.RuleListener;
|
|
15
|
+
/**
|
|
16
|
+
* Backwards-compatible alias that maintains the original API.
|
|
17
|
+
* Uses reference tracking internally for automatic detection of vanilla-extract functions.
|
|
18
|
+
*/
|
|
19
|
+
export declare const createNodeVisitors: (ruleContext: Rule.RuleContext, orderingStrategy: OrderingStrategy, userDefinedGroupOrder?: string[], sortRemainingProperties?: SortRemainingProperties) => Rule.RuleListener;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
import { enforceAlphabeticalCSSOrderInRecipe } from '../alphabetical-order/recipe-order-enforcer.js';
|
|
3
|
+
import { enforceAlphabeticalCSSOrderInStyleObject } from '../alphabetical-order/style-object-processor.js';
|
|
4
|
+
import { enforceConcentricCSSOrderInRecipe } from '../concentric-order/recipe-order-enforcer.js';
|
|
5
|
+
import { enforceConcentricCSSOrderInStyleObject } from '../concentric-order/style-object-processor.js';
|
|
6
|
+
import { enforceUserDefinedGroupOrderInRecipe } from '../custom-order/recipe-order-enforcer.js';
|
|
7
|
+
import { enforceUserDefinedGroupOrderInStyleObject } from '../custom-order/style-object-processor.js';
|
|
8
|
+
import { enforceFontFaceOrder } from './font-face-property-order-enforcer.js';
|
|
9
|
+
import { ReferenceTracker, createReferenceTrackingVisitor } from './reference-tracker.js';
|
|
10
|
+
import { processStyleNode } from './style-node-processor.js';
|
|
11
|
+
/**
|
|
12
|
+
* Creates an ESLint rule listener with visitors for style-related function calls using reference tracking.
|
|
13
|
+
* This automatically detects vanilla-extract functions based on their import statements.
|
|
14
|
+
*
|
|
15
|
+
* @param ruleContext The ESLint rule context.
|
|
16
|
+
* @param orderingStrategy The strategy to use for ordering CSS properties.
|
|
17
|
+
* @param userDefinedGroupOrder An optional array of property groups for the 'userDefinedGroupOrder' strategy.
|
|
18
|
+
* @param sortRemainingProperties An optional strategy for sorting properties not in user-defined groups.
|
|
19
|
+
* @returns An object with visitor functions for the ESLint rule.
|
|
20
|
+
*/
|
|
21
|
+
export const createReferenceBasedNodeVisitors = (ruleContext, orderingStrategy, userDefinedGroupOrder, sortRemainingProperties) => {
|
|
22
|
+
const tracker = new ReferenceTracker();
|
|
23
|
+
const trackingVisitor = createReferenceTrackingVisitor(tracker);
|
|
24
|
+
// Select the appropriate property processing function based on the ordering strategy
|
|
25
|
+
const processProperty = (() => {
|
|
26
|
+
switch (orderingStrategy) {
|
|
27
|
+
case 'alphabetical':
|
|
28
|
+
return enforceAlphabeticalCSSOrderInStyleObject;
|
|
29
|
+
case 'concentric':
|
|
30
|
+
return enforceConcentricCSSOrderInStyleObject;
|
|
31
|
+
case 'userDefinedGroupOrder':
|
|
32
|
+
if (!userDefinedGroupOrder || userDefinedGroupOrder.length === 0) {
|
|
33
|
+
return enforceAlphabeticalCSSOrderInStyleObject;
|
|
34
|
+
}
|
|
35
|
+
return (ruleContext, node) => enforceUserDefinedGroupOrderInStyleObject(ruleContext, node, userDefinedGroupOrder, sortRemainingProperties);
|
|
36
|
+
default:
|
|
37
|
+
return enforceAlphabeticalCSSOrderInStyleObject;
|
|
38
|
+
}
|
|
39
|
+
})();
|
|
40
|
+
return {
|
|
41
|
+
// Include the reference tracking visitors
|
|
42
|
+
...trackingVisitor,
|
|
43
|
+
CallExpression(callExpression) {
|
|
44
|
+
if (callExpression.callee.type !== 'Identifier') {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const functionName = callExpression.callee.name;
|
|
48
|
+
// Check if this function is tracked as a vanilla-extract function
|
|
49
|
+
if (!tracker.isTrackedFunction(functionName)) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const originalName = tracker.getOriginalName(functionName);
|
|
53
|
+
if (!originalName) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
// Handle different function types based on their original imported name
|
|
57
|
+
switch (originalName) {
|
|
58
|
+
case 'fontFace':
|
|
59
|
+
if (callExpression.arguments.length > 0) {
|
|
60
|
+
const styleArguments = callExpression.arguments[0];
|
|
61
|
+
enforceFontFaceOrder(ruleContext, styleArguments);
|
|
62
|
+
}
|
|
63
|
+
break;
|
|
64
|
+
case 'globalFontFace':
|
|
65
|
+
if (callExpression.arguments.length > 1) {
|
|
66
|
+
const styleArguments = callExpression.arguments[1];
|
|
67
|
+
enforceFontFaceOrder(ruleContext, styleArguments);
|
|
68
|
+
}
|
|
69
|
+
break;
|
|
70
|
+
case 'style':
|
|
71
|
+
case 'styleVariants':
|
|
72
|
+
case 'keyframes':
|
|
73
|
+
if (callExpression.arguments.length > 0) {
|
|
74
|
+
const styleArguments = callExpression.arguments[0];
|
|
75
|
+
processStyleNode(ruleContext, styleArguments, processProperty);
|
|
76
|
+
}
|
|
77
|
+
break;
|
|
78
|
+
case 'globalStyle':
|
|
79
|
+
case 'globalKeyframes':
|
|
80
|
+
if (callExpression.arguments.length > 1) {
|
|
81
|
+
const styleArguments = callExpression.arguments[1];
|
|
82
|
+
processStyleNode(ruleContext, styleArguments, processProperty);
|
|
83
|
+
}
|
|
84
|
+
break;
|
|
85
|
+
case 'recipe':
|
|
86
|
+
switch (orderingStrategy) {
|
|
87
|
+
case 'alphabetical':
|
|
88
|
+
enforceAlphabeticalCSSOrderInRecipe(callExpression, ruleContext);
|
|
89
|
+
break;
|
|
90
|
+
case 'concentric':
|
|
91
|
+
enforceConcentricCSSOrderInRecipe(ruleContext, callExpression);
|
|
92
|
+
break;
|
|
93
|
+
case 'userDefinedGroupOrder':
|
|
94
|
+
if (userDefinedGroupOrder) {
|
|
95
|
+
enforceUserDefinedGroupOrderInRecipe(ruleContext, callExpression, userDefinedGroupOrder, sortRemainingProperties);
|
|
96
|
+
}
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Backwards-compatible alias that maintains the original API.
|
|
106
|
+
* Uses reference tracking internally for automatic detection of vanilla-extract functions.
|
|
107
|
+
*/
|
|
108
|
+
export const createNodeVisitors = createReferenceBasedNodeVisitors;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
import { TSESTree } from '@typescript-eslint/utils';
|
|
3
|
+
export interface ImportReference {
|
|
4
|
+
source: string;
|
|
5
|
+
importedName: string;
|
|
6
|
+
localName: string;
|
|
7
|
+
}
|
|
8
|
+
export interface WrapperFunctionInfo {
|
|
9
|
+
originalFunction: string;
|
|
10
|
+
parameterMapping: number;
|
|
11
|
+
}
|
|
12
|
+
export interface TrackedFunctions {
|
|
13
|
+
styleFunctions: Set<string>;
|
|
14
|
+
recipeFunctions: Set<string>;
|
|
15
|
+
fontFaceFunctions: Set<string>;
|
|
16
|
+
globalFunctions: Set<string>;
|
|
17
|
+
keyframeFunctions: Set<string>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Tracks vanilla-extract function imports and their local bindings
|
|
21
|
+
*/
|
|
22
|
+
export declare class ReferenceTracker {
|
|
23
|
+
private imports;
|
|
24
|
+
private trackedFunctions;
|
|
25
|
+
private wrapperFunctions;
|
|
26
|
+
constructor();
|
|
27
|
+
/**
|
|
28
|
+
* Processes import declarations to track vanilla-extract functions
|
|
29
|
+
*/
|
|
30
|
+
processImportDeclaration(node: TSESTree.ImportDeclaration): void;
|
|
31
|
+
/**
|
|
32
|
+
* Processes variable declarations to track re-assignments and destructuring
|
|
33
|
+
*/
|
|
34
|
+
processVariableDeclarator(node: TSESTree.VariableDeclarator): void;
|
|
35
|
+
/**
|
|
36
|
+
* Processes function declarations to detect wrapper functions
|
|
37
|
+
*/
|
|
38
|
+
processFunctionDeclaration(node: TSESTree.FunctionDeclaration): void;
|
|
39
|
+
/**
|
|
40
|
+
* Analyzes a function to see if it wraps a vanilla-extract function
|
|
41
|
+
*/
|
|
42
|
+
private analyzeWrapperFunction;
|
|
43
|
+
/**
|
|
44
|
+
* Analyzes a wrapper function expression to detect vanilla-extract calls and parameter mapping
|
|
45
|
+
*/
|
|
46
|
+
private analyzeWrapperExpression;
|
|
47
|
+
/**
|
|
48
|
+
* Checks if a node is a vanilla-extract function call
|
|
49
|
+
*/
|
|
50
|
+
private checkForVanillaExtractCall;
|
|
51
|
+
/**
|
|
52
|
+
* Traverses a block statement to find vanilla-extract calls
|
|
53
|
+
*/
|
|
54
|
+
private traverseBlockForVanillaExtractCalls;
|
|
55
|
+
/**
|
|
56
|
+
* Checks if a function name corresponds to a tracked vanilla-extract function
|
|
57
|
+
*/
|
|
58
|
+
isTrackedFunction(functionName: string): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Gets the category of a tracked function
|
|
61
|
+
*/
|
|
62
|
+
getFunctionCategory(functionName: string): keyof TrackedFunctions | null;
|
|
63
|
+
/**
|
|
64
|
+
* Gets the original imported name for a local function name
|
|
65
|
+
*/
|
|
66
|
+
getOriginalName(localName: string): string | null;
|
|
67
|
+
/**
|
|
68
|
+
* Gets wrapper function information
|
|
69
|
+
*/
|
|
70
|
+
getWrapperInfo(functionName: string): WrapperFunctionInfo | null;
|
|
71
|
+
/**
|
|
72
|
+
* Gets all tracked functions by category
|
|
73
|
+
*/
|
|
74
|
+
getTrackedFunctions(): TrackedFunctions;
|
|
75
|
+
/**
|
|
76
|
+
* Resets the tracker state (useful for processing multiple files)
|
|
77
|
+
*/
|
|
78
|
+
reset(): void;
|
|
79
|
+
private isVanillaExtractSource;
|
|
80
|
+
private categorizeFunction;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Creates a visitor that tracks vanilla-extract imports and bindings
|
|
84
|
+
*/
|
|
85
|
+
export declare function createReferenceTrackingVisitor(tracker: ReferenceTracker): Rule.RuleListener;
|