@antebudimir/eslint-plugin-vanilla-extract 1.15.1 → 1.17.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.
@@ -0,0 +1,2 @@
1
+ import noUnitlessValuesRule from './rule-definition.js';
2
+ export default noUnitlessValuesRule;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ declare const noUnitlessValuesRule: Rule.RuleModule;
3
+ export default noUnitlessValuesRule;
@@ -0,0 +1,35 @@
1
+ import { createUnitlessValueVisitors } from './unitless-value-visitor-creator.js';
2
+ const noUnitlessValuesRule = {
3
+ meta: {
4
+ type: 'suggestion',
5
+ docs: {
6
+ description: 'disallow unitless numeric values for CSS properties that require units',
7
+ category: 'Stylistic Issues',
8
+ recommended: false,
9
+ },
10
+ schema: [
11
+ {
12
+ type: 'object',
13
+ properties: {
14
+ allow: {
15
+ type: 'array',
16
+ items: {
17
+ type: 'string',
18
+ },
19
+ uniqueItems: true,
20
+ default: [],
21
+ },
22
+ },
23
+ additionalProperties: false,
24
+ },
25
+ ],
26
+ messages: {
27
+ noUnitlessValue: 'Property "{{ property }}" has unitless value {{ value }}. Add an explicit unit (e.g., "{{ value }}px", "{{ value }}rem").',
28
+ },
29
+ },
30
+ create(context) {
31
+ const options = context.options[0] || {};
32
+ return createUnitlessValueVisitors(context, options);
33
+ },
34
+ };
35
+ export default noUnitlessValuesRule;
@@ -0,0 +1,13 @@
1
+ import type { Rule } from 'eslint';
2
+ import { TSESTree } from '@typescript-eslint/utils';
3
+ export interface NoUnitlessValuesOptions {
4
+ allow?: string[];
5
+ }
6
+ /**
7
+ * Recursively processes a style object, reporting instances of unitless numeric values for properties that require units.
8
+ *
9
+ * @param ruleContext The ESLint rule context.
10
+ * @param node The ObjectExpression node representing the style object to be processed.
11
+ * @param options Rule options including allow list.
12
+ */
13
+ export declare const processUnitlessValueInStyleObject: (ruleContext: Rule.RuleContext, node: TSESTree.ObjectExpression, options?: NoUnitlessValuesOptions) => void;
@@ -0,0 +1,330 @@
1
+ import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';
2
+ /**
3
+ * CSS properties that require units for length/dimension values.
4
+ * These properties should not have unitless numeric values (except 0).
5
+ */
6
+ const PROPERTIES_REQUIRING_UNITS = new Set([
7
+ // Box model
8
+ 'width',
9
+ 'height',
10
+ 'minWidth',
11
+ 'maxWidth',
12
+ 'minHeight',
13
+ 'maxHeight',
14
+ 'min-width',
15
+ 'max-width',
16
+ 'min-height',
17
+ 'max-height',
18
+ // Spacing
19
+ 'margin',
20
+ 'marginTop',
21
+ 'marginRight',
22
+ 'marginBottom',
23
+ 'marginLeft',
24
+ 'marginBlock',
25
+ 'marginBlockStart',
26
+ 'marginBlockEnd',
27
+ 'marginInline',
28
+ 'marginInlineStart',
29
+ 'marginInlineEnd',
30
+ 'margin-top',
31
+ 'margin-right',
32
+ 'margin-bottom',
33
+ 'margin-left',
34
+ 'margin-block',
35
+ 'margin-block-start',
36
+ 'margin-block-end',
37
+ 'margin-inline',
38
+ 'margin-inline-start',
39
+ 'margin-inline-end',
40
+ 'padding',
41
+ 'paddingTop',
42
+ 'paddingRight',
43
+ 'paddingBottom',
44
+ 'paddingLeft',
45
+ 'paddingBlock',
46
+ 'paddingBlockStart',
47
+ 'paddingBlockEnd',
48
+ 'paddingInline',
49
+ 'paddingInlineStart',
50
+ 'paddingInlineEnd',
51
+ 'padding-top',
52
+ 'padding-right',
53
+ 'padding-bottom',
54
+ 'padding-left',
55
+ 'padding-block',
56
+ 'padding-block-start',
57
+ 'padding-block-end',
58
+ 'padding-inline',
59
+ 'padding-inline-start',
60
+ 'padding-inline-end',
61
+ // Positioning
62
+ 'top',
63
+ 'right',
64
+ 'bottom',
65
+ 'left',
66
+ 'inset',
67
+ 'insetBlock',
68
+ 'insetBlockStart',
69
+ 'insetBlockEnd',
70
+ 'insetInline',
71
+ 'insetInlineStart',
72
+ 'insetInlineEnd',
73
+ 'inset-block',
74
+ 'inset-block-start',
75
+ 'inset-block-end',
76
+ 'inset-inline',
77
+ 'inset-inline-start',
78
+ 'inset-inline-end',
79
+ // Border
80
+ 'borderWidth',
81
+ 'borderTopWidth',
82
+ 'borderRightWidth',
83
+ 'borderBottomWidth',
84
+ 'borderLeftWidth',
85
+ 'borderBlockWidth',
86
+ 'borderBlockStartWidth',
87
+ 'borderBlockEndWidth',
88
+ 'borderInlineWidth',
89
+ 'borderInlineStartWidth',
90
+ 'borderInlineEndWidth',
91
+ 'border-width',
92
+ 'border-top-width',
93
+ 'border-right-width',
94
+ 'border-bottom-width',
95
+ 'border-left-width',
96
+ 'border-block-width',
97
+ 'border-block-start-width',
98
+ 'border-block-end-width',
99
+ 'border-inline-width',
100
+ 'border-inline-start-width',
101
+ 'border-inline-end-width',
102
+ 'borderRadius',
103
+ 'borderTopLeftRadius',
104
+ 'borderTopRightRadius',
105
+ 'borderBottomLeftRadius',
106
+ 'borderBottomRightRadius',
107
+ 'borderStartStartRadius',
108
+ 'borderStartEndRadius',
109
+ 'borderEndStartRadius',
110
+ 'borderEndEndRadius',
111
+ 'border-radius',
112
+ 'border-top-left-radius',
113
+ 'border-top-right-radius',
114
+ 'border-bottom-left-radius',
115
+ 'border-bottom-right-radius',
116
+ 'border-start-start-radius',
117
+ 'border-start-end-radius',
118
+ 'border-end-start-radius',
119
+ 'border-end-end-radius',
120
+ // Typography
121
+ 'fontSize',
122
+ 'font-size',
123
+ 'letterSpacing',
124
+ 'letter-spacing',
125
+ 'wordSpacing',
126
+ 'word-spacing',
127
+ 'textIndent',
128
+ 'text-indent',
129
+ // Flexbox/Grid
130
+ 'gap',
131
+ 'rowGap',
132
+ 'columnGap',
133
+ 'row-gap',
134
+ 'column-gap',
135
+ 'flexBasis',
136
+ 'flex-basis',
137
+ // Outline
138
+ 'outlineWidth',
139
+ 'outline-width',
140
+ 'outlineOffset',
141
+ 'outline-offset',
142
+ // Other
143
+ 'blockSize',
144
+ 'inlineSize',
145
+ 'minBlockSize',
146
+ 'maxBlockSize',
147
+ 'minInlineSize',
148
+ 'maxInlineSize',
149
+ 'block-size',
150
+ 'inline-size',
151
+ 'min-block-size',
152
+ 'max-block-size',
153
+ 'min-inline-size',
154
+ 'max-inline-size',
155
+ ]);
156
+ /**
157
+ * CSS properties that accept unitless numeric values.
158
+ * These properties should NOT be flagged when they have numeric values.
159
+ */
160
+ const UNITLESS_VALID_PROPERTIES = new Set([
161
+ 'opacity',
162
+ 'zIndex',
163
+ 'z-index',
164
+ 'lineHeight',
165
+ 'line-height',
166
+ 'flexGrow',
167
+ 'flex-grow',
168
+ 'flexShrink',
169
+ 'flex-shrink',
170
+ 'order',
171
+ 'fontWeight',
172
+ 'font-weight',
173
+ 'zoom',
174
+ 'animationIterationCount',
175
+ 'animation-iteration-count',
176
+ 'columnCount',
177
+ 'column-count',
178
+ 'gridColumn',
179
+ 'grid-column',
180
+ 'gridColumnEnd',
181
+ 'grid-column-end',
182
+ 'gridColumnStart',
183
+ 'grid-column-start',
184
+ 'gridRow',
185
+ 'grid-row',
186
+ 'gridRowEnd',
187
+ 'grid-row-end',
188
+ 'gridRowStart',
189
+ 'grid-row-start',
190
+ 'orphans',
191
+ 'widows',
192
+ 'fillOpacity',
193
+ 'fill-opacity',
194
+ 'strokeOpacity',
195
+ 'stroke-opacity',
196
+ 'strokeMiterlimit',
197
+ 'stroke-miterlimit',
198
+ ]);
199
+ /**
200
+ * Checks if a property name requires units for numeric values.
201
+ */
202
+ const requiresUnits = (propertyName, allow = []) => {
203
+ if (allow.includes(propertyName)) {
204
+ return false;
205
+ }
206
+ if (UNITLESS_VALID_PROPERTIES.has(propertyName)) {
207
+ return false;
208
+ }
209
+ return PROPERTIES_REQUIRING_UNITS.has(propertyName);
210
+ };
211
+ /**
212
+ * Gets the property name from a Property node.
213
+ */
214
+ const getPropertyName = (property) => {
215
+ if (property.key.type === AST_NODE_TYPES.Identifier) {
216
+ return property.key.name;
217
+ }
218
+ if (property.key.type === AST_NODE_TYPES.Literal && typeof property.key.value === 'string') {
219
+ return property.key.value;
220
+ }
221
+ return null;
222
+ };
223
+ /**
224
+ * Recursively processes a style object, reporting instances of unitless numeric values for properties that require units.
225
+ *
226
+ * @param ruleContext The ESLint rule context.
227
+ * @param node The ObjectExpression node representing the style object to be processed.
228
+ * @param options Rule options including allow list.
229
+ */
230
+ export const processUnitlessValueInStyleObject = (ruleContext, node, options = {}) => {
231
+ const allow = options.allow || [];
232
+ node.properties.forEach((property) => {
233
+ if (property.type !== AST_NODE_TYPES.Property) {
234
+ return;
235
+ }
236
+ const propertyName = getPropertyName(property);
237
+ if (!propertyName) {
238
+ return;
239
+ }
240
+ // Skip special nested structures like @media, selectors, etc.
241
+ // These will be processed recursively
242
+ if (propertyName.startsWith('@') || propertyName.startsWith(':') || propertyName === 'selectors') {
243
+ if (property.value.type === AST_NODE_TYPES.ObjectExpression) {
244
+ if (propertyName === '@media' || propertyName === 'selectors') {
245
+ property.value.properties.forEach((nestedProperty) => {
246
+ if (nestedProperty.type === AST_NODE_TYPES.Property &&
247
+ nestedProperty.value.type === AST_NODE_TYPES.ObjectExpression) {
248
+ processUnitlessValueInStyleObject(ruleContext, nestedProperty.value, options);
249
+ }
250
+ });
251
+ }
252
+ else {
253
+ // For pseudo-selectors and other nested objects, process directly
254
+ processUnitlessValueInStyleObject(ruleContext, property.value, options);
255
+ }
256
+ }
257
+ return;
258
+ }
259
+ // Check if this property requires units
260
+ if (!requiresUnits(propertyName, allow)) {
261
+ // Still need to process nested objects for non-CSS properties
262
+ if (property.value.type === AST_NODE_TYPES.ObjectExpression) {
263
+ processUnitlessValueInStyleObject(ruleContext, property.value, options);
264
+ }
265
+ return;
266
+ }
267
+ // Check for unitless numeric literal values (e.g., width: 100)
268
+ if (property.value.type === AST_NODE_TYPES.Literal && typeof property.value.value === 'number') {
269
+ // Allow 0 without units (valid CSS), including -0
270
+ if (property.value.value === 0 || property.value.value === -0) {
271
+ return;
272
+ }
273
+ // Report unitless numeric value
274
+ ruleContext.report({
275
+ node: property.value,
276
+ messageId: 'noUnitlessValue',
277
+ data: {
278
+ property: propertyName,
279
+ value: String(property.value.value),
280
+ },
281
+ });
282
+ }
283
+ // Check for string literals that are unitless numbers (e.g., width: '100')
284
+ if (property.value.type === AST_NODE_TYPES.Literal && typeof property.value.value === 'string') {
285
+ const stringValue = property.value.value.trim();
286
+ // Check if the string is a pure number (with optional negative sign and decimals)
287
+ // This regex matches: -10, 10, 10.5, -10.5, but not 10px, 10rem, etc.
288
+ const unitlessNumberRegex = /^-?\d+(\.\d+)?$/;
289
+ if (unitlessNumberRegex.test(stringValue)) {
290
+ // Allow '0' and '-0' without units
291
+ const numValue = parseFloat(stringValue);
292
+ if (numValue === 0 || numValue === -0) {
293
+ return;
294
+ }
295
+ // Report unitless string numeric value
296
+ ruleContext.report({
297
+ node: property.value,
298
+ messageId: 'noUnitlessValue',
299
+ data: {
300
+ property: propertyName,
301
+ value: stringValue,
302
+ },
303
+ });
304
+ }
305
+ }
306
+ // Check for unary expressions (e.g., -10)
307
+ if (property.value.type === AST_NODE_TYPES.UnaryExpression && property.value.operator === '-') {
308
+ if (property.value.argument.type === AST_NODE_TYPES.Literal &&
309
+ typeof property.value.argument.value === 'number') {
310
+ // Allow -0 without units
311
+ if (property.value.argument.value === 0) {
312
+ return;
313
+ }
314
+ // Report unitless numeric value
315
+ ruleContext.report({
316
+ node: property.value,
317
+ messageId: 'noUnitlessValue',
318
+ data: {
319
+ property: propertyName,
320
+ value: `-${property.value.argument.value}`,
321
+ },
322
+ });
323
+ }
324
+ }
325
+ // Process nested objects (for complex selectors, etc.)
326
+ if (property.value.type === AST_NODE_TYPES.ObjectExpression) {
327
+ processUnitlessValueInStyleObject(ruleContext, property.value, options);
328
+ }
329
+ });
330
+ };
@@ -0,0 +1,11 @@
1
+ import type { Rule } from 'eslint';
2
+ import type { NoUnitlessValuesOptions } from './unitless-value-processor.js';
3
+ /**
4
+ * Creates ESLint rule visitors for detecting unitless numeric values in style-related function calls.
5
+ * Uses reference tracking to automatically detect vanilla-extract functions based on their import statements.
6
+ *
7
+ * @param context The ESLint rule context.
8
+ * @param options Rule options including allowed property names.
9
+ * @returns An object with visitor functions for the ESLint rule.
10
+ */
11
+ export declare const createUnitlessValueVisitors: (context: Rule.RuleContext, options?: NoUnitlessValuesOptions) => Rule.RuleListener;
@@ -0,0 +1,68 @@
1
+ import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';
2
+ import { processRecipeProperties } from '../shared-utils/recipe-property-processor.js';
3
+ import { ReferenceTracker, createReferenceTrackingVisitor } from '../shared-utils/reference-tracker.js';
4
+ import { processStyleNode } from '../shared-utils/style-node-processor.js';
5
+ import { processUnitlessValueInStyleObject } from './unitless-value-processor.js';
6
+ /**
7
+ * Creates ESLint rule visitors for detecting unitless numeric values in style-related function calls.
8
+ * Uses reference tracking to automatically detect vanilla-extract functions based on their import statements.
9
+ *
10
+ * @param context The ESLint rule context.
11
+ * @param options Rule options including allowed property names.
12
+ * @returns An object with visitor functions for the ESLint rule.
13
+ */
14
+ export const createUnitlessValueVisitors = (context, options = {}) => {
15
+ const tracker = new ReferenceTracker();
16
+ const trackingVisitor = createReferenceTrackingVisitor(tracker);
17
+ const processWithOptions = (ruleContext, node) => {
18
+ processUnitlessValueInStyleObject(ruleContext, node, options);
19
+ };
20
+ return {
21
+ ...trackingVisitor,
22
+ CallExpression(node) {
23
+ if (node.callee.type !== AST_NODE_TYPES.Identifier) {
24
+ return;
25
+ }
26
+ const functionName = node.callee.name;
27
+ // Check if this function is tracked as a vanilla-extract function
28
+ if (!tracker.isTrackedFunction(functionName)) {
29
+ return;
30
+ }
31
+ const originalName = tracker.getOriginalName(functionName);
32
+ if (!originalName) {
33
+ return;
34
+ }
35
+ // Handle different function types based on their original imported name
36
+ switch (originalName) {
37
+ case 'fontFace':
38
+ if (node.arguments.length > 0 && node.arguments[0]?.type === AST_NODE_TYPES.ObjectExpression) {
39
+ processWithOptions(context, node.arguments[0]);
40
+ }
41
+ break;
42
+ case 'globalFontFace':
43
+ if (node.arguments.length > 1 && node.arguments[1]?.type === AST_NODE_TYPES.ObjectExpression) {
44
+ processWithOptions(context, node.arguments[1]);
45
+ }
46
+ break;
47
+ case 'style':
48
+ case 'styleVariants':
49
+ case 'keyframes':
50
+ if (node.arguments.length > 0) {
51
+ processStyleNode(context, node.arguments[0], processWithOptions);
52
+ }
53
+ break;
54
+ case 'globalStyle':
55
+ case 'globalKeyframes':
56
+ if (node.arguments.length >= 2) {
57
+ processStyleNode(context, node.arguments[1], processWithOptions);
58
+ }
59
+ break;
60
+ case 'recipe':
61
+ if (node.arguments.length > 0 && node.arguments[0]?.type === AST_NODE_TYPES.ObjectExpression) {
62
+ processRecipeProperties(context, node.arguments[0], processWithOptions);
63
+ }
64
+ break;
65
+ }
66
+ },
67
+ };
68
+ };
@@ -19,7 +19,8 @@ import { processStyleNode } from './style-node-processor.js';
19
19
  * @returns An object with visitor functions for the ESLint rule.
20
20
  */
21
21
  export const createNodeVisitors = (ruleContext, orderingStrategy, userDefinedGroupOrder, sortRemainingProperties) => {
22
- const tracker = new ReferenceTracker();
22
+ const wrapperSettings = resolveWrapperSettings(ruleContext);
23
+ const tracker = new ReferenceTracker(wrapperSettings);
23
24
  const trackingVisitor = createReferenceTrackingVisitor(tracker);
24
25
  return {
25
26
  // Include the import/variable tracking visitors
@@ -64,6 +65,14 @@ export const createNodeVisitors = (ruleContext, orderingStrategy, userDefinedGro
64
65
  },
65
66
  };
66
67
  };
68
+ const resolveWrapperSettings = (ruleContext) => {
69
+ const pluginSettings = (ruleContext.settings?.['vanilla-extract'] ??
70
+ {});
71
+ return {
72
+ style: pluginSettings.style ?? [],
73
+ recipe: pluginSettings.recipe ?? [],
74
+ };
75
+ };
67
76
  /**
68
77
  * Helper function to process style ordering for style-related functions
69
78
  */
@@ -7,10 +7,11 @@ import { TSESTree } from '@typescript-eslint/utils';
7
7
  * @param processProperty A callback function to process each property object (e.g., for alphabetical or concentric ordering).
8
8
  *
9
9
  * This function iterates through the properties of the recipe object:
10
- * - For the `base` property, it directly processes the object.
11
- * - For the `variants` property, it processes each variant's options individually.
10
+ * - For the `base` property, it processes object or array style nodes.
11
+ * - For the `variants` property, it processes each variant option as object or array style nodes.
12
12
  *
13
13
  * The function skips any non-Property nodes or nodes without an Identifier key.
14
- * It only processes ObjectExpression values to ensure type safety.
14
+ * It delegates node handling to `processStyleNode`, which safely supports
15
+ * ObjectExpression and ArrayExpression values.
15
16
  */
16
17
  export declare const processRecipeProperties: (ruleContext: Rule.RuleContext, recipeNode: TSESTree.ObjectExpression, processProperty: (ruleContext: Rule.RuleContext, value: TSESTree.ObjectExpression) => void) => void;
@@ -1,4 +1,5 @@
1
1
  import { TSESTree } from '@typescript-eslint/utils';
2
+ import { processStyleNode } from './style-node-processor.js';
2
3
  /**
3
4
  * Processes the `base` and `variants` properties of a recipe object.
4
5
  * @param ruleContext The ESLint rule context.
@@ -6,11 +7,12 @@ import { TSESTree } from '@typescript-eslint/utils';
6
7
  * @param processProperty A callback function to process each property object (e.g., for alphabetical or concentric ordering).
7
8
  *
8
9
  * This function iterates through the properties of the recipe object:
9
- * - For the `base` property, it directly processes the object.
10
- * - For the `variants` property, it processes each variant's options individually.
10
+ * - For the `base` property, it processes object or array style nodes.
11
+ * - For the `variants` property, it processes each variant option as object or array style nodes.
11
12
  *
12
13
  * The function skips any non-Property nodes or nodes without an Identifier key.
13
- * It only processes ObjectExpression values to ensure type safety.
14
+ * It delegates node handling to `processStyleNode`, which safely supports
15
+ * ObjectExpression and ArrayExpression values.
14
16
  */
15
17
  export const processRecipeProperties = (ruleContext, recipeNode, processProperty) => {
16
18
  recipeNode.properties.forEach((property) => {
@@ -18,16 +20,16 @@ export const processRecipeProperties = (ruleContext, recipeNode, processProperty
18
20
  return; // Skip non-property nodes or nodes without an identifier key
19
21
  }
20
22
  // Process the `base` property
21
- if (property.key.name === 'base' && property.value.type === 'ObjectExpression') {
22
- processProperty(ruleContext, property.value);
23
+ if (property.key.name === 'base') {
24
+ processStyleNode(ruleContext, property.value, processProperty);
23
25
  }
24
26
  // Process the `variants` property
25
27
  if (property.key.name === 'variants' && property.value.type === 'ObjectExpression') {
26
28
  property.value.properties.forEach((variantProperty) => {
27
29
  if (variantProperty.type === 'Property' && variantProperty.value.type === 'ObjectExpression') {
28
30
  variantProperty.value.properties.forEach((optionProperty) => {
29
- if (optionProperty.type === 'Property' && optionProperty.value.type === 'ObjectExpression') {
30
- processProperty(ruleContext, optionProperty.value);
31
+ if (optionProperty.type === 'Property') {
32
+ processStyleNode(ruleContext, optionProperty.value, processProperty);
31
33
  }
32
34
  });
33
35
  }
@@ -23,7 +23,12 @@ export declare class ReferenceTracker {
23
23
  private imports;
24
24
  private trackedFunctions;
25
25
  private wrapperFunctions;
26
- constructor();
26
+ private style;
27
+ private recipe;
28
+ constructor(options?: {
29
+ style?: string[];
30
+ recipe?: string[];
31
+ });
27
32
  /**
28
33
  * Processes import declarations to track vanilla-extract functions
29
34
  */
@@ -77,6 +82,7 @@ export declare class ReferenceTracker {
77
82
  */
78
83
  reset(): void;
79
84
  private isVanillaExtractSource;
85
+ private getCustomWrapper;
80
86
  private categorizeFunction;
81
87
  }
82
88
  /**
@@ -3,7 +3,7 @@ import { TSESTree } from '@typescript-eslint/utils';
3
3
  * Tracks vanilla-extract function imports and their local bindings
4
4
  */
5
5
  export class ReferenceTracker {
6
- constructor() {
6
+ constructor(options) {
7
7
  this.imports = new Map();
8
8
  this.wrapperFunctions = new Map(); // wrapper function name -> detailed info
9
9
  this.trackedFunctions = {
@@ -13,27 +13,40 @@ export class ReferenceTracker {
13
13
  globalFunctions: new Set(),
14
14
  keyframeFunctions: new Set(),
15
15
  };
16
+ this.style = new Set(options?.style ?? []);
17
+ this.recipe = new Set(options?.recipe ?? []);
16
18
  }
17
19
  /**
18
20
  * Processes import declarations to track vanilla-extract functions
19
21
  */
20
22
  processImportDeclaration(node) {
21
23
  const source = node.source.value;
22
- // Check if this is a vanilla-extract import
23
- if (typeof source !== 'string' || !this.isVanillaExtractSource(source)) {
24
+ if (typeof source !== 'string') {
24
25
  return;
25
26
  }
27
+ const isVanillaExtractImport = this.isVanillaExtractSource(source);
26
28
  node.specifiers.forEach((specifier) => {
27
29
  if (specifier.type === 'ImportSpecifier') {
28
30
  const importedName = specifier.imported.type === 'Identifier' ? specifier.imported.name : specifier.imported.value;
29
31
  const localName = specifier.local.name;
32
+ const customWrapper = this.getCustomWrapper(importedName, localName);
33
+ let trackedImportName;
34
+ if (isVanillaExtractImport) {
35
+ trackedImportName = importedName;
36
+ }
37
+ else {
38
+ if (!customWrapper) {
39
+ return;
40
+ }
41
+ trackedImportName = customWrapper;
42
+ }
30
43
  const reference = {
31
44
  source,
32
- importedName,
45
+ importedName: trackedImportName,
33
46
  localName,
34
47
  };
35
48
  this.imports.set(localName, reference);
36
- this.categorizeFunction(localName, importedName);
49
+ this.categorizeFunction(localName, trackedImportName);
37
50
  }
38
51
  });
39
52
  }
@@ -219,6 +232,15 @@ export class ReferenceTracker {
219
232
  source === '@vanilla-extract/recipes' ||
220
233
  source.startsWith('@vanilla-extract/'));
221
234
  }
235
+ getCustomWrapper(importedName, localName) {
236
+ if (this.style.has(importedName) || this.style.has(localName)) {
237
+ return 'style';
238
+ }
239
+ if (this.recipe.has(importedName) || this.recipe.has(localName)) {
240
+ return 'recipe';
241
+ }
242
+ return null;
243
+ }
222
244
  categorizeFunction(localName, importedName) {
223
245
  switch (importedName) {
224
246
  case 'style':
@@ -1 +1,5 @@
1
1
  export type OrderingStrategy = 'alphabetical' | 'concentric' | 'userDefinedGroupOrder';
2
+ export interface VanillaExtractPluginSettings {
3
+ style?: string[];
4
+ recipe?: string[];
5
+ }
package/dist/index.d.ts CHANGED
@@ -10,6 +10,7 @@ declare const vanillaExtract: {
10
10
  'no-empty-style-blocks': import("eslint").Rule.RuleModule;
11
11
  'no-px-unit': import("eslint").Rule.RuleModule;
12
12
  'no-trailing-zero': import("eslint").Rule.RuleModule;
13
+ 'no-unitless-values': import("eslint").Rule.RuleModule;
13
14
  'no-unknown-unit': import("eslint").Rule.RuleModule;
14
15
  'no-zero-unit': import("eslint").Rule.RuleModule;
15
16
  'prefer-logical-properties': import("eslint").Rule.RuleModule;