@antebudimir/eslint-plugin-vanilla-extract 1.16.0 → 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.
package/README.md CHANGED
@@ -304,6 +304,36 @@ export default [
304
304
 
305
305
  > **Note:** Remember to enable only one ordering rule at a time. See the "Important" section above for details on switching between ordering rules.
306
306
 
307
+ ### Global Settings (Recommended for shared wrappers)
308
+
309
+ If you use imported wrapper functions across multiple ordering rules, configure them once in ESLint `settings`.
310
+ All ordering rules (`alphabetical-order`, `concentric-order`, `custom-order`) read this value.
311
+
312
+ ```typescript
313
+ import { defineConfig } from 'eslint/config';
314
+ import vanillaExtract from '@antebudimir/eslint-plugin-vanilla-extract';
315
+
316
+ export default defineConfig([
317
+ {
318
+ files: ['**/*.css.ts'],
319
+ plugins: {
320
+ 'vanilla-extract': vanillaExtract,
321
+ },
322
+ settings: {
323
+ 'vanilla-extract': {
324
+ style: ['componentStyle', 'layerStyle'],
325
+ recipe: ['componentRecipe'],
326
+ },
327
+ },
328
+ rules: {
329
+ ...vanillaExtract.configs.recommended.rules,
330
+ },
331
+ },
332
+ ]);
333
+ ```
334
+
335
+ Configure wrapper names only via ESLint `settings` (`style`, `recipe`).
336
+
307
337
  ## Rules
308
338
 
309
339
  ### vanilla-extract/alphabetical-order
@@ -336,6 +366,32 @@ export const myStyle = style({
336
366
  });
337
367
  ```
338
368
 
369
+ #### Global setting: `settings['vanilla-extract'].style`
370
+
371
+ `vanilla-extract/alphabetical-order` reads wrapper names from global ESLint settings.
372
+
373
+ ```typescript
374
+ import { defineConfig } from 'eslint/config';
375
+ import vanillaExtract from '@antebudimir/eslint-plugin-vanilla-extract';
376
+
377
+ export default defineConfig([
378
+ {
379
+ files: ['**/*.css.ts'],
380
+ plugins: {
381
+ 'vanilla-extract': vanillaExtract,
382
+ },
383
+ settings: {
384
+ 'vanilla-extract': {
385
+ style: ['componentStyle'],
386
+ },
387
+ },
388
+ rules: {
389
+ 'vanilla-extract/alphabetical-order': 'error',
390
+ },
391
+ },
392
+ ]);
393
+ ```
394
+
339
395
  ### vanilla-extract/concentric-order
340
396
 
341
397
  This rule enforces that CSS properties in vanilla-extract style objects follow the [concentric CSS](#concentric-css-model) ordering pattern, which organizes properties from outside to inside.
@@ -364,6 +420,33 @@ export const myStyle = style({
364
420
  });
365
421
  ```
366
422
 
423
+ #### Global setting: `settings['vanilla-extract'].style`
424
+
425
+ Use this setting when style wrappers are imported from local modules (for example `componentStyle`, `layerStyle`).
426
+ If a wrapper function name is listed, the rule treats calls to that function like `style(...)` calls.
427
+
428
+ ```typescript
429
+ import { defineConfig } from 'eslint/config';
430
+ import vanillaExtract from '@antebudimir/eslint-plugin-vanilla-extract';
431
+
432
+ export default defineConfig([
433
+ {
434
+ files: ['**/*.css.ts'],
435
+ plugins: {
436
+ 'vanilla-extract': vanillaExtract,
437
+ },
438
+ settings: {
439
+ 'vanilla-extract': {
440
+ style: ['componentStyle', 'layerStyle'],
441
+ },
442
+ },
443
+ rules: {
444
+ 'vanilla-extract/concentric-order': 'error',
445
+ },
446
+ },
447
+ ]);
448
+ ```
449
+
367
450
  ### vanilla-extract/custom-order
368
451
 
369
452
  The `vanilla-extract/custom-order` rule enables you to enforce a custom ordering of CSS properties in your
@@ -388,6 +471,39 @@ To configure the rule, add it to your ESLint configuration file with your desire
388
471
  `groups` array to include any number of available CSS property groups you want to enforce, with a minimum of one group
389
472
  required.
390
473
 
474
+ #### Global setting: `settings['vanilla-extract'].style`
475
+
476
+ `vanilla-extract/custom-order` also reads `style` from global settings together with
477
+ `groupOrder` and `sortRemainingProperties`.
478
+
479
+ ```typescript
480
+ import { defineConfig } from 'eslint/config';
481
+ import vanillaExtract from '@antebudimir/eslint-plugin-vanilla-extract';
482
+
483
+ export default defineConfig([
484
+ {
485
+ files: ['**/*.css.ts'],
486
+ plugins: {
487
+ 'vanilla-extract': vanillaExtract,
488
+ },
489
+ settings: {
490
+ 'vanilla-extract': {
491
+ style: ['componentStyle'],
492
+ },
493
+ },
494
+ rules: {
495
+ 'vanilla-extract/custom-order': [
496
+ 'error',
497
+ {
498
+ groupOrder: ['font', 'dimensions', 'margin', 'padding', 'position', 'border'],
499
+ sortRemainingProperties: 'alphabetical',
500
+ },
501
+ ],
502
+ },
503
+ },
504
+ ]);
505
+ ```
506
+
391
507
  ```typescript
392
508
  // ❌ Incorrect (Unordered)
393
509
  import { style } from '@vanilla-extract/css';
@@ -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.js CHANGED
@@ -12,7 +12,7 @@ import preferThemeTokensRule from './css-rules/prefer-theme-tokens/index.js';
12
12
  const vanillaExtract = {
13
13
  meta: {
14
14
  name: '@antebudimir/eslint-plugin-vanilla-extract',
15
- version: '1.16.0',
15
+ version: '1.17.0',
16
16
  },
17
17
  rules: {
18
18
  'alphabetical-order': alphabeticalOrderRule,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antebudimir/eslint-plugin-vanilla-extract",
3
- "version": "1.16.0",
3
+ "version": "1.17.0",
4
4
  "description": "Comprehensive ESLint plugin for vanilla-extract with CSS property ordering, style validation, and best practices enforcement. Supports alphabetical, concentric and custom CSS ordering, auto-fixing, and zero-runtime safety.",
5
5
  "author": "Ante Budimir",
6
6
  "license": "MIT",