@antebudimir/eslint-plugin-vanilla-extract 1.10.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 CHANGED
@@ -27,6 +27,8 @@ ordering option based on groups available in [concentric CSS](src/css-rules/conc
27
27
  - Handles complex cases like nested objects, arrays of styles, and pseudo selectors
28
28
  - Works with camelCase properties as used in vanilla-extract
29
29
  - Additional linting rules for enhanced code quality (see roadmap for upcoming features)
30
+ - Automatic wrapper function detection - works with custom wrapper functions that call vanilla-extract APIs, using
31
+ reference tracking to apply all rules regardless of how vanilla-extract functions are wrapped
30
32
 
31
33
  ## Requirements
32
34
 
@@ -537,16 +539,16 @@ The roadmap outlines the project's current status and future plans:
537
539
  - Recommended ESLint configuration for the plugin.
538
540
  - `no-zero-unit` rule to disallow units when the value is zero.
539
541
  - `no-unknown-unit` rule to disallow unknown units.
542
+ - Support for using the plugin’s recommended config via the extends field (as discussed in
543
+ [issue #3](https://github.com/antebudimir/eslint-plugin-vanilla-extract/issues/3))
540
544
  - Comprehensive rule testing.
541
545
 
542
546
  ### Current Work
543
547
 
544
- - Support for using the plugin’s recommended config via the extends field (as discussed in
545
- [issue #3](https://github.com/antebudimir/eslint-plugin-vanilla-extract/issues/3))
548
+ - `no-number-trailing-zero` rule to disallow trailing zeros in numbers.
546
549
 
547
550
  ### Upcoming Features
548
551
 
549
- - `no-number-trailing-zero` rule to disallow trailing zeros in numbers.
550
552
  - `no-px-unit` rule to disallow use of `px` units with configurable whitelist.
551
553
  - `prefer-logical-properties` rule to enforce use of logical properties.
552
554
  - `prefer-theme-tokens` rule to enforce use of theme tokens instead of hard-coded values when available.
@@ -5,8 +5,7 @@ import { TSESTree } from '@typescript-eslint/utils';
5
5
  */
6
6
  export declare const isEffectivelyEmptyStylesObject: (stylesObject: TSESTree.ObjectExpression) => boolean;
7
7
  /**
8
- * Creates ESLint rule visitors for detecting empty style blocks in vanilla-extract.
9
- * @param ruleContext The ESLint rule rule context.
10
- * @returns An object with visitor functions for the ESLint rule.
8
+ * Creates ESLint rule visitors for detecting empty style blocks using reference tracking.
9
+ * This automatically detects vanilla-extract functions based on their import statements.
11
10
  */
12
11
  export declare const createEmptyStyleVisitors: (ruleContext: Rule.RuleContext) => Rule.RuleListener;
@@ -1,12 +1,29 @@
1
1
  import { TSESTree } from '@typescript-eslint/utils';
2
2
  import { isEmptyObject } from '../shared-utils/empty-object-processor.js';
3
+ import { ReferenceTracker, createReferenceTrackingVisitor } from '../shared-utils/reference-tracker.js';
3
4
  import { processConditionalExpression } from './conditional-processor.js';
4
5
  import { processEmptyNestedStyles } from './empty-nested-style-processor.js';
5
6
  import { reportEmptyDeclaration } from './fix-utils.js';
6
- import { removeNodeWithComma } from './node-remover.js';
7
7
  import { getStyleKeyName } from './property-utils.js';
8
8
  import { processRecipeProperties } from './recipe-processor.js';
9
9
  import { processStyleVariants } from './style-variants-processor.js';
10
+ /**
11
+ * Checks if a nested object (selectors, media, supports) contains only empty objects.
12
+ */
13
+ const isNestedObjectEmpty = (obj) => {
14
+ if (obj.properties.length === 0) {
15
+ return true;
16
+ }
17
+ return obj.properties.every((property) => {
18
+ if (property.type !== 'Property') {
19
+ return true; // Skip non-property elements
20
+ }
21
+ if (property.value.type === 'ObjectExpression') {
22
+ return isEmptyObject(property.value);
23
+ }
24
+ return false; // Non-object values mean it's not empty
25
+ });
26
+ };
10
27
  /**
11
28
  * Checks if a style object is effectively empty (contains only empty objects).
12
29
  */
@@ -42,98 +59,98 @@ export const isEffectivelyEmptyStylesObject = (stylesObject) => {
42
59
  }
43
60
  }
44
61
  }
45
- // If this looks like a recipe object (has base or variants)
62
+ // If this looks like a recipe (has base or variants), check recipe-specific emptiness
46
63
  if (hasBaseProperty || hasVariantsProperty) {
47
- // A recipe is effectively empty if both base and variants are empty
48
64
  return isBaseEmpty && areAllVariantsEmpty;
49
65
  }
50
- // / For non-recipe objects, check if all special properties (selectors, media queries, variants) are effectively empty
51
- function isSpecialProperty(propertyName) {
52
- return (propertyName === 'selectors' || (propertyName && propertyName.startsWith('@')) || propertyName === 'variants');
53
- }
54
- const specialProperties = stylesObject.properties.filter((prop) => prop.type === 'Property' && isSpecialProperty(getStyleKeyName(prop.key)));
55
- const allSpecialPropertiesEmpty = specialProperties.every((property) => {
56
- if (property.value.type === 'ObjectExpression' && isEmptyObject(property.value)) {
57
- return true;
66
+ // For regular style objects, check if all properties are effectively empty
67
+ return stylesObject.properties.every((property) => {
68
+ if (property.type !== 'Property') {
69
+ return true; // Skip spread elements for emptiness check
58
70
  }
59
71
  const propertyName = getStyleKeyName(property.key);
60
- // This defensive check handles malformed AST nodes that lack valid property names.
61
- // This is difficult to test because it's challenging to construct a valid AST
62
- // where getStyleKeyName would return a falsy value.
63
72
  if (!propertyName) {
64
- return false;
73
+ return true; // Skip properties we can't identify
65
74
  }
66
- // For selectors, media queries and supports, check if all nested objects are empty
67
- if ((propertyName === 'selectors' || (propertyName && propertyName.startsWith('@'))) &&
68
- property.value.type === 'ObjectExpression') {
69
- // This handles the edge case of an empty properties array.
70
- // This code path is difficult to test in isolation because it requires
71
- // constructing a specific AST structure that bypasses earlier conditions.
72
- if (property.value.properties.length === 0) {
73
- return true;
74
- }
75
- return property.value.properties.every((nestedProperty) => {
76
- return (nestedProperty.type === 'Property' &&
77
- nestedProperty.value.type === 'ObjectExpression' &&
78
- isEmptyObject(nestedProperty.value));
79
- });
75
+ // Handle special nested objects like selectors, media queries, supports
76
+ if (propertyName === 'selectors' || propertyName.startsWith('@')) {
77
+ if (property.value.type === 'ObjectExpression') {
78
+ return isNestedObjectEmpty(property.value);
79
+ }
80
+ return false; // Non-object values in these properties
81
+ }
82
+ // Handle regular CSS properties
83
+ if (property.value.type === 'ObjectExpression') {
84
+ return isEmptyObject(property.value);
80
85
  }
81
- // Default fallback for cases not handled by the conditions above.
82
- // This is difficult to test because it requires creating an AST structure
83
- // that doesn't trigger any of the preceding return statements.
84
- return false;
86
+ return false; // Non-empty property (literal values, etc.)
85
87
  });
86
- // If we have special properties and they're all empty, the style is effectively empty
87
- return specialProperties.length > 0 && allSpecialPropertiesEmpty;
88
88
  };
89
89
  /**
90
- * Creates ESLint rule visitors for detecting empty style blocks in vanilla-extract.
91
- * @param ruleContext The ESLint rule rule context.
92
- * @returns An object with visitor functions for the ESLint rule.
90
+ * Creates ESLint rule visitors for detecting empty style blocks using reference tracking.
91
+ * This automatically detects vanilla-extract functions based on their import statements.
93
92
  */
94
93
  export const createEmptyStyleVisitors = (ruleContext) => {
95
- // Track reported nodes to prevent duplicate reports
94
+ const tracker = new ReferenceTracker();
95
+ const trackingVisitor = createReferenceTrackingVisitor(tracker);
96
96
  const reportedNodes = new Set();
97
97
  return {
98
+ // Include the reference tracking visitors
99
+ ...trackingVisitor,
98
100
  CallExpression(node) {
99
101
  if (node.callee.type !== 'Identifier') {
100
102
  return;
101
103
  }
102
- // Target vanilla-extract style functions
103
- const styleApiFunctions = [
104
- 'style',
105
- 'styleVariants',
106
- 'recipe',
107
- 'globalStyle',
108
- 'fontFace',
109
- 'globalFontFace',
110
- 'keyframes',
111
- 'globalKeyframes',
112
- ];
113
- if (!styleApiFunctions.includes(node.callee.name) || node.arguments.length === 0) {
104
+ const functionName = node.callee.name;
105
+ // Check if this function is tracked as a vanilla-extract function
106
+ if (!tracker.isTrackedFunction(functionName)) {
107
+ return;
108
+ }
109
+ const originalName = tracker.getOriginalName(functionName);
110
+ const wrapperInfo = tracker.getWrapperInfo(functionName);
111
+ if (!originalName || node.arguments.length === 0) {
114
112
  return;
115
113
  }
116
114
  // Handle styleVariants specifically
117
- if (node.callee.name === 'styleVariants' && node.arguments[0]?.type === 'ObjectExpression') {
118
- processStyleVariants(ruleContext, node.arguments[0], reportedNodes);
119
- // If the entire styleVariants object is empty after processing, remove the declaration
120
- if (isEmptyObject(node.arguments[0])) {
121
- reportEmptyDeclaration(ruleContext, node.arguments[0], node);
115
+ if (originalName === 'styleVariants') {
116
+ // For wrapper functions, use the correct parameter index
117
+ const styleArgumentIndex = wrapperInfo?.parameterMapping ?? 0;
118
+ if (node.arguments.length <= styleArgumentIndex) {
119
+ return;
120
+ }
121
+ if (node.arguments[styleArgumentIndex]?.type === 'ObjectExpression') {
122
+ processStyleVariants(ruleContext, node.arguments[styleArgumentIndex], reportedNodes);
123
+ // If the entire styleVariants object is empty after processing, remove the declaration
124
+ if (isEmptyObject(node.arguments[styleArgumentIndex])) {
125
+ reportEmptyDeclaration(ruleContext, node.arguments[styleArgumentIndex], node);
126
+ }
122
127
  }
123
128
  return;
124
129
  }
125
- const defaultStyleArgumentIndex = 0;
126
- const globalFunctionNames = ['globalStyle', 'globalFontFace', 'globalKeyframes'];
127
- // Determine the style argument index based on the function name
128
- const styleArgumentIndex = globalFunctionNames.includes(node.callee.name) ? 1 : defaultStyleArgumentIndex;
130
+ // Determine the style argument index based on the original function name and wrapper info
131
+ let styleArgumentIndex;
132
+ if (wrapperInfo) {
133
+ // Use wrapper function parameter mapping
134
+ styleArgumentIndex = wrapperInfo.parameterMapping;
135
+ }
136
+ else {
137
+ // Use original logic for direct vanilla-extract calls
138
+ styleArgumentIndex =
139
+ originalName === 'globalStyle' || originalName === 'globalKeyframes' || originalName === 'globalFontFace'
140
+ ? 1
141
+ : 0;
142
+ }
129
143
  // For global functions, check if we have enough arguments
130
- if (styleArgumentIndex === 1 && node.arguments.length <= styleArgumentIndex) {
144
+ if ((originalName === 'globalStyle' || originalName === 'globalKeyframes' || originalName === 'globalFontFace') &&
145
+ node.arguments.length <= styleArgumentIndex) {
146
+ return;
147
+ }
148
+ // For wrapper functions, ensure we have enough arguments
149
+ if (wrapperInfo && node.arguments.length <= styleArgumentIndex) {
131
150
  return;
132
151
  }
133
152
  const styleArgument = node.arguments[styleArgumentIndex];
134
153
  // This defensive check prevents duplicate processing of nodes.
135
- // This code path's difficult to test because the ESLint visitor pattern
136
- // typically ensures each node is only visited once per rule execution.
137
154
  if (reportedNodes.has(styleArgument)) {
138
155
  return;
139
156
  }
@@ -149,14 +166,27 @@ export const createEmptyStyleVisitors = (ruleContext) => {
149
166
  return;
150
167
  }
151
168
  // For recipe - check if entire recipe is effectively empty
152
- if (node.callee.name === 'recipe' && styleArgument?.type === 'ObjectExpression') {
153
- if (isEffectivelyEmptyStylesObject(styleArgument)) {
169
+ if (originalName === 'recipe') {
170
+ if (styleArgument?.type === 'ObjectExpression') {
171
+ if (isEffectivelyEmptyStylesObject(styleArgument)) {
172
+ reportedNodes.add(styleArgument);
173
+ reportEmptyDeclaration(ruleContext, styleArgument, node);
174
+ return;
175
+ }
176
+ // Process individual properties in recipe
177
+ processRecipeProperties(ruleContext, styleArgument, reportedNodes);
178
+ }
179
+ return;
180
+ }
181
+ // Handle fontFace functions - both fontFace and globalFontFace need empty object checks
182
+ if (originalName === 'fontFace' || originalName === 'globalFontFace') {
183
+ // Direct empty object case - remove the entire declaration
184
+ if (styleArgument?.type === 'ObjectExpression' && isEmptyObject(styleArgument)) {
154
185
  reportedNodes.add(styleArgument);
155
186
  reportEmptyDeclaration(ruleContext, styleArgument, node);
156
187
  return;
157
188
  }
158
- // Process individual properties in recipe
159
- processRecipeProperties(ruleContext, styleArgument, reportedNodes);
189
+ return;
160
190
  }
161
191
  // For style objects with nested empty objects
162
192
  if (styleArgument?.type === 'ObjectExpression') {
@@ -170,7 +200,10 @@ export const createEmptyStyleVisitors = (ruleContext) => {
170
200
  node: property.argument,
171
201
  messageId: 'emptySpreadObject',
172
202
  fix(fixer) {
173
- return removeNodeWithComma(ruleContext, property, fixer);
203
+ if (property.range) {
204
+ return fixer.removeRange([property.range[0], property.range[1]]);
205
+ }
206
+ return null;
174
207
  },
175
208
  });
176
209
  }
@@ -1,6 +1,7 @@
1
1
  import type { Rule } from 'eslint';
2
2
  /**
3
3
  * Creates ESLint rule visitors for detecting and processing unknown CSS units
4
- * in style-related function calls.
4
+ * in style-related function calls using reference tracking.
5
+ * This automatically detects vanilla-extract functions based on their import statements.
5
6
  */
6
7
  export declare const createUnknownUnitVisitors: (context: Rule.RuleContext) => Rule.RuleListener;
@@ -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
- if (['fontFace', 'globalFontFace'].includes(node.callee.name)) {
16
- const argumentIndex = node.callee.name === 'fontFace' ? 0 : 1;
17
- if (node.arguments.length > argumentIndex &&
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
- if (['keyframes', 'style', 'styleVariants'].includes(node.callee.name)) {
24
- if (node.arguments.length > 0) {
25
- processStyleNode(context, node.arguments[0], processUnknownUnitInStyleObject);
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
- if (node.callee.name === 'recipe' &&
32
- node.arguments.length > 0 &&
33
- node.arguments[0]?.type === AST_NODE_TYPES.ObjectExpression) {
34
- processRecipeProperties(context, node.arguments[0], processUnknownUnitInStyleObject);
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
- if (['fontFace', 'globalFontFace'].includes(node.callee.name)) {
24
- const argumentIndex = node.callee.name === 'fontFace' ? 0 : 1;
25
- if (node.arguments.length > argumentIndex &&
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
- if (['keyframes', 'style', 'styleVariants'].includes(node.callee.name)) {
32
- if (node.arguments.length > 0) {
33
- processStyleNode(context, node.arguments[0], processZeroUnitInStyleObject);
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
- if (node.callee.name === 'recipe' &&
40
- node.arguments.length > 0 &&
41
- node.arguments[0]?.type === AST_NODE_TYPES.ObjectExpression) {
42
- processRecipeProperties(context, node.arguments[0], processZeroUnitInStyleObject);
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
- // 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.0',
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.0",
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",