@antebudimir/eslint-plugin-vanilla-extract 1.2.0 → 1.4.6

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.
Files changed (65) hide show
  1. package/README.md +46 -8
  2. package/dist/css-rules/alphabetical-order/__tests__/animation.test.d.ts +1 -0
  3. package/dist/css-rules/alphabetical-order/__tests__/animation.test.js +108 -0
  4. package/dist/css-rules/alphabetical-order/__tests__/font-face.test.d.ts +1 -0
  5. package/dist/css-rules/alphabetical-order/__tests__/font-face.test.js +138 -0
  6. package/dist/css-rules/alphabetical-order/__tests__/global.test.d.ts +1 -0
  7. package/dist/css-rules/alphabetical-order/__tests__/global.test.js +51 -0
  8. package/dist/css-rules/alphabetical-order/__tests__/recipe.test.d.ts +1 -0
  9. package/dist/css-rules/alphabetical-order/__tests__/recipe.test.js +91 -0
  10. package/dist/css-rules/alphabetical-order/__tests__/style.test.d.ts +1 -0
  11. package/dist/css-rules/alphabetical-order/__tests__/style.test.js +108 -0
  12. package/dist/css-rules/alphabetical-order/__tests__/variants.test.d.ts +1 -0
  13. package/dist/css-rules/alphabetical-order/__tests__/variants.test.js +63 -0
  14. package/dist/css-rules/alphabetical-order/property-order-enforcer.js +1 -11
  15. package/dist/css-rules/alphabetical-order/rule-definition.js +2 -1
  16. package/dist/css-rules/concentric-order/__tests__/animation.test.d.ts +1 -0
  17. package/dist/css-rules/concentric-order/__tests__/animation.test.js +69 -0
  18. package/dist/css-rules/concentric-order/__tests__/font-face.test.d.ts +1 -0
  19. package/dist/css-rules/concentric-order/__tests__/font-face.test.js +94 -0
  20. package/dist/css-rules/concentric-order/__tests__/global.test.d.ts +1 -0
  21. package/dist/css-rules/concentric-order/__tests__/global.test.js +57 -0
  22. package/dist/css-rules/concentric-order/__tests__/recipe.test.d.ts +1 -0
  23. package/dist/css-rules/concentric-order/__tests__/recipe.test.js +100 -0
  24. package/dist/css-rules/concentric-order/__tests__/style.test.d.ts +1 -0
  25. package/dist/css-rules/concentric-order/__tests__/style.test.js +126 -0
  26. package/dist/css-rules/concentric-order/__tests__/variants.test.d.ts +1 -0
  27. package/dist/css-rules/concentric-order/__tests__/variants.test.js +133 -0
  28. package/dist/css-rules/concentric-order/property-order-enforcer.js +2 -2
  29. package/dist/css-rules/concentric-order/rule-definition.js +3 -1
  30. package/dist/css-rules/custom-order/__tests__/animation.test.d.ts +1 -0
  31. package/dist/css-rules/custom-order/__tests__/animation.test.js +148 -0
  32. package/dist/css-rules/custom-order/__tests__/font-face.test.d.ts +1 -0
  33. package/dist/css-rules/custom-order/__tests__/font-face.test.js +124 -0
  34. package/dist/css-rules/custom-order/__tests__/global.test.d.ts +1 -0
  35. package/dist/css-rules/custom-order/__tests__/global.test.js +124 -0
  36. package/dist/css-rules/custom-order/__tests__/recipe.test.d.ts +1 -0
  37. package/dist/css-rules/custom-order/__tests__/recipe.test.js +208 -0
  38. package/dist/css-rules/custom-order/__tests__/style.test.d.ts +1 -0
  39. package/dist/css-rules/custom-order/__tests__/style.test.js +249 -0
  40. package/dist/css-rules/custom-order/__tests__/variants.test.d.ts +1 -0
  41. package/dist/css-rules/custom-order/__tests__/variants.test.js +184 -0
  42. package/dist/css-rules/custom-order/rule-definition.js +1 -0
  43. package/dist/css-rules/shared-utils/__tests__/css-property-priority-map.test.d.ts +1 -0
  44. package/dist/css-rules/shared-utils/__tests__/css-property-priority-map.test.js +37 -0
  45. package/dist/css-rules/shared-utils/__tests__/font-face-property-order-enforcer.test.d.ts +1 -0
  46. package/dist/css-rules/shared-utils/__tests__/font-face-property-order-enforcer.test.js +58 -0
  47. package/dist/css-rules/shared-utils/__tests__/order-strategy-visitor-creator.test.d.ts +1 -0
  48. package/dist/css-rules/shared-utils/__tests__/order-strategy-visitor-creator.test.js +125 -0
  49. package/dist/css-rules/shared-utils/__tests__/property-name-extractor.test.d.ts +1 -0
  50. package/dist/css-rules/shared-utils/__tests__/property-name-extractor.test.js +53 -0
  51. package/dist/css-rules/shared-utils/__tests__/recipe-property-processor.test.d.ts +1 -0
  52. package/dist/css-rules/shared-utils/__tests__/recipe-property-processor.test.js +116 -0
  53. package/dist/css-rules/shared-utils/__tests__/style-node-processor.test.d.ts +1 -0
  54. package/dist/css-rules/shared-utils/__tests__/style-node-processor.test.js +55 -0
  55. package/dist/css-rules/shared-utils/__tests__/test-property-name-rule.d.ts +3 -0
  56. package/dist/css-rules/shared-utils/__tests__/test-property-name-rule.js +30 -0
  57. package/dist/css-rules/shared-utils/alphabetical-property-comparator.d.ts +8 -0
  58. package/dist/css-rules/shared-utils/alphabetical-property-comparator.js +19 -0
  59. package/dist/css-rules/shared-utils/font-face-property-order-enforcer.d.ts +10 -0
  60. package/dist/css-rules/shared-utils/font-face-property-order-enforcer.js +39 -0
  61. package/dist/css-rules/shared-utils/order-strategy-visitor-creator.d.ts +4 -3
  62. package/dist/css-rules/shared-utils/order-strategy-visitor-creator.js +23 -8
  63. package/dist/css-rules/shared-utils/style-node-processor.js +2 -5
  64. package/dist/index.js +1 -1
  65. package/package.json +11 -6
package/README.md CHANGED
@@ -1,9 +1,12 @@
1
1
  # @antebudimir/eslint-plugin-vanilla-extract
2
2
 
3
- [![npm version](https://img.shields.io/npm/v/@antebudimir/eslint-plugin-vanilla-extract.svg)](https://www.npmjs.com/package/@antebudimir/eslint-plugin-vanilla-extract)
3
+ [![npm version](https://img.shields.io/npm/v/@antebudimir/eslint-plugin-vanilla-extract.svg)](https://www.npmjs.com/package/@antebudimir/eslint-plugin-vanilla-extract) [![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)
4
4
 
5
- An ESLint plugin for enforcing CSS ordering in [vanilla-extract](https://github.com/vanilla-extract-css/vanilla-extract) css styles. Available presets are for alphabetical and
6
- [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.
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).
6
+
7
+ ## Demo
8
+
9
+ ![Plugin Demo](https://github.com/user-attachments/assets/93ba118d-84df-4da0-ac68-fdb429e581d6)
7
10
 
8
11
  ## Features
9
12
 
@@ -16,6 +19,7 @@ An ESLint plugin for enforcing CSS ordering in [vanilla-extract](https://github.
16
19
  - Handles multiple vanilla-extract APIs (style, styleVariants, recipe, globalStyle, etc.)
17
20
  - Handles complex cases like nested objects, arrays of styles, and pseudo selectors
18
21
  - Works with camelCase properties as used in vanilla-extract
22
+ - Additional linting rules for enhanced code quality (see roadmap for upcoming features)
19
23
 
20
24
  ## Requirements
21
25
 
@@ -180,9 +184,37 @@ export const myStyle = style({
180
184
  });
181
185
  ```
182
186
 
187
+ ## Font Face Declarations
188
+
189
+ For `fontFace` and `globalFontFace` API calls, all three ordering rules (alphabetical, concentric, and custom) enforce the same special ordering:
190
+
191
+ 1. The `src` property always appears first
192
+ 2. All remaining properties are sorted alphabetically
193
+
194
+ This special handling is applied because:
195
+
196
+ - The `src` property is the most critical property in font face declarations
197
+ - Consistent ordering improves readability for these specific APIs
198
+ - Font-related properties are specialized and benefit from standardized ordering
199
+
200
+ ```typescript
201
+ // ✅ Correct ordering for font faces
202
+ export const theFont = fontFace({
203
+ src: ['url("/fonts/MyFont.woff2") format("woff2")', 'url("/fonts/MyFont.woff") format("woff")'],
204
+ ascentOverride: '90%',
205
+ descentOverride: '10%',
206
+ fontDisplay: 'swap',
207
+ fontFeatureSettings: '"liga" 1',
208
+ fontStretch: 'normal',
209
+ // ...other properties in alphabetical order
210
+ });
211
+ ```
212
+
213
+ Opinionated, but it is what it is. If someone has a suggestion for a better ordering, let me know!
214
+
183
215
  ## Concentric CSS Model
184
216
 
185
- Here's a list of all available groups from the provided concentricGroups array:
217
+ Here's a list of all available groups from the provided [concentricGroups](src/css-rules/concentric-order/concentric-groups.ts) array:
186
218
 
187
219
  1. boxSizing
188
220
  2. position
@@ -224,16 +256,22 @@ The roadmap outlines the project's current status and future plans:
224
256
 
225
257
  - Initial release with support for alphabetical, concentric, and custom group CSS ordering.
226
258
  - Auto-fix capability integrated into ESLint.
227
- - Support for multiple vanilla-extract APIs (e.g., `style`, `styleVariants`, `recipe`, `globalStyle` etc.).
259
+ - Support for multiple vanilla-extract APIs (e.g., `style`, `styleVariants`, `recipe`, `globalStyle`, `fontFace`, etc.).
260
+ - Rules tested.
228
261
 
229
262
  ### Current Work
230
263
 
231
- - Compatibility testing to determine if the plugin works with ESLint v8. **Note**: There are no plans to ensure compatibility if issues arise. Upcoming features will be prioritized.
264
+ - `no-empty-blocks` rule to disallow empty blocks.
232
265
 
233
266
  ### Upcoming Features
234
267
 
235
- - Begin work on test coverage.
236
- - Support for additional vanilla-extract APIs, including `fontFace`, `globalFontFace`.
268
+ - `no-unknown-units` rule to disallow unknown units.
269
+ - `no-number-trailing-zeros` rule to disallow trailing zeros in numbers.
270
+ - `no-zero-unit` rule to disallow units when the value is zero.
271
+ - `no-px-unit` rule to disallow use of `px` units with configurable whitelist.
272
+ - `prefer-logical-properties` rule to enforce use of logical properties.
273
+ - `prefer-theme-tokens` rule to enforce use of theme tokens instead of hard-coded values when available.
274
+ - `no-global-style` rule to disallow use of `globalStyle` function.
237
275
  - 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.
238
276
 
239
277
  ## Contributing
@@ -0,0 +1,108 @@
1
+ import tsParser from '@typescript-eslint/parser';
2
+ import { run } from 'eslint-vitest-rule-tester';
3
+ import alphabeticalOrderRule from '../rule-definition.js';
4
+ run({
5
+ name: 'vanilla-extract/alphabetical-order/animation',
6
+ rule: alphabeticalOrderRule,
7
+ languageOptions: {
8
+ parser: tsParser,
9
+ parserOptions: {
10
+ ecmaVersion: 2022,
11
+ sourceType: 'module',
12
+ },
13
+ },
14
+ valid: [
15
+ // keyframes with alphabetical ordering
16
+ `
17
+ import { keyframes } from '@vanilla-extract/css';
18
+
19
+ const fadeIn = keyframes({
20
+ '0%': {
21
+ opacity: 0,
22
+ transform: 'translateY(10px)'
23
+ },
24
+ '100%': {
25
+ opacity: 1,
26
+ transform: 'translateY(0)'
27
+ }
28
+ });
29
+ `,
30
+ // globalKeyframes with alphabetical ordering
31
+ `
32
+ import { globalKeyframes } from '@vanilla-extract/css';
33
+
34
+ globalKeyframes('fadeIn', {
35
+ '0%': {
36
+ opacity: 0,
37
+ transform: 'translateY(10px)'
38
+ },
39
+ '100%': {
40
+ opacity: 1,
41
+ transform: 'translateY(0)'
42
+ }
43
+ });
44
+ `,
45
+ ],
46
+ invalid: [
47
+ // keyframes with incorrect ordering
48
+ {
49
+ code: `
50
+ import { keyframes } from '@vanilla-extract/css';
51
+ const fadeIn = keyframes({
52
+ '0%': {
53
+ transform: 'translateY(10px)',
54
+ opacity: 0
55
+ },
56
+ '100%': {
57
+ transform: 'translateY(0)',
58
+ opacity: 1
59
+ }
60
+ });
61
+ `,
62
+ errors: [{ messageId: 'alphabeticalOrder' }, { messageId: 'alphabeticalOrder' }],
63
+ output: `
64
+ import { keyframes } from '@vanilla-extract/css';
65
+ const fadeIn = keyframes({
66
+ '0%': {
67
+ opacity: 0,
68
+ transform: 'translateY(10px)'
69
+ },
70
+ '100%': {
71
+ opacity: 1,
72
+ transform: 'translateY(0)'
73
+ }
74
+ });
75
+ `,
76
+ },
77
+ // globalKeyframes with incorrect ordering
78
+ {
79
+ code: `
80
+ import { globalKeyframes } from '@vanilla-extract/css';
81
+ globalKeyframes('fadeIn', {
82
+ '0%': {
83
+ transform: 'translateY(10px)',
84
+ opacity: 0
85
+ },
86
+ '100%': {
87
+ transform: 'translateY(0)',
88
+ opacity: 1
89
+ }
90
+ });
91
+ `,
92
+ errors: [{ messageId: 'alphabeticalOrder' }, { messageId: 'alphabeticalOrder' }],
93
+ output: `
94
+ import { globalKeyframes } from '@vanilla-extract/css';
95
+ globalKeyframes('fadeIn', {
96
+ '0%': {
97
+ opacity: 0,
98
+ transform: 'translateY(10px)'
99
+ },
100
+ '100%': {
101
+ opacity: 1,
102
+ transform: 'translateY(0)'
103
+ }
104
+ });
105
+ `,
106
+ },
107
+ ],
108
+ });
@@ -0,0 +1,138 @@
1
+ import tsParser from '@typescript-eslint/parser';
2
+ import { run } from 'eslint-vitest-rule-tester';
3
+ import alphabeticalOrderRule from '../rule-definition.js';
4
+ run({
5
+ name: 'vanilla-extract/alphabetical-order/font-face',
6
+ rule: alphabeticalOrderRule,
7
+ languageOptions: {
8
+ parser: tsParser,
9
+ parserOptions: {
10
+ ecmaVersion: 2022,
11
+ sourceType: 'module',
12
+ },
13
+ },
14
+ valid: [
15
+ // fontFace with src first and other properties alphabetically ordered
16
+ `
17
+ import { fontFace } from '@vanilla-extract/css';
18
+
19
+ const myFont = fontFace({
20
+ src: ['url("/fonts/MyFont.woff2") format("woff2")'],
21
+ ascentOverride: '90%',
22
+ descentOverride: '10%',
23
+ fontDisplay: 'swap',
24
+ fontFeatureSettings: '"liga" 1',
25
+ fontStretch: 'normal',
26
+ fontStyle: 'normal',
27
+ fontVariant: 'normal',
28
+ fontWeight: '400'
29
+ });
30
+ `,
31
+ // globalFontFace with src first and other properties alphabetically ordered
32
+ `
33
+ import { globalFontFace } from '@vanilla-extract/css';
34
+
35
+ globalFontFace('GlobalFont', {
36
+ src: ['url("/fonts/MyFont.woff2") format("woff2")'],
37
+ ascentOverride: '90%',
38
+ descentOverride: '10%',
39
+ fontDisplay: 'swap',
40
+ fontFeatureSettings: '"liga" 1',
41
+ fontStretch: 'normal',
42
+ fontStyle: 'normal',
43
+ fontVariant: 'normal',
44
+ fontWeight: '400'
45
+ });
46
+ `,
47
+ ],
48
+ invalid: [
49
+ // fontFace with src not first
50
+ {
51
+ code: `
52
+ import { fontFace } from '@vanilla-extract/css';
53
+ const myFont = fontFace({
54
+ fontWeight: '400',
55
+ src: ['url("/fonts/MyFont.woff2") format("woff2")'],
56
+ ascentOverride: '90%',
57
+ fontStyle: 'normal'
58
+ });
59
+ `,
60
+ errors: [{ messageId: 'fontFaceOrder' }],
61
+ output: `
62
+ import { fontFace } from '@vanilla-extract/css';
63
+ const myFont = fontFace({
64
+ src: ['url("/fonts/MyFont.woff2") format("woff2")'],
65
+ ascentOverride: '90%',
66
+ fontStyle: 'normal',
67
+ fontWeight: '400'
68
+ });
69
+ `,
70
+ },
71
+ // fontFace with src first but other properties not in alphabetical order
72
+ {
73
+ code: `
74
+ import { fontFace } from '@vanilla-extract/css';
75
+ const myFont = fontFace({
76
+ src: ['url("/fonts/MyFont.woff2") format("woff2")'],
77
+ fontWeight: '400',
78
+ ascentOverride: '90%',
79
+ fontStyle: 'normal'
80
+ });
81
+ `,
82
+ errors: [{ messageId: 'fontFaceOrder' }],
83
+ output: `
84
+ import { fontFace } from '@vanilla-extract/css';
85
+ const myFont = fontFace({
86
+ src: ['url("/fonts/MyFont.woff2") format("woff2")'],
87
+ ascentOverride: '90%',
88
+ fontStyle: 'normal',
89
+ fontWeight: '400'
90
+ });
91
+ `,
92
+ },
93
+ // globalFontFace with src not first
94
+ {
95
+ code: `
96
+ import { globalFontFace } from '@vanilla-extract/css';
97
+ globalFontFace('GlobalFont', {
98
+ fontWeight: '400',
99
+ fontStyle: 'normal',
100
+ src: ['url("/fonts/MyFont.woff2") format("woff2")'],
101
+ ascentOverride: '90%'
102
+ });
103
+ `,
104
+ errors: [{ messageId: 'fontFaceOrder' }],
105
+ output: `
106
+ import { globalFontFace } from '@vanilla-extract/css';
107
+ globalFontFace('GlobalFont', {
108
+ src: ['url("/fonts/MyFont.woff2") format("woff2")'],
109
+ ascentOverride: '90%',
110
+ fontStyle: 'normal',
111
+ fontWeight: '400'
112
+ });
113
+ `,
114
+ },
115
+ // globalFontFace with src first but other properties not in alphabetical order
116
+ {
117
+ code: `
118
+ import { globalFontFace } from '@vanilla-extract/css';
119
+ globalFontFace('GlobalFont', {
120
+ src: ['url("/fonts/MyFont.woff2") format("woff2")'],
121
+ fontWeight: '400',
122
+ fontStyle: 'normal',
123
+ ascentOverride: '90%'
124
+ });
125
+ `,
126
+ errors: [{ messageId: 'fontFaceOrder' }],
127
+ output: `
128
+ import { globalFontFace } from '@vanilla-extract/css';
129
+ globalFontFace('GlobalFont', {
130
+ src: ['url("/fonts/MyFont.woff2") format("woff2")'],
131
+ ascentOverride: '90%',
132
+ fontStyle: 'normal',
133
+ fontWeight: '400'
134
+ });
135
+ `,
136
+ },
137
+ ],
138
+ });
@@ -0,0 +1,51 @@
1
+ import tsParser from '@typescript-eslint/parser';
2
+ import { run } from 'eslint-vitest-rule-tester';
3
+ import alphabeticalOrderRule from '../rule-definition.js';
4
+ run({
5
+ name: 'vanilla-extract/alphabetical-order/global',
6
+ rule: alphabeticalOrderRule,
7
+ languageOptions: {
8
+ parser: tsParser,
9
+ parserOptions: {
10
+ ecmaVersion: 2022,
11
+ sourceType: 'module',
12
+ },
13
+ },
14
+ valid: [
15
+ // globalStyle with alphabetical ordering
16
+ `
17
+ import { globalStyle } from '@vanilla-extract/css';
18
+
19
+ globalStyle('body', {
20
+ backgroundColor: 'white',
21
+ color: 'black',
22
+ margin: 0,
23
+ padding: 0
24
+ });
25
+ `,
26
+ ],
27
+ invalid: [
28
+ // globalStyle with incorrect ordering
29
+ {
30
+ code: `
31
+ import { globalStyle } from '@vanilla-extract/css';
32
+ globalStyle('body', {
33
+ color: 'black',
34
+ backgroundColor: 'white',
35
+ padding: 0,
36
+ margin: 0
37
+ });
38
+ `,
39
+ errors: [{ messageId: 'alphabeticalOrder' }],
40
+ output: `
41
+ import { globalStyle } from '@vanilla-extract/css';
42
+ globalStyle('body', {
43
+ backgroundColor: 'white',
44
+ color: 'black',
45
+ margin: 0,
46
+ padding: 0
47
+ });
48
+ `,
49
+ },
50
+ ],
51
+ });
@@ -0,0 +1,91 @@
1
+ import tsParser from '@typescript-eslint/parser';
2
+ import { run } from 'eslint-vitest-rule-tester';
3
+ import alphabeticalOrderRule from '../rule-definition.js';
4
+ run({
5
+ name: 'vanilla-extract/alphabetical-order/recipe',
6
+ rule: alphabeticalOrderRule,
7
+ languageOptions: {
8
+ parser: tsParser,
9
+ parserOptions: {
10
+ ecmaVersion: 2022,
11
+ sourceType: 'module',
12
+ },
13
+ },
14
+ valid: [
15
+ // Recipe with alphabetical ordering
16
+ `
17
+ import { recipe } from '@vanilla-extract/recipes';
18
+
19
+ const myRecipe = recipe({
20
+ base: {
21
+ alignItems: 'center',
22
+ display: 'flex'
23
+ },
24
+ variants: {
25
+ color: {
26
+ blue: {
27
+ backgroundColor: 'blue',
28
+ color: 'white'
29
+ },
30
+ red: {
31
+ backgroundColor: 'red',
32
+ color: 'black'
33
+ }
34
+ }
35
+ }
36
+ });
37
+ `,
38
+ ],
39
+ invalid: [
40
+ // Recipe with incorrect ordering
41
+ {
42
+ code: `
43
+ import { recipe } from '@vanilla-extract/recipes';
44
+ const myRecipe = recipe({
45
+ base: {
46
+ display: 'flex',
47
+ alignItems: 'center'
48
+ },
49
+ variants: {
50
+ color: {
51
+ blue: {
52
+ color: 'white',
53
+ backgroundColor: 'blue'
54
+ },
55
+ red: {
56
+ color: 'black',
57
+ backgroundColor: 'red'
58
+ }
59
+ }
60
+ }
61
+ });
62
+ `,
63
+ errors: [
64
+ { messageId: 'alphabeticalOrder' },
65
+ { messageId: 'alphabeticalOrder' },
66
+ { messageId: 'alphabeticalOrder' },
67
+ ],
68
+ output: `
69
+ import { recipe } from '@vanilla-extract/recipes';
70
+ const myRecipe = recipe({
71
+ base: {
72
+ alignItems: 'center',
73
+ display: 'flex'
74
+ },
75
+ variants: {
76
+ color: {
77
+ blue: {
78
+ backgroundColor: 'blue',
79
+ color: 'white'
80
+ },
81
+ red: {
82
+ backgroundColor: 'red',
83
+ color: 'black'
84
+ }
85
+ }
86
+ }
87
+ });
88
+ `,
89
+ },
90
+ ],
91
+ });
@@ -0,0 +1,108 @@
1
+ import tsParser from '@typescript-eslint/parser';
2
+ import { run } from 'eslint-vitest-rule-tester';
3
+ import alphabeticalOrderRule from '../rule-definition.js';
4
+ run({
5
+ name: 'vanilla-extract/alphabetical-order/style',
6
+ rule: alphabeticalOrderRule,
7
+ languageOptions: {
8
+ parser: tsParser,
9
+ parserOptions: {
10
+ ecmaVersion: 2022,
11
+ sourceType: 'module',
12
+ },
13
+ },
14
+ valid: [
15
+ // Basic style object with alphabetical ordering
16
+ `
17
+ import { style } from '@vanilla-extract/css';
18
+
19
+ const myStyle = style({
20
+ alignItems: 'center',
21
+ backgroundColor: 'red',
22
+ color: 'blue',
23
+ display: 'flex',
24
+ margin: '10px',
25
+ padding: '20px',
26
+ zIndex: 1
27
+ });
28
+ `,
29
+ // Style with nested selectors
30
+ `
31
+ import { style } from '@vanilla-extract/css';
32
+
33
+ const myStyle = style({
34
+ alignItems: 'center',
35
+ backgroundColor: 'red',
36
+ color: 'blue',
37
+ selectors: {
38
+ '&:hover': {
39
+ backgroundColor: 'blue',
40
+ color: 'white'
41
+ }
42
+ }
43
+ });
44
+ `,
45
+ ],
46
+ invalid: [
47
+ // Basic style object with incorrect ordering
48
+ {
49
+ code: `
50
+ import { style } from '@vanilla-extract/css';
51
+ const myStyle = style({
52
+ backgroundColor: 'red',
53
+ alignItems: 'center',
54
+ padding: '20px',
55
+ color: 'blue',
56
+ margin: '10px',
57
+ display: 'flex',
58
+ zIndex: 1
59
+ });
60
+ `,
61
+ errors: [{ messageId: 'alphabeticalOrder' }],
62
+ output: `
63
+ import { style } from '@vanilla-extract/css';
64
+ const myStyle = style({
65
+ alignItems: 'center',
66
+ backgroundColor: 'red',
67
+ color: 'blue',
68
+ display: 'flex',
69
+ margin: '10px',
70
+ padding: '20px',
71
+ zIndex: 1
72
+ });
73
+ `,
74
+ },
75
+ // Style with nested selectors having incorrect ordering
76
+ {
77
+ code: `
78
+ import { style } from '@vanilla-extract/css';
79
+ const myStyle = style({
80
+ backgroundColor: 'red',
81
+ alignItems: 'center',
82
+ color: 'blue',
83
+ selectors: {
84
+ '&:hover': {
85
+ color: 'white',
86
+ backgroundColor: 'blue'
87
+ }
88
+ }
89
+ });
90
+ `,
91
+ errors: [{ messageId: 'alphabeticalOrder' }, { messageId: 'alphabeticalOrder' }],
92
+ output: `
93
+ import { style } from '@vanilla-extract/css';
94
+ const myStyle = style({
95
+ alignItems: 'center',
96
+ backgroundColor: 'red',
97
+ color: 'blue',
98
+ selectors: {
99
+ '&:hover': {
100
+ backgroundColor: 'blue',
101
+ color: 'white'
102
+ }
103
+ }
104
+ });
105
+ `,
106
+ },
107
+ ],
108
+ });
@@ -0,0 +1,63 @@
1
+ import tsParser from '@typescript-eslint/parser';
2
+ import { run } from 'eslint-vitest-rule-tester';
3
+ import alphabeticalOrderRule from '../rule-definition.js';
4
+ run({
5
+ name: 'vanilla-extract/alphabetical-order/variants',
6
+ rule: alphabeticalOrderRule,
7
+ languageOptions: {
8
+ parser: tsParser,
9
+ parserOptions: {
10
+ ecmaVersion: 2022,
11
+ sourceType: 'module',
12
+ },
13
+ },
14
+ valid: [
15
+ // styleVariants with alphabetical ordering
16
+ `
17
+ import { styleVariants } from '@vanilla-extract/css';
18
+
19
+ const variants = styleVariants({
20
+ primary: {
21
+ backgroundColor: 'blue',
22
+ color: 'white'
23
+ },
24
+ secondary: {
25
+ backgroundColor: 'gray',
26
+ color: 'black'
27
+ }
28
+ });
29
+ `,
30
+ ],
31
+ invalid: [
32
+ // styleVariants with incorrect ordering
33
+ {
34
+ code: `
35
+ import { styleVariants } from '@vanilla-extract/css';
36
+ const variants = styleVariants({
37
+ primary: {
38
+ color: 'white',
39
+ backgroundColor: 'blue'
40
+ },
41
+ secondary: {
42
+ color: 'black',
43
+ backgroundColor: 'gray'
44
+ }
45
+ });
46
+ `,
47
+ errors: [{ messageId: 'alphabeticalOrder' }, { messageId: 'alphabeticalOrder' }],
48
+ output: `
49
+ import { styleVariants } from '@vanilla-extract/css';
50
+ const variants = styleVariants({
51
+ primary: {
52
+ backgroundColor: 'blue',
53
+ color: 'white'
54
+ },
55
+ secondary: {
56
+ backgroundColor: 'gray',
57
+ color: 'black'
58
+ }
59
+ });
60
+ `,
61
+ },
62
+ ],
63
+ });
@@ -1,17 +1,7 @@
1
1
  import { TSESTree } from '@typescript-eslint/utils';
2
+ import { comparePropertiesAlphabetically } from '../shared-utils/alphabetical-property-comparator.js';
2
3
  import { generateFixesForCSSOrder } from '../shared-utils/css-order-fixer.js';
3
4
  import { getPropertyName } from '../shared-utils/property-separator.js';
4
- /**
5
- * Compares two CSS properties alphabetically.
6
- * @param firstProperty The first property to compare.
7
- * @param secondProperty The second property to compare.
8
- * @returns A number indicating the relative order of the properties (-1, 0, or 1).
9
- */
10
- const comparePropertiesAlphabetically = (firstProperty, secondProperty) => {
11
- const firstName = getPropertyName(firstProperty);
12
- const secondName = getPropertyName(secondProperty);
13
- return firstName.localeCompare(secondName);
14
- };
15
5
  /**
16
6
  * Reports an ordering issue to ESLint and generates fixes.
17
7
  * @param ruleContext The ESLint rule context.