@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.
- package/README.md +46 -8
- package/dist/css-rules/alphabetical-order/__tests__/animation.test.d.ts +1 -0
- package/dist/css-rules/alphabetical-order/__tests__/animation.test.js +108 -0
- package/dist/css-rules/alphabetical-order/__tests__/font-face.test.d.ts +1 -0
- package/dist/css-rules/alphabetical-order/__tests__/font-face.test.js +138 -0
- package/dist/css-rules/alphabetical-order/__tests__/global.test.d.ts +1 -0
- package/dist/css-rules/alphabetical-order/__tests__/global.test.js +51 -0
- package/dist/css-rules/alphabetical-order/__tests__/recipe.test.d.ts +1 -0
- package/dist/css-rules/alphabetical-order/__tests__/recipe.test.js +91 -0
- package/dist/css-rules/alphabetical-order/__tests__/style.test.d.ts +1 -0
- package/dist/css-rules/alphabetical-order/__tests__/style.test.js +108 -0
- package/dist/css-rules/alphabetical-order/__tests__/variants.test.d.ts +1 -0
- package/dist/css-rules/alphabetical-order/__tests__/variants.test.js +63 -0
- package/dist/css-rules/alphabetical-order/property-order-enforcer.js +1 -11
- package/dist/css-rules/alphabetical-order/rule-definition.js +2 -1
- package/dist/css-rules/concentric-order/__tests__/animation.test.d.ts +1 -0
- package/dist/css-rules/concentric-order/__tests__/animation.test.js +69 -0
- package/dist/css-rules/concentric-order/__tests__/font-face.test.d.ts +1 -0
- package/dist/css-rules/concentric-order/__tests__/font-face.test.js +94 -0
- package/dist/css-rules/concentric-order/__tests__/global.test.d.ts +1 -0
- package/dist/css-rules/concentric-order/__tests__/global.test.js +57 -0
- package/dist/css-rules/concentric-order/__tests__/recipe.test.d.ts +1 -0
- package/dist/css-rules/concentric-order/__tests__/recipe.test.js +100 -0
- package/dist/css-rules/concentric-order/__tests__/style.test.d.ts +1 -0
- package/dist/css-rules/concentric-order/__tests__/style.test.js +126 -0
- package/dist/css-rules/concentric-order/__tests__/variants.test.d.ts +1 -0
- package/dist/css-rules/concentric-order/__tests__/variants.test.js +133 -0
- package/dist/css-rules/concentric-order/property-order-enforcer.js +2 -2
- package/dist/css-rules/concentric-order/rule-definition.js +3 -1
- package/dist/css-rules/custom-order/__tests__/animation.test.d.ts +1 -0
- package/dist/css-rules/custom-order/__tests__/animation.test.js +148 -0
- package/dist/css-rules/custom-order/__tests__/font-face.test.d.ts +1 -0
- package/dist/css-rules/custom-order/__tests__/font-face.test.js +124 -0
- package/dist/css-rules/custom-order/__tests__/global.test.d.ts +1 -0
- package/dist/css-rules/custom-order/__tests__/global.test.js +124 -0
- package/dist/css-rules/custom-order/__tests__/recipe.test.d.ts +1 -0
- package/dist/css-rules/custom-order/__tests__/recipe.test.js +208 -0
- package/dist/css-rules/custom-order/__tests__/style.test.d.ts +1 -0
- package/dist/css-rules/custom-order/__tests__/style.test.js +249 -0
- package/dist/css-rules/custom-order/__tests__/variants.test.d.ts +1 -0
- package/dist/css-rules/custom-order/__tests__/variants.test.js +184 -0
- package/dist/css-rules/custom-order/rule-definition.js +1 -0
- package/dist/css-rules/shared-utils/__tests__/css-property-priority-map.test.d.ts +1 -0
- package/dist/css-rules/shared-utils/__tests__/css-property-priority-map.test.js +37 -0
- package/dist/css-rules/shared-utils/__tests__/font-face-property-order-enforcer.test.d.ts +1 -0
- package/dist/css-rules/shared-utils/__tests__/font-face-property-order-enforcer.test.js +58 -0
- package/dist/css-rules/shared-utils/__tests__/order-strategy-visitor-creator.test.d.ts +1 -0
- package/dist/css-rules/shared-utils/__tests__/order-strategy-visitor-creator.test.js +125 -0
- package/dist/css-rules/shared-utils/__tests__/property-name-extractor.test.d.ts +1 -0
- package/dist/css-rules/shared-utils/__tests__/property-name-extractor.test.js +53 -0
- package/dist/css-rules/shared-utils/__tests__/recipe-property-processor.test.d.ts +1 -0
- package/dist/css-rules/shared-utils/__tests__/recipe-property-processor.test.js +116 -0
- package/dist/css-rules/shared-utils/__tests__/style-node-processor.test.d.ts +1 -0
- package/dist/css-rules/shared-utils/__tests__/style-node-processor.test.js +55 -0
- package/dist/css-rules/shared-utils/__tests__/test-property-name-rule.d.ts +3 -0
- package/dist/css-rules/shared-utils/__tests__/test-property-name-rule.js +30 -0
- package/dist/css-rules/shared-utils/alphabetical-property-comparator.d.ts +8 -0
- package/dist/css-rules/shared-utils/alphabetical-property-comparator.js +19 -0
- package/dist/css-rules/shared-utils/font-face-property-order-enforcer.d.ts +10 -0
- package/dist/css-rules/shared-utils/font-face-property-order-enforcer.js +39 -0
- package/dist/css-rules/shared-utils/order-strategy-visitor-creator.d.ts +4 -3
- package/dist/css-rules/shared-utils/order-strategy-visitor-creator.js +23 -8
- package/dist/css-rules/shared-utils/style-node-processor.js +2 -5
- package/dist/index.js +1 -1
- package/package.json +11 -6
package/README.md
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
# @antebudimir/eslint-plugin-vanilla-extract
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/@antebudimir/eslint-plugin-vanilla-extract)
|
|
3
|
+
[](https://www.npmjs.com/package/@antebudimir/eslint-plugin-vanilla-extract) [](https://github.com/antebudimir/eslint-plugin-vanilla-extract/actions/workflows/ci.yml) [](https://coveralls.io/github/antebudimir/eslint-plugin-vanilla-extract?branch=main)
|
|
4
4
|
|
|
5
|
-
An ESLint plugin for enforcing
|
|
6
|
-
|
|
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
|
+

|
|
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
|
-
-
|
|
264
|
+
- `no-empty-blocks` rule to disallow empty blocks.
|
|
232
265
|
|
|
233
266
|
### Upcoming Features
|
|
234
267
|
|
|
235
|
-
-
|
|
236
|
-
-
|
|
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 @@
|
|
|
1
|
+
export {};
|
|
@@ -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 @@
|
|
|
1
|
+
export {};
|
|
@@ -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 @@
|
|
|
1
|
+
export {};
|
|
@@ -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 @@
|
|
|
1
|
+
export {};
|
|
@@ -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 @@
|
|
|
1
|
+
export {};
|
|
@@ -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 @@
|
|
|
1
|
+
export {};
|
|
@@ -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.
|