@antebudimir/eslint-plugin-vanilla-extract 1.9.0 → 1.10.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
@@ -1,8 +1,15 @@
1
1
  # @antebudimir/eslint-plugin-vanilla-extract
2
2
 
3
- [![CI](https://github.com/antebudimir/eslint-plugin-vanilla-extract/actions/workflows/ci.yml/badge.svg)](https://github.com/antebudimir/eslint-plugin-vanilla-extract/actions/workflows/ci.yml) [![Coverage Status](https://coveralls.io/repos/github/antebudimir/eslint-plugin-vanilla-extract/badge.svg?branch=main)](https://coveralls.io/github/antebudimir/eslint-plugin-vanilla-extract?branch=main) [![npm version](https://img.shields.io/npm/v/@antebudimir/eslint-plugin-vanilla-extract.svg)](https://www.npmjs.com/package/@antebudimir/eslint-plugin-vanilla-extract) ![NPM Downloads](https://img.shields.io/npm/d18m/%40antebudimir%2Feslint-plugin-vanilla-extract)
3
+ [![CI](https://github.com/antebudimir/eslint-plugin-vanilla-extract/actions/workflows/ci.yml/badge.svg)](https://github.com/antebudimir/eslint-plugin-vanilla-extract/actions/workflows/ci.yml)
4
+ [![Coverage Status](https://coveralls.io/repos/github/antebudimir/eslint-plugin-vanilla-extract/badge.svg?branch=main)](https://coveralls.io/github/antebudimir/eslint-plugin-vanilla-extract?branch=main)
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
+ ![NPM Downloads](https://img.shields.io/npm/d18m/%40antebudimir%2Feslint-plugin-vanilla-extract)
4
7
 
5
- An ESLint plugin for enforcing best practices in [vanilla-extract](https://github.com/vanilla-extract-css/vanilla-extract) CSS styles, including CSS property ordering and additional linting rules. Available presets are for alphabetical and [concentric](https://rhodesmill.org/brandon/2011/concentric-css/) CSS ordering. The plugin also supports a custom group ordering option based on groups available in [concentric CSS](src/css-rules/concentric-order/concentric-groups.ts).
8
+ An ESLint plugin for enforcing best practices in
9
+ [vanilla-extract](https://github.com/vanilla-extract-css/vanilla-extract) CSS styles, including CSS property ordering
10
+ and additional linting rules. Available presets are for alphabetical and
11
+ [concentric](https://rhodesmill.org/brandon/2011/concentric-css/) CSS ordering. The plugin also supports a custom group
12
+ ordering option based on groups available in [concentric CSS](src/css-rules/concentric-order/concentric-groups.ts).
6
13
 
7
14
  ## Demo
8
15
 
@@ -14,7 +21,7 @@ An ESLint plugin for enforcing best practices in [vanilla-extract](https://githu
14
21
  - Alphabetical ordering for clean, predictable style organization
15
22
  - Concentric ordering for logical, outside-in property arrangement
16
23
  - Custom group ordering option for more fine-grained control
17
- - Built for ESLint 9 flat config system
24
+ - Compatible with ESLint 8.57.0+ and fully optimized for ESLint 9's flat config system
18
25
  - Provides auto-fix capability to automatically sort properties
19
26
  - Handles multiple vanilla-extract APIs (style, styleVariants, recipe, globalStyle, etc.)
20
27
  - Handles complex cases like nested objects, arrays of styles, and pseudo selectors
@@ -23,9 +30,12 @@ An ESLint plugin for enforcing best practices in [vanilla-extract](https://githu
23
30
 
24
31
  ## Requirements
25
32
 
26
- - ESLint 9.0.0 or higher
33
+ - ESLint 8.57.0 or higher
27
34
  - Node.js 18.18.0 or higher
28
35
  - ESM (ECMAScript Modules) only
36
+ - Flat config system using either:
37
+ - `eslint.config.mjs` (recommended, always works with ESM plugins)
38
+ - `eslint.config.js` (only if your package.json has `"type": "module"`)
29
39
 
30
40
  ## Installation
31
41
 
@@ -38,21 +48,47 @@ yarn add --dev @antebudimir/eslint-plugin-vanilla-extract
38
48
 
39
49
  # Using pnpm
40
50
  pnpm add -D @antebudimir/eslint-plugin-vanilla-extract
51
+
52
+ # For ESLint 8.57.0 with flat config, you'll also need:
53
+ npm install --save-dev @eslint/eslintrc @eslint/js
54
+ yarn add --dev @eslint/eslintrc @eslint/js
55
+ pnpm add -D @eslint/eslintrc @eslint/js
41
56
  ```
42
57
 
43
58
  ## Usage
44
59
 
45
60
  **Note: This plugin is ESM-only.** It must be used with ESM configurations and can't be used with CommonJS `require()`.
46
61
 
47
- ### ESLint Flat Config (ESLint 9+)
62
+ ### Configuration Options
63
+
64
+ There are two main ways to configure this plugin in your ESLint flat config:
48
65
 
49
- Create or update your `eslint.config.js` or `eslint.config.mjs` file:
66
+ ### Option 1: Using extends (recommended, available from v1.10.0)
67
+
68
+ The simplest way to apply the recommended ruleset:
50
69
 
51
70
  ```typescript
71
+ import { defineConfig } from 'eslint/config';
52
72
  import vanillaExtract from '@antebudimir/eslint-plugin-vanilla-extract';
53
73
 
54
- // Using the recommended configuration
55
- export default [
74
+ export default defineConfig([
75
+ {
76
+ files: ['**/*.css.ts'],
77
+ ignores: ['src/**/theme-contract.css.ts'],
78
+ extends: [vanillaExtract.configs.recommended],
79
+ },
80
+ ];
81
+ ```
82
+
83
+ ### Option 2: Using plugins with explicit rule configuration
84
+
85
+ This approach gives you more control over individual rules:
86
+
87
+ ```typescript
88
+ import { defineConfig } from 'eslint/config';
89
+ import vanillaExtract from '@antebudimir/eslint-plugin-vanilla-extract';
90
+
91
+ export default defineConfig([
56
92
  {
57
93
  files: ['**/*.css.ts'],
58
94
  ignores: ['src/**/theme-contract.css.ts'],
@@ -62,12 +98,12 @@ export default [
62
98
  rules: {
63
99
  // Apply all recommended rules
64
100
  ...vanillaExtract.configs.recommended.rules,
65
-
101
+
66
102
  // Optionally override specific rules
67
103
  // 'vanilla-extract/concentric-order': 'warn', // Change severity from error to warn
68
104
  // 'vanilla-extract/no-empty-style-blocks': 'off', // Disable a recommended rule
69
105
  // 'vanilla-extract/no-zero-unit': 'warn', // Change severity from error to warn
70
-
106
+
71
107
  // Add additional rules not in recommended config
72
108
  // 'vanilla-extract/alphabetical-order': 'error', // Override concentric-order rule
73
109
  },
@@ -75,6 +111,80 @@ export default [
75
111
  ];
76
112
  ```
77
113
 
114
+ ### Using with FlatCompat (for ESLint 8.57.0 & 8.57.1)
115
+
116
+ If you're migrating from legacy ESLint configurations, you can use the `FlatCompat` utility to convert them while adding
117
+ vanilla-extract support:
118
+
119
+ ```typescript
120
+ import path from 'path';
121
+ import { fileURLToPath } from 'url';
122
+ import { FlatCompat } from '@eslint/eslintrc';
123
+ import js from '@eslint/js';
124
+ import vanillaExtract from '@antebudimir/eslint-plugin-vanilla-extract';
125
+
126
+ // Mimic CommonJS variables
127
+ const __filename = fileURLToPath(import.meta.url);
128
+ const __dirname = path.dirname(__filename);
129
+
130
+ // Create a compatibility layer instance
131
+ const compat = new FlatCompat({
132
+ baseDirectory: __dirname,
133
+ recommendedConfig: js.configs.recommended,
134
+ });
135
+
136
+ export default [
137
+ // Convert your existing ESLint configs
138
+ ...compat.config({
139
+ extends: [
140
+ 'eslint:recommended',
141
+ 'plugin:@typescript-eslint/recommended',
142
+ // etc
143
+ ],
144
+ }),
145
+
146
+ // Add vanilla-extract by using explicit rule config
147
+ {
148
+ files: ['**/*.css.ts'],
149
+ ignores: ['src/**/theme-contract.css.ts'],
150
+ plugins: {
151
+ 'vanilla-extract': vanillaExtract,
152
+ },
153
+ rules: {
154
+ // Apply all recommended rules
155
+ ...vanillaExtract.configs.recommended.rules,
156
+ // or specify rule by rule as described above
157
+ },
158
+ },
159
+ ];
160
+ ```
161
+
162
+ #### Common Issues with FlatCompat
163
+
164
+ 1. **Error: "Unexpected top-level property 'files'"**
165
+
166
+ - Solution: When using `compat.config()`, use `overrides` instead of `files` at the top level.
167
+
168
+ 2. **Error: "Missing parameter 'recommendedConfig' in FlatCompat constructor"**
169
+
170
+ - Solution: Import `js` from `@eslint/js` and add `recommendedConfig: js.configs.recommended` to the FlatCompat
171
+ constructor.
172
+
173
+ 3. **Error: "Unexpected undefined config at user-defined index 0"**
174
+ - Solution: Make sure you're using a default export for your configuration array.
175
+
176
+ ### VS Code Integration
177
+
178
+ For VS Code users, add these settings to your `.vscode/settings.json`:
179
+
180
+ ```json
181
+ {
182
+ "eslint.useFlatConfig": true,
183
+ "eslint.experimental.useFlatConfig": true,
184
+ "eslint.validate": ["javascript", "typescript", "typescriptreact"]
185
+ }
186
+ ```
187
+
78
188
  ### Recommended Configuration
79
189
 
80
190
  The recommended configuration enables the following rules with error severity:
@@ -181,20 +291,27 @@ export const myStyle = style({
181
291
 
182
292
  ### vanilla-extract/custom-order
183
293
 
184
- The `vanilla-extract/custom-order` rule enables you to enforce a custom ordering of CSS properties in your vanilla-extract styles. You can specify an array of property groups in your preferred order, and the rule will ensure that properties within these groups are sorted according to their position in the concentric CSS model.
294
+ The `vanilla-extract/custom-order` rule enables you to enforce a custom ordering of CSS properties in your
295
+ vanilla-extract styles. You can specify an array of property groups in your preferred order, and the rule will ensure
296
+ that properties within these groups are sorted according to their position in the concentric CSS model.
185
297
 
186
298
  Key features of this rule include:
187
299
 
188
300
  1. Custom group ordering: Define your preferred order of CSS property groups.
189
- 2. Handling of unspecified groups: All groups not included in the custom array will have their properties sorted after the last specified group.
190
- 3. Flexible sorting options: You can choose to sort remaining properties either alphabetically or following the concentric CSS order by setting the `sortRemainingProperties` option to 'alphabetical' or 'concentric' respectively.
301
+ 2. Handling of unspecified groups: All groups not included in the custom array will have their properties sorted after
302
+ the last specified group.
303
+ 3. Flexible sorting options: You can choose to sort remaining properties either alphabetically or following the
304
+ concentric CSS order by setting the `sortRemainingProperties` option to 'alphabetical' or 'concentric' respectively.
191
305
 
192
306
  Default behavior:
193
307
 
194
308
  - If not set, `sortRemainingProperties` defaults to 'alphabetical'.
195
- - If no `groupOrder` is specified or an empty array is provided, the rule will default to sorting all properties alphabetically, and `sortRemainingProperties` will be ignored even if set.
309
+ - If no `groupOrder` is specified or an empty array is provided, the rule will default to sorting all properties
310
+ alphabetically, and `sortRemainingProperties` will be ignored even if set.
196
311
 
197
- To configure the rule, add it to your ESLint configuration file with your desired options. You can customize the `groups` array to include any number of available CSS property groups you want to enforce, with a minimum of one group required.
312
+ To configure the rule, add it to your ESLint configuration file with your desired options. You can customize the
313
+ `groups` array to include any number of available CSS property groups you want to enforce, with a minimum of one group
314
+ required.
198
315
 
199
316
  ```typescript
200
317
  // ❌ Incorrect (Unordered)
@@ -237,7 +354,8 @@ export const myStyle = style({
237
354
 
238
355
  ### vanilla-extract/no-empty-style-blocks
239
356
 
240
- This rule detects and prevents empty style blocks in vanilla-extract stylesheets. It helps maintain cleaner codebases by eliminating empty style definitions that often result from incomplete refactoring or forgotten implementations.
357
+ This rule detects and prevents empty style blocks in vanilla-extract stylesheets. It helps maintain cleaner codebases by
358
+ eliminating empty style definitions that often result from incomplete refactoring or forgotten implementations.
241
359
 
242
360
  ```typescript
243
361
  // ❌ Incorrect
@@ -273,23 +391,24 @@ export const recipeWithEmptyVariants = recipe({
273
391
 
274
392
  ## vanilla-extract/no-unknown-unit
275
393
 
276
- This rule enforces the use of valid CSS units in vanilla-extract style objects. It prevents typos and non-standard units that could cause styling issues or browser compatibility problems.
394
+ This rule enforces the use of valid CSS units in vanilla-extract style objects. It prevents typos and non-standard units
395
+ that could cause styling issues or browser compatibility problems.
277
396
 
278
397
  ```typescript
279
398
  // ❌ Incorrect
280
399
  import { style, globalStyle, recipe } from '@vanilla-extract/css';
281
400
 
282
401
  export const invalidStyle = style({
283
- margin: '5abc', // Non-existent unit
402
+ margin: '5abc', // Non-existent unit
284
403
  fontSize: '1.5rems', // Typo in unit
285
404
  });
286
405
 
287
406
  export const myRecipe = recipe({
288
407
  variants: {
289
408
  size: {
290
- large: { padding: '4xm' } // Invalid unit
291
- }
292
- }
409
+ large: { padding: '4xm' }, // Invalid unit
410
+ },
411
+ },
293
412
  });
294
413
 
295
414
  // ✅ Correct
@@ -303,15 +422,16 @@ export const validStyle = style({
303
422
  export const myRecipe = recipe({
304
423
  variants: {
305
424
  size: {
306
- large: { padding: '4em' }
307
- }
308
- }
425
+ large: { padding: '4em' },
426
+ },
427
+ },
309
428
  });
310
429
  ```
311
430
 
312
431
  ## vanilla-extract/no-zero-unit
313
432
 
314
- This rule enforces the removal of unnecessary units for zero values in vanilla-extract style objects. It helps maintain cleaner and more consistent CSS by eliminating redundant units when the value is zero.
433
+ This rule enforces the removal of unnecessary units for zero values in vanilla-extract style objects. It helps maintain
434
+ cleaner and more consistent CSS by eliminating redundant units when the value is zero.
315
435
 
316
436
  ```typescript
317
437
  // ❌ Incorrect
@@ -339,7 +459,8 @@ export const myStyle = style({
339
459
 
340
460
  ## Font Face Declarations
341
461
 
342
- For `fontFace` and `globalFontFace` API calls, all three ordering rules (alphabetical, concentric, and custom) enforce the same special ordering:
462
+ For `fontFace` and `globalFontFace` API calls, all three ordering rules (alphabetical, concentric, and custom) enforce
463
+ the same special ordering:
343
464
 
344
465
  1. The `src` property always appears first
345
466
  2. All remaining properties are sorted alphabetically
@@ -367,7 +488,8 @@ Opinionated, but it is what it is. If someone has a suggestion for a better orde
367
488
 
368
489
  ## Concentric CSS Model
369
490
 
370
- Here's a list of all available groups from the provided [concentricGroups](src/css-rules/concentric-order/concentric-groups.ts) array:
491
+ Here's a list of all available groups from the provided
492
+ [concentricGroups](src/css-rules/concentric-order/concentric-groups.ts) array:
371
493
 
372
494
  1. boxSizing
373
495
  2. position
@@ -399,7 +521,8 @@ Here's a list of all available groups from the provided [concentricGroups](src/c
399
521
  28. counters
400
522
  29. breaks
401
523
 
402
- These groups represent different categories of CSS properties, organized in a concentric order from outside to inside. Each group contains related CSS properties that affect specific aspects of an element's styling and layout.
524
+ These groups represent different categories of CSS properties, organized in a concentric order from outside to inside.
525
+ Each group contains related CSS properties that affect specific aspects of an element's styling and layout.
403
526
 
404
527
  ## Roadmap
405
528
 
@@ -418,7 +541,8 @@ The roadmap outlines the project's current status and future plans:
418
541
 
419
542
  ### Current Work
420
543
 
421
- - Support for using the plugin’s recommended config via the extends field (as discussed in [issue #3](https://github.com/antebudimir/eslint-plugin-vanilla-extract/issues/3))
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))
422
546
 
423
547
  ### Upcoming Features
424
548
 
@@ -427,8 +551,10 @@ The roadmap outlines the project's current status and future plans:
427
551
  - `prefer-logical-properties` rule to enforce use of logical properties.
428
552
  - `prefer-theme-tokens` rule to enforce use of theme tokens instead of hard-coded values when available.
429
553
  - `no-global-style` rule to disallow use of `globalStyle` function.
430
- - `property-unit-match` rule to enforce valid units per CSS property specs. **Note**: This feature will only be implemented if there's sufficient interest from the community.
431
- - Option to sort properties within user-defined concentric groups alphabetically instead of following the concentric order. **Note**: This feature will only be implemented if there's sufficient interest from the community.
554
+ - `property-unit-match` rule to enforce valid units per CSS property specs. **Note**: This feature will only be
555
+ implemented if there's sufficient interest from the community.
556
+ - Option to sort properties within user-defined concentric groups alphabetically instead of following the concentric
557
+ order. **Note**: This feature will only be implemented if there's sufficient interest from the community.
432
558
 
433
559
  ## Contributing
434
560
 
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const vanillaExtract: {
1
+ declare const vanillaExtract: {
2
2
  meta: {
3
3
  name: string;
4
4
  version: string;
@@ -11,16 +11,6 @@ export declare const vanillaExtract: {
11
11
  'no-unknown-unit': import("eslint").Rule.RuleModule;
12
12
  'no-zero-unit': import("eslint").Rule.RuleModule;
13
13
  };
14
- configs: {
15
- recommended: {
16
- plugins: string[];
17
- rules: {
18
- 'vanilla-extract/concentric-order': string;
19
- 'vanilla-extract/no-empty-style-blocks': string;
20
- 'vanilla-extract/no-unknown-unit': string;
21
- 'vanilla-extract/no-zero-unit': string;
22
- };
23
- };
24
- };
14
+ configs: {};
25
15
  };
26
16
  export default vanillaExtract;
package/dist/index.js CHANGED
@@ -4,10 +4,10 @@ import customOrderRule from './css-rules/custom-order/rule-definition.js';
4
4
  import noEmptyStyleBlocksRule from './css-rules/no-empty-blocks/rule-definition.js';
5
5
  import noUnknownUnitRule from './css-rules/no-unknown-unit/rule-definition.js';
6
6
  import noZeroUnitRule from './css-rules/no-zero-unit/rule-definition.js';
7
- export const vanillaExtract = {
7
+ const vanillaExtract = {
8
8
  meta: {
9
9
  name: '@antebudimir/eslint-plugin-vanilla-extract',
10
- version: '1.9.0',
10
+ version: '1.10.0',
11
11
  },
12
12
  rules: {
13
13
  'alphabetical-order': alphabeticalOrderRule,
@@ -17,16 +17,19 @@ export const vanillaExtract = {
17
17
  'no-unknown-unit': noUnknownUnitRule,
18
18
  'no-zero-unit': noZeroUnitRule,
19
19
  },
20
- configs: {
21
- recommended: {
22
- plugins: ['vanilla-extract'],
23
- rules: {
24
- 'vanilla-extract/concentric-order': 'error',
25
- 'vanilla-extract/no-empty-style-blocks': 'error',
26
- 'vanilla-extract/no-unknown-unit': 'error',
27
- 'vanilla-extract/no-zero-unit': 'error',
28
- },
20
+ configs: {},
21
+ };
22
+ Object.assign(vanillaExtract.configs, {
23
+ recommended: {
24
+ plugins: {
25
+ 'vanilla-extract': vanillaExtract,
26
+ },
27
+ rules: {
28
+ 'vanilla-extract/concentric-order': 'error',
29
+ 'vanilla-extract/no-empty-style-blocks': 'error',
30
+ 'vanilla-extract/no-unknown-unit': 'error',
31
+ 'vanilla-extract/no-zero-unit': 'error',
29
32
  },
30
33
  },
31
- };
34
+ });
32
35
  export default vanillaExtract;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antebudimir/eslint-plugin-vanilla-extract",
3
- "version": "1.9.0",
3
+ "version": "1.10.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",
@@ -45,7 +45,7 @@
45
45
  "node": ">=18.18.0"
46
46
  },
47
47
  "peerDependencies": {
48
- "eslint": ">=9.0.0"
48
+ "eslint": ">=8.57.0"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@eslint/eslintrc": "^3.3.0",