@antebudimir/eslint-plugin-vanilla-extract 1.10.0 → 1.11.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.
@@ -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
- // Select the appropriate property processing function based on the ordering strategy
28
- const processProperty = (() => {
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 fontFaceFunctionArgumentIndexMap = {
49
- fontFace: 0, // First argument (index 0)
50
- globalFontFace: 1, // Second argument (index 1)
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
- // Handle style-related functions
62
- if (['keyframes', 'style', 'styleVariants'].includes(node.callee.name)) {
63
- if (node.arguments.length > 0) {
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 recipe function
75
- if (node.callee.name === 'recipe') {
76
- switch (orderingStrategy) {
77
- case 'alphabetical':
78
- enforceAlphabeticalCSSOrderInRecipe(node, ruleContext);
79
- break;
80
- case 'concentric':
81
- enforceConcentricCSSOrderInRecipe(ruleContext, node);
82
- break;
83
- case 'userDefinedGroupOrder':
84
- if (userDefinedGroupOrder) {
85
- enforceUserDefinedGroupOrderInRecipe(ruleContext, node, userDefinedGroupOrder, sortRemainingProperties);
86
- }
87
- break;
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;
@@ -0,0 +1,260 @@
1
+ import { TSESTree } from '@typescript-eslint/utils';
2
+ /**
3
+ * Tracks vanilla-extract function imports and their local bindings
4
+ */
5
+ export class ReferenceTracker {
6
+ constructor() {
7
+ this.imports = new Map();
8
+ this.wrapperFunctions = new Map(); // wrapper function name -> detailed info
9
+ this.trackedFunctions = {
10
+ styleFunctions: new Set(),
11
+ recipeFunctions: new Set(),
12
+ fontFaceFunctions: new Set(),
13
+ globalFunctions: new Set(),
14
+ keyframeFunctions: new Set(),
15
+ };
16
+ }
17
+ /**
18
+ * Processes import declarations to track vanilla-extract functions
19
+ */
20
+ processImportDeclaration(node) {
21
+ const source = node.source.value;
22
+ // Check if this is a vanilla-extract import
23
+ if (typeof source !== 'string' || !this.isVanillaExtractSource(source)) {
24
+ return;
25
+ }
26
+ node.specifiers.forEach((specifier) => {
27
+ if (specifier.type === 'ImportSpecifier') {
28
+ const importedName = specifier.imported.type === 'Identifier' ? specifier.imported.name : specifier.imported.value;
29
+ const localName = specifier.local.name;
30
+ const reference = {
31
+ source,
32
+ importedName,
33
+ localName,
34
+ };
35
+ this.imports.set(localName, reference);
36
+ this.categorizeFunction(localName, importedName);
37
+ }
38
+ });
39
+ }
40
+ /**
41
+ * Processes variable declarations to track re-assignments and destructuring
42
+ */
43
+ processVariableDeclarator(node) {
44
+ // Handle destructuring assignments like: const { style, recipe } = vanillaExtract;
45
+ if (node.id.type === 'ObjectPattern' && node.init?.type === 'Identifier') {
46
+ const sourceIdentifier = node.init.name;
47
+ const sourceReference = this.imports.get(sourceIdentifier);
48
+ if (sourceReference && this.isVanillaExtractSource(sourceReference.source)) {
49
+ node.id.properties.forEach((property) => {
50
+ if (property.type === 'Property' &&
51
+ property.key.type === 'Identifier' &&
52
+ property.value.type === 'Identifier') {
53
+ const importedName = property.key.name;
54
+ const localName = property.value.name;
55
+ const reference = {
56
+ source: sourceReference.source,
57
+ importedName,
58
+ localName,
59
+ };
60
+ this.imports.set(localName, reference);
61
+ this.categorizeFunction(localName, importedName);
62
+ }
63
+ });
64
+ }
65
+ }
66
+ // Handle simple assignments like: const myStyle = style;
67
+ if (node.id.type === 'Identifier' && node.init?.type === 'Identifier') {
68
+ const sourceReference = this.imports.get(node.init.name);
69
+ if (sourceReference) {
70
+ this.imports.set(node.id.name, sourceReference);
71
+ this.categorizeFunction(node.id.name, sourceReference.importedName);
72
+ }
73
+ }
74
+ // Handle arrow function assignments that wrap vanilla-extract functions
75
+ if (node.id.type === 'Identifier' && node.init?.type === 'ArrowFunctionExpression') {
76
+ this.analyzeWrapperFunction(node.id.name, node.init);
77
+ }
78
+ }
79
+ /**
80
+ * Processes function declarations to detect wrapper functions
81
+ */
82
+ processFunctionDeclaration(node) {
83
+ if (node.id?.name) {
84
+ this.analyzeWrapperFunction(node.id.name, node);
85
+ }
86
+ }
87
+ /**
88
+ * Analyzes a function to see if it wraps a vanilla-extract function
89
+ */
90
+ analyzeWrapperFunction(functionName, functionNode) {
91
+ const body = functionNode.body;
92
+ // Handle arrow functions with expression body
93
+ if (functionNode.type === 'ArrowFunctionExpression' && body.type !== 'BlockStatement') {
94
+ this.analyzeWrapperExpression(functionName, body);
95
+ return;
96
+ }
97
+ // Handle functions with block statement body
98
+ if (body.type === 'BlockStatement') {
99
+ this.traverseBlockForVanillaExtractCalls(functionName, body);
100
+ }
101
+ }
102
+ /**
103
+ * Analyzes a wrapper function expression to detect vanilla-extract calls and parameter mapping
104
+ */
105
+ analyzeWrapperExpression(wrapperName, expression) {
106
+ if (expression.type === 'CallExpression' && expression.callee.type === 'Identifier') {
107
+ const calledFunction = expression.callee.name;
108
+ if (this.isTrackedFunction(calledFunction)) {
109
+ const originalName = this.getOriginalName(calledFunction);
110
+ if (originalName) {
111
+ // For now, create a simple wrapper info
112
+ const wrapperInfo = {
113
+ originalFunction: originalName,
114
+ parameterMapping: 1, // layerStyle uses second parameter as the style object
115
+ };
116
+ this.wrapperFunctions.set(wrapperName, wrapperInfo);
117
+ this.categorizeFunction(wrapperName, originalName);
118
+ }
119
+ }
120
+ }
121
+ }
122
+ /**
123
+ * Checks if a node is a vanilla-extract function call
124
+ */
125
+ checkForVanillaExtractCall(wrapperName, node) {
126
+ if (node.type === 'CallExpression' && node.callee.type === 'Identifier') {
127
+ const calledFunction = node.callee.name;
128
+ if (this.isTrackedFunction(calledFunction)) {
129
+ const originalName = this.getOriginalName(calledFunction);
130
+ if (originalName) {
131
+ const wrapperInfo = {
132
+ originalFunction: originalName,
133
+ parameterMapping: 0, // Default to first parameter
134
+ };
135
+ this.wrapperFunctions.set(wrapperName, wrapperInfo);
136
+ this.categorizeFunction(wrapperName, originalName);
137
+ }
138
+ }
139
+ }
140
+ }
141
+ /**
142
+ * Traverses a block statement to find vanilla-extract calls
143
+ */
144
+ traverseBlockForVanillaExtractCalls(wrapperName, block) {
145
+ for (const statement of block.body) {
146
+ if (statement.type === 'ReturnStatement' && statement.argument) {
147
+ this.checkForVanillaExtractCall(wrapperName, statement.argument);
148
+ }
149
+ else if (statement.type === 'ExpressionStatement') {
150
+ this.checkForVanillaExtractCall(wrapperName, statement.expression);
151
+ }
152
+ }
153
+ }
154
+ /**
155
+ * Checks if a function name corresponds to a tracked vanilla-extract function
156
+ */
157
+ isTrackedFunction(functionName) {
158
+ return this.imports.has(functionName) || this.wrapperFunctions.has(functionName);
159
+ }
160
+ /**
161
+ * Gets the category of a tracked function
162
+ */
163
+ getFunctionCategory(functionName) {
164
+ if (this.trackedFunctions.styleFunctions.has(functionName)) {
165
+ return 'styleFunctions';
166
+ }
167
+ if (this.trackedFunctions.recipeFunctions.has(functionName)) {
168
+ return 'recipeFunctions';
169
+ }
170
+ if (this.trackedFunctions.fontFaceFunctions.has(functionName)) {
171
+ return 'fontFaceFunctions';
172
+ }
173
+ if (this.trackedFunctions.globalFunctions.has(functionName)) {
174
+ return 'globalFunctions';
175
+ }
176
+ if (this.trackedFunctions.keyframeFunctions.has(functionName)) {
177
+ return 'keyframeFunctions';
178
+ }
179
+ return null;
180
+ }
181
+ /**
182
+ * Gets the original imported name for a local function name
183
+ */
184
+ getOriginalName(localName) {
185
+ const reference = this.imports.get(localName);
186
+ if (reference) {
187
+ return reference.importedName;
188
+ }
189
+ // Check if it's a wrapper function
190
+ const wrapperInfo = this.wrapperFunctions.get(localName);
191
+ return wrapperInfo?.originalFunction ?? null;
192
+ }
193
+ /**
194
+ * Gets wrapper function information
195
+ */
196
+ getWrapperInfo(functionName) {
197
+ return this.wrapperFunctions.get(functionName) ?? null;
198
+ }
199
+ /**
200
+ * Gets all tracked functions by category
201
+ */
202
+ getTrackedFunctions() {
203
+ return this.trackedFunctions;
204
+ }
205
+ /**
206
+ * Resets the tracker state (useful for processing multiple files)
207
+ */
208
+ reset() {
209
+ this.imports.clear();
210
+ this.wrapperFunctions.clear();
211
+ this.trackedFunctions.styleFunctions.clear();
212
+ this.trackedFunctions.recipeFunctions.clear();
213
+ this.trackedFunctions.fontFaceFunctions.clear();
214
+ this.trackedFunctions.globalFunctions.clear();
215
+ this.trackedFunctions.keyframeFunctions.clear();
216
+ }
217
+ isVanillaExtractSource(source) {
218
+ return (source === '@vanilla-extract/css' ||
219
+ source === '@vanilla-extract/recipes' ||
220
+ source.startsWith('@vanilla-extract/'));
221
+ }
222
+ categorizeFunction(localName, importedName) {
223
+ switch (importedName) {
224
+ case 'style':
225
+ case 'styleVariants':
226
+ this.trackedFunctions.styleFunctions.add(localName);
227
+ break;
228
+ case 'recipe':
229
+ this.trackedFunctions.recipeFunctions.add(localName);
230
+ break;
231
+ case 'fontFace':
232
+ case 'globalFontFace':
233
+ this.trackedFunctions.fontFaceFunctions.add(localName);
234
+ break;
235
+ case 'globalStyle':
236
+ case 'globalKeyframes':
237
+ this.trackedFunctions.globalFunctions.add(localName);
238
+ break;
239
+ case 'keyframes':
240
+ this.trackedFunctions.keyframeFunctions.add(localName);
241
+ break;
242
+ }
243
+ }
244
+ }
245
+ /**
246
+ * Creates a visitor that tracks vanilla-extract imports and bindings
247
+ */
248
+ export function createReferenceTrackingVisitor(tracker) {
249
+ return {
250
+ ImportDeclaration(node) {
251
+ tracker.processImportDeclaration(node);
252
+ },
253
+ VariableDeclarator(node) {
254
+ tracker.processVariableDeclarator(node);
255
+ },
256
+ FunctionDeclaration(node) {
257
+ tracker.processFunctionDeclaration(node);
258
+ },
259
+ };
260
+ }
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import noZeroUnitRule from './css-rules/no-zero-unit/rule-definition.js';
7
7
  const vanillaExtract = {
8
8
  meta: {
9
9
  name: '@antebudimir/eslint-plugin-vanilla-extract',
10
- version: '1.10.0',
10
+ version: '1.11.1',
11
11
  },
12
12
  rules: {
13
13
  'alphabetical-order': alphabeticalOrderRule,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antebudimir/eslint-plugin-vanilla-extract",
3
- "version": "1.10.0",
3
+ "version": "1.11.1",
4
4
  "description": "ESLint plugin for enforcing best practices in vanilla-extract CSS styles, including CSS property ordering and additional linting rules.",
5
5
  "author": "Ante Budimir",
6
6
  "license": "MIT",