@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.
package/README.md CHANGED
@@ -5,6 +5,16 @@
5
5
  [![npm version](https://img.shields.io/npm/v/@antebudimir/eslint-plugin-vanilla-extract.svg)](https://www.npmjs.com/package/@antebudimir/eslint-plugin-vanilla-extract)
6
6
  ![NPM Downloads](https://img.shields.io/npm/d18m/%40antebudimir%2Feslint-plugin-vanilla-extract)
7
7
 
8
+ ---
9
+
10
+ **Maintaining this plugin takes time and care! If you find it valuable, please consider supporting its development:**
11
+ 💖 GitHub Sponsors: <https://github.com/sponsors/antebudimir>
12
+ ☕ Ko-fi: <https://ko-fi.com/antebudimir>
13
+ 💸 Revolut: <https://revolut.me/antebudimir>
14
+ 🟡 Liberapay: <https://liberapay.com/antebudimir>
15
+
16
+ ---
17
+
8
18
  An ESLint plugin for enforcing best practices in
9
19
  [vanilla-extract](https://github.com/vanilla-extract-css/vanilla-extract) CSS styles, including CSS property ordering
10
20
  and additional linting rules. Available presets are for alphabetical and
@@ -27,6 +37,8 @@ ordering option based on groups available in [concentric CSS](src/css-rules/conc
27
37
  - Handles complex cases like nested objects, arrays of styles, and pseudo selectors
28
38
  - Works with camelCase properties as used in vanilla-extract
29
39
  - Additional linting rules for enhanced code quality (see roadmap for upcoming features)
40
+ - Automatic wrapper function detection - works with custom wrapper functions that call vanilla-extract APIs, using
41
+ reference tracking to apply all rules regardless of how vanilla-extract functions are wrapped
30
42
 
31
43
  ## Requirements
32
44
 
@@ -65,7 +77,7 @@ There are two main ways to configure this plugin in your ESLint flat config:
65
77
 
66
78
  ### Option 1: Using extends (recommended, available from v1.10.0)
67
79
 
68
- The simplest way to apply the recommended ruleset:
80
+ The simplest and most concise way to apply the recommended ruleset:
69
81
 
70
82
  ```typescript
71
83
  import { defineConfig } from 'eslint/config';
@@ -76,13 +88,18 @@ export default defineConfig([
76
88
  files: ['**/*.css.ts'],
77
89
  ignores: ['src/**/theme-contract.css.ts'],
78
90
  extends: [vanillaExtract.configs.recommended],
91
+ // You can still override rules when using extends
92
+ // rules: {
93
+ // 'vanilla-extract/concentric-order': 'off',
94
+ // 'vanilla-extract/alphabetical-order': 'error',
95
+ // },
79
96
  },
80
97
  ];
81
98
  ```
82
99
 
83
- ### Option 2: Using plugins with explicit rule configuration
100
+ ### Option 2: Using plugins with explicit rule spreading
84
101
 
85
- This approach gives you more control over individual rules:
102
+ This approach is more explicit - you manually register the plugin and spread the recommended rules:
86
103
 
87
104
  ```typescript
88
105
  import { defineConfig } from 'eslint/config';
@@ -104,13 +121,64 @@ export default defineConfig([
104
121
  // 'vanilla-extract/no-empty-style-blocks': 'off', // Disable a recommended rule
105
122
  // 'vanilla-extract/no-zero-unit': 'warn', // Change severity from error to warn
106
123
 
107
- // Add additional rules not in recommended config
108
- // 'vanilla-extract/alphabetical-order': 'error', // Override concentric-order rule
124
+ // Switch to a different ordering rule (see "Important" section below)
125
+ // 'vanilla-extract/concentric-order': 'off',
126
+ // 'vanilla-extract/alphabetical-order': 'error',
127
+ },
128
+ },
129
+ ];
130
+ ```
131
+
132
+ #### Important: Only Enable One Ordering Rule at a Time
133
+
134
+ The plugin includes three CSS property ordering rules: `alphabetical-order`, `concentric-order`, and `custom-order`. **Only one ordering rule should be enabled at a time** to avoid conflicting auto-fixes.
135
+
136
+ If you want to use a different ordering rule than the one in the recommended config, you must explicitly disable the default rule.
137
+
138
+ ##### Example: Switching from concentric to alphabetical ordering
139
+
140
+ ```typescript
141
+ export default [
142
+ {
143
+ files: ['**/*.css.ts'],
144
+ plugins: {
145
+ 'vanilla-extract': vanillaExtract,
146
+ },
147
+ rules: {
148
+ ...vanillaExtract.configs.recommended.rules,
149
+ 'vanilla-extract/concentric-order': 'off', // Disable the default
150
+ 'vanilla-extract/alphabetical-order': 'error', // Enable alphabetical
151
+ },
152
+ },
153
+ ];
154
+ ```
155
+
156
+ ##### Example: Using custom-order instead of the recommended concentric-order
157
+
158
+ ```typescript
159
+ export default [
160
+ {
161
+ files: ['**/*.css.ts'],
162
+ plugins: {
163
+ 'vanilla-extract': vanillaExtract,
164
+ },
165
+ rules: {
166
+ ...vanillaExtract.configs.recommended.rules,
167
+ 'vanilla-extract/concentric-order': 'off', // Disable the default
168
+ 'vanilla-extract/custom-order': [
169
+ 'error',
170
+ {
171
+ groupOrder: ['font', 'dimensions', 'margin', 'padding', 'position', 'border'],
172
+ sortRemainingProperties: 'alphabetical',
173
+ },
174
+ ],
109
175
  },
110
176
  },
111
177
  ];
112
178
  ```
113
179
 
180
+ > **⚠️ Warning:** If multiple ordering rules are enabled simultaneously, they will produce conflicting auto-fixes that ESLint cannot apply, causing auto-fix on save to fail. Always ensure only one ordering rule is active.
181
+
114
182
  ### Using with FlatCompat (for ESLint 8.57.0 & 8.57.1)
115
183
 
116
184
  If you're migrating from legacy ESLint configurations, you can use the `FlatCompat` utility to convert them while adding
@@ -191,10 +259,15 @@ The recommended configuration enables the following rules with error severity:
191
259
 
192
260
  - `vanilla-extract/concentric-order`: Enforces concentric CSS property ordering
193
261
  - `vanilla-extract/no-empty-style-blocks`: Prevents empty style blocks
194
- - `vanilla-extract/no-unknown-unit`: prohibits usage of unrecognized CSS units.
195
- - `vanilla-extract/no-zero-unit`: removes unnecessary units for zero values
262
+ - `vanilla-extract/no-unknown-unit`: Prohibits usage of unrecognized CSS units
263
+ - `vanilla-extract/no-zero-unit`: Removes unnecessary units for zero values
196
264
 
197
- You can use the recommended configuration as a starting point and override rules as needed for your project.
265
+ **Additional rules available** (not enabled by default):
266
+
267
+ - `vanilla-extract/alphabetical-order`: Alternative ordering rule (alphabetical sorting)
268
+ - `vanilla-extract/custom-order`: Alternative ordering rule (custom group-based sorting)
269
+
270
+ You can use the recommended configuration as a starting point and override rules as needed for your project. See the configuration examples above for how to switch between ordering rules.
198
271
 
199
272
  ### Custom Configuration
200
273
 
@@ -228,6 +301,8 @@ export default [
228
301
  ];
229
302
  ```
230
303
 
304
+ > **Note:** Remember to enable only one ordering rule at a time. See the "Important" section above for details on switching between ordering rules.
305
+
231
306
  ## Rules
232
307
 
233
308
  ### vanilla-extract/alphabetical-order
@@ -537,16 +612,16 @@ The roadmap outlines the project's current status and future plans:
537
612
  - Recommended ESLint configuration for the plugin.
538
613
  - `no-zero-unit` rule to disallow units when the value is zero.
539
614
  - `no-unknown-unit` rule to disallow unknown units.
615
+ - Support for using the plugin’s recommended config via the extends field (as discussed in
616
+ [issue #3](https://github.com/antebudimir/eslint-plugin-vanilla-extract/issues/3))
540
617
  - Comprehensive rule testing.
541
618
 
542
619
  ### Current Work
543
620
 
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))
621
+ - `no-number-trailing-zero` rule to disallow trailing zeros in numbers.
546
622
 
547
623
  ### Upcoming Features
548
624
 
549
- - `no-number-trailing-zero` rule to disallow trailing zeros in numbers.
550
625
  - `no-px-unit` rule to disallow use of `px` units with configurable whitelist.
551
626
  - `prefer-logical-properties` rule to enforce use of logical properties.
552
627
  - `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;