@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
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import tsParser from '@typescript-eslint/parser';
|
|
2
|
+
import { run } from 'eslint-vitest-rule-tester';
|
|
3
|
+
import customGroupOrderRule from '../rule-definition.js';
|
|
4
|
+
run({
|
|
5
|
+
name: 'vanilla-extract/custom-order/style',
|
|
6
|
+
rule: customGroupOrderRule,
|
|
7
|
+
languageOptions: {
|
|
8
|
+
parser: tsParser,
|
|
9
|
+
parserOptions: {
|
|
10
|
+
ecmaVersion: 2022,
|
|
11
|
+
sourceType: 'module',
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
valid: [
|
|
15
|
+
// Style with custom group ordering (dimensions, margin, font, border, boxShadow)
|
|
16
|
+
{
|
|
17
|
+
code: `
|
|
18
|
+
import { style } from '@vanilla-extract/css';
|
|
19
|
+
const myStyle = style({
|
|
20
|
+
// dimensions group first
|
|
21
|
+
width: '10rem',
|
|
22
|
+
minWidth: '5rem',
|
|
23
|
+
height: '10rem',
|
|
24
|
+
maxHeight: '20rem',
|
|
25
|
+
|
|
26
|
+
// margin group second
|
|
27
|
+
margin: '1rem',
|
|
28
|
+
marginTop: '0.5rem',
|
|
29
|
+
|
|
30
|
+
// font group third
|
|
31
|
+
fontFamily: 'sans-serif',
|
|
32
|
+
fontSize: '1rem',
|
|
33
|
+
fontWeight: 'bold',
|
|
34
|
+
|
|
35
|
+
// border group fourth
|
|
36
|
+
border: '1px solid black',
|
|
37
|
+
borderRadius: '4px',
|
|
38
|
+
|
|
39
|
+
// boxShadow group fifth
|
|
40
|
+
boxShadow: '0 2px 4px rgba(0,0,0,0.1)',
|
|
41
|
+
|
|
42
|
+
// remaining properties in concentric order
|
|
43
|
+
position: 'relative',
|
|
44
|
+
display: 'flex',
|
|
45
|
+
backgroundColor: 'red',
|
|
46
|
+
padding: '2rem',
|
|
47
|
+
color: 'blue'
|
|
48
|
+
});
|
|
49
|
+
`,
|
|
50
|
+
options: [
|
|
51
|
+
{
|
|
52
|
+
groupOrder: ['dimensions', 'margin', 'font', 'border', 'boxShadow'],
|
|
53
|
+
sortRemainingProperties: 'concentric',
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
// Style with nested selectors following custom group ordering
|
|
58
|
+
{
|
|
59
|
+
code: `
|
|
60
|
+
import { style } from '@vanilla-extract/css';
|
|
61
|
+
const myStyle = style({
|
|
62
|
+
width: '10rem',
|
|
63
|
+
margin: '1rem',
|
|
64
|
+
fontFamily: 'sans-serif',
|
|
65
|
+
border: '1px solid black',
|
|
66
|
+
boxShadow: '0 2px 4px rgba(0,0,0,0.1)',
|
|
67
|
+
position: 'relative',
|
|
68
|
+
backgroundColor: 'red',
|
|
69
|
+
selectors: {
|
|
70
|
+
'&:hover': {
|
|
71
|
+
width: '12rem',
|
|
72
|
+
margin: '12px',
|
|
73
|
+
fontSize: '1rem',
|
|
74
|
+
borderColor: 'blue',
|
|
75
|
+
boxShadow: '0 4px 8px rgba(0,0,0,0.2)',
|
|
76
|
+
position: 'relative',
|
|
77
|
+
backgroundColor: 'blue',
|
|
78
|
+
color: 'white'
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
`,
|
|
83
|
+
options: [
|
|
84
|
+
{
|
|
85
|
+
groupOrder: ['dimensions', 'margin', 'font', 'border', 'boxShadow'],
|
|
86
|
+
sortRemainingProperties: 'concentric',
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
code: `
|
|
92
|
+
import { style } from '@vanilla-extract/css';
|
|
93
|
+
const myStyle = style({
|
|
94
|
+
// dimensions group first
|
|
95
|
+
width: '10rem',
|
|
96
|
+
height: '10rem',
|
|
97
|
+
|
|
98
|
+
// margin group second
|
|
99
|
+
margin: '1rem',
|
|
100
|
+
|
|
101
|
+
// font group third
|
|
102
|
+
fontFamily: 'sans-serif',
|
|
103
|
+
|
|
104
|
+
// border group fourth
|
|
105
|
+
border: '1px solid black',
|
|
106
|
+
|
|
107
|
+
// boxShadow group fifth
|
|
108
|
+
boxShadow: '0 2px 4px rgba(0,0,0,0.1)',
|
|
109
|
+
|
|
110
|
+
// remaining properties in alphabetical order
|
|
111
|
+
backgroundColor: 'red',
|
|
112
|
+
color: 'blue',
|
|
113
|
+
display: 'flex',
|
|
114
|
+
padding: '2rem',
|
|
115
|
+
position: 'relative'
|
|
116
|
+
});
|
|
117
|
+
`,
|
|
118
|
+
options: [
|
|
119
|
+
{
|
|
120
|
+
groupOrder: ['dimensions', 'margin', 'font', 'border', 'boxShadow'],
|
|
121
|
+
sortRemainingProperties: 'alphabetical',
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
invalid: [
|
|
127
|
+
// Style with incorrect custom group ordering
|
|
128
|
+
{
|
|
129
|
+
code: `
|
|
130
|
+
import { style } from '@vanilla-extract/css';
|
|
131
|
+
const myStyle = style({
|
|
132
|
+
position: 'relative',
|
|
133
|
+
border: '1px solid black',
|
|
134
|
+
width: '10rem',
|
|
135
|
+
color: 'blue',
|
|
136
|
+
margin: '1rem',
|
|
137
|
+
fontFamily: 'sans-serif',
|
|
138
|
+
boxShadow: '0 2px 4px rgba(0,0,0,0.1)',
|
|
139
|
+
backgroundColor: 'red'
|
|
140
|
+
});
|
|
141
|
+
`,
|
|
142
|
+
options: [
|
|
143
|
+
{
|
|
144
|
+
groupOrder: ['dimensions', 'margin', 'font', 'border', 'boxShadow'],
|
|
145
|
+
sortRemainingProperties: 'concentric',
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
errors: [{ messageId: 'incorrectOrder' }],
|
|
149
|
+
output: `
|
|
150
|
+
import { style } from '@vanilla-extract/css';
|
|
151
|
+
const myStyle = style({
|
|
152
|
+
width: '10rem',
|
|
153
|
+
margin: '1rem',
|
|
154
|
+
fontFamily: 'sans-serif',
|
|
155
|
+
border: '1px solid black',
|
|
156
|
+
boxShadow: '0 2px 4px rgba(0,0,0,0.1)',
|
|
157
|
+
position: 'relative',
|
|
158
|
+
backgroundColor: 'red',
|
|
159
|
+
color: 'blue'
|
|
160
|
+
});
|
|
161
|
+
`,
|
|
162
|
+
},
|
|
163
|
+
// Style with nested selectors having incorrect ordering
|
|
164
|
+
{
|
|
165
|
+
code: `
|
|
166
|
+
import { style } from '@vanilla-extract/css';
|
|
167
|
+
const myStyle = style({
|
|
168
|
+
border: '1px solid black',
|
|
169
|
+
width: '10rem',
|
|
170
|
+
position: 'relative',
|
|
171
|
+
margin: '1rem',
|
|
172
|
+
selectors: {
|
|
173
|
+
'&:hover': {
|
|
174
|
+
color: 'white',
|
|
175
|
+
width: '12rem',
|
|
176
|
+
border: '2px solid blue',
|
|
177
|
+
margin: '1.2rem',
|
|
178
|
+
backgroundColor: 'blue'
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
`,
|
|
183
|
+
options: [
|
|
184
|
+
{
|
|
185
|
+
groupOrder: ['dimensions', 'margin', 'font', 'border', 'boxShadow'],
|
|
186
|
+
sortRemainingProperties: 'concentric',
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
errors: [{ messageId: 'incorrectOrder' }, { messageId: 'incorrectOrder' }],
|
|
190
|
+
output: `
|
|
191
|
+
import { style } from '@vanilla-extract/css';
|
|
192
|
+
const myStyle = style({
|
|
193
|
+
width: '10rem',
|
|
194
|
+
margin: '1rem',
|
|
195
|
+
border: '1px solid black',
|
|
196
|
+
position: 'relative',
|
|
197
|
+
selectors: {
|
|
198
|
+
'&:hover': {
|
|
199
|
+
width: '12rem',
|
|
200
|
+
margin: '1.2rem',
|
|
201
|
+
border: '2px solid blue',
|
|
202
|
+
backgroundColor: 'blue',
|
|
203
|
+
color: 'white'
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
`,
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
code: `
|
|
211
|
+
import { style } from '@vanilla-extract/css';
|
|
212
|
+
const myStyle = style({
|
|
213
|
+
position: 'relative',
|
|
214
|
+
border: '1px solid black',
|
|
215
|
+
width: '10rem',
|
|
216
|
+
padding: '2rem',
|
|
217
|
+
color: 'blue',
|
|
218
|
+
margin: '1rem',
|
|
219
|
+
display: 'flex',
|
|
220
|
+
fontFamily: 'sans-serif',
|
|
221
|
+
boxShadow: '0 2px 4px rgba(0,0,0,0.1)',
|
|
222
|
+
backgroundColor: 'red'
|
|
223
|
+
});
|
|
224
|
+
`,
|
|
225
|
+
options: [
|
|
226
|
+
{
|
|
227
|
+
groupOrder: ['dimensions', 'margin', 'font', 'border', 'boxShadow'],
|
|
228
|
+
sortRemainingProperties: 'alphabetical',
|
|
229
|
+
},
|
|
230
|
+
],
|
|
231
|
+
errors: [{ messageId: 'incorrectOrder' }],
|
|
232
|
+
output: `
|
|
233
|
+
import { style } from '@vanilla-extract/css';
|
|
234
|
+
const myStyle = style({
|
|
235
|
+
width: '10rem',
|
|
236
|
+
margin: '1rem',
|
|
237
|
+
fontFamily: 'sans-serif',
|
|
238
|
+
border: '1px solid black',
|
|
239
|
+
boxShadow: '0 2px 4px rgba(0,0,0,0.1)',
|
|
240
|
+
backgroundColor: 'red',
|
|
241
|
+
color: 'blue',
|
|
242
|
+
display: 'flex',
|
|
243
|
+
padding: '2rem',
|
|
244
|
+
position: 'relative'
|
|
245
|
+
});
|
|
246
|
+
`,
|
|
247
|
+
},
|
|
248
|
+
],
|
|
249
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import tsParser from '@typescript-eslint/parser';
|
|
2
|
+
import { run } from 'eslint-vitest-rule-tester';
|
|
3
|
+
import customGroupOrderRule from '../rule-definition.js';
|
|
4
|
+
run({
|
|
5
|
+
name: 'vanilla-extract/custom-order/variants',
|
|
6
|
+
rule: customGroupOrderRule,
|
|
7
|
+
languageOptions: {
|
|
8
|
+
parser: tsParser,
|
|
9
|
+
parserOptions: {
|
|
10
|
+
ecmaVersion: 2022,
|
|
11
|
+
sourceType: 'module',
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
valid: [
|
|
15
|
+
// styleVariants with custom group ordering (concentric for remaining)
|
|
16
|
+
{
|
|
17
|
+
code: `
|
|
18
|
+
import { styleVariants } from '@vanilla-extract/css';
|
|
19
|
+
|
|
20
|
+
const variants = styleVariants({
|
|
21
|
+
primary: {
|
|
22
|
+
margin: '1rem',
|
|
23
|
+
padding: '0.5rem',
|
|
24
|
+
position: 'relative',
|
|
25
|
+
display: 'flex',
|
|
26
|
+
backgroundColor: 'blue',
|
|
27
|
+
color: 'white'
|
|
28
|
+
},
|
|
29
|
+
secondary: {
|
|
30
|
+
margin: '0.8rem',
|
|
31
|
+
padding: '0.4rem',
|
|
32
|
+
position: 'relative',
|
|
33
|
+
display: 'flex',
|
|
34
|
+
backgroundColor: 'gray',
|
|
35
|
+
color: 'black'
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
`,
|
|
39
|
+
options: [
|
|
40
|
+
{
|
|
41
|
+
groupOrder: ['margin', 'padding', 'dimensions', 'font', 'border', 'boxShadow'],
|
|
42
|
+
sortRemainingProperties: 'concentric',
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
// styleVariants with custom group ordering (alphabetical for remaining)
|
|
47
|
+
{
|
|
48
|
+
code: `
|
|
49
|
+
import { styleVariants } from '@vanilla-extract/css';
|
|
50
|
+
|
|
51
|
+
const variants = styleVariants({
|
|
52
|
+
primary: {
|
|
53
|
+
margin: '1rem',
|
|
54
|
+
padding: '0.5rem',
|
|
55
|
+
backgroundColor: 'blue',
|
|
56
|
+
color: 'white',
|
|
57
|
+
display: 'flex',
|
|
58
|
+
position: 'relative'
|
|
59
|
+
},
|
|
60
|
+
secondary: {
|
|
61
|
+
margin: '0.8rem',
|
|
62
|
+
padding: '0.4rem',
|
|
63
|
+
backgroundColor: 'gray',
|
|
64
|
+
color: 'black',
|
|
65
|
+
display: 'flex',
|
|
66
|
+
position: 'relative'
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
`,
|
|
70
|
+
options: [
|
|
71
|
+
{
|
|
72
|
+
groupOrder: ['margin', 'padding', 'dimensions', 'font', 'border', 'boxShadow'],
|
|
73
|
+
sortRemainingProperties: 'alphabetical',
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
invalid: [
|
|
79
|
+
// styleVariants with incorrect ordering (concentric for remaining)
|
|
80
|
+
{
|
|
81
|
+
code: `
|
|
82
|
+
import { styleVariants } from '@vanilla-extract/css';
|
|
83
|
+
const variants = styleVariants({
|
|
84
|
+
primary: {
|
|
85
|
+
color: 'white',
|
|
86
|
+
backgroundColor: 'blue',
|
|
87
|
+
padding: '0.5rem',
|
|
88
|
+
margin: '1rem',
|
|
89
|
+
display: 'flex',
|
|
90
|
+
position: 'relative'
|
|
91
|
+
},
|
|
92
|
+
secondary: {
|
|
93
|
+
color: 'black',
|
|
94
|
+
backgroundColor: 'gray',
|
|
95
|
+
padding: '0.4rem',
|
|
96
|
+
margin: '0.8rem',
|
|
97
|
+
display: 'flex',
|
|
98
|
+
position: 'relative'
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
`,
|
|
102
|
+
options: [
|
|
103
|
+
{
|
|
104
|
+
groupOrder: ['margin', 'padding', 'dimensions', 'font', 'border', 'boxShadow'],
|
|
105
|
+
sortRemainingProperties: 'concentric',
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
errors: [{ messageId: 'incorrectOrder' }, { messageId: 'incorrectOrder' }],
|
|
109
|
+
output: `
|
|
110
|
+
import { styleVariants } from '@vanilla-extract/css';
|
|
111
|
+
const variants = styleVariants({
|
|
112
|
+
primary: {
|
|
113
|
+
margin: '1rem',
|
|
114
|
+
padding: '0.5rem',
|
|
115
|
+
position: 'relative',
|
|
116
|
+
display: 'flex',
|
|
117
|
+
backgroundColor: 'blue',
|
|
118
|
+
color: 'white'
|
|
119
|
+
},
|
|
120
|
+
secondary: {
|
|
121
|
+
margin: '0.8rem',
|
|
122
|
+
padding: '0.4rem',
|
|
123
|
+
position: 'relative',
|
|
124
|
+
display: 'flex',
|
|
125
|
+
backgroundColor: 'gray',
|
|
126
|
+
color: 'black'
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
`,
|
|
130
|
+
},
|
|
131
|
+
// styleVariants with incorrect ordering (alphabetical for remaining)
|
|
132
|
+
{
|
|
133
|
+
code: `
|
|
134
|
+
import { styleVariants } from '@vanilla-extract/css';
|
|
135
|
+
const variants = styleVariants({
|
|
136
|
+
primary: {
|
|
137
|
+
position: 'relative',
|
|
138
|
+
display: 'flex',
|
|
139
|
+
margin: '1rem',
|
|
140
|
+
padding: '0.5rem',
|
|
141
|
+
backgroundColor: 'blue',
|
|
142
|
+
color: 'white'
|
|
143
|
+
},
|
|
144
|
+
secondary: {
|
|
145
|
+
color: 'black',
|
|
146
|
+
backgroundColor: 'gray',
|
|
147
|
+
padding: '0.4rem',
|
|
148
|
+
margin: '0.8rem',
|
|
149
|
+
display: 'flex',
|
|
150
|
+
position: 'relative'
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
`,
|
|
154
|
+
options: [
|
|
155
|
+
{
|
|
156
|
+
groupOrder: ['margin', 'padding', 'dimensions', 'font', 'border', 'boxShadow'],
|
|
157
|
+
sortRemainingProperties: 'alphabetical',
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
errors: [{ messageId: 'incorrectOrder' }, { messageId: 'incorrectOrder' }],
|
|
161
|
+
output: `
|
|
162
|
+
import { styleVariants } from '@vanilla-extract/css';
|
|
163
|
+
const variants = styleVariants({
|
|
164
|
+
primary: {
|
|
165
|
+
margin: '1rem',
|
|
166
|
+
padding: '0.5rem',
|
|
167
|
+
backgroundColor: 'blue',
|
|
168
|
+
color: 'white',
|
|
169
|
+
display: 'flex',
|
|
170
|
+
position: 'relative'
|
|
171
|
+
},
|
|
172
|
+
secondary: {
|
|
173
|
+
margin: '0.8rem',
|
|
174
|
+
padding: '0.4rem',
|
|
175
|
+
backgroundColor: 'gray',
|
|
176
|
+
color: 'black',
|
|
177
|
+
display: 'flex',
|
|
178
|
+
position: 'relative'
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
`,
|
|
182
|
+
},
|
|
183
|
+
],
|
|
184
|
+
});
|
|
@@ -28,6 +28,7 @@ const customGroupOrderRule = {
|
|
|
28
28
|
],
|
|
29
29
|
messages: {
|
|
30
30
|
incorrectOrder: "Property '{{nextProperty}}' should come before '{{currentProperty}}' according to custom CSS group ordering.",
|
|
31
|
+
fontFaceOrder: "Properties in fontFace should be ordered with 'src' first, followed by other properties in alphabetical order. Property '{{nextProperty}}' should come before '{{currentProperty}}'.",
|
|
31
32
|
},
|
|
32
33
|
},
|
|
33
34
|
create(ruleContext) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import tsParser from '@typescript-eslint/parser';
|
|
2
|
+
import { run } from 'eslint-vitest-rule-tester';
|
|
3
|
+
import concentricOrderRule from '../../concentric-order/rule-definition.js';
|
|
4
|
+
import { createCSSPropertyPriorityMap } from '../css-property-priority-map.js';
|
|
5
|
+
// A modified version of the rule that uses invalid group names
|
|
6
|
+
const testPropertyPriorityMapRule = {
|
|
7
|
+
...concentricOrderRule,
|
|
8
|
+
create(context) {
|
|
9
|
+
// This will trigger the || [] fallback by using non-existent group names
|
|
10
|
+
createCSSPropertyPriorityMap(['non-existent-group', 'another-fake-group']);
|
|
11
|
+
// Return the original rule's implementation
|
|
12
|
+
return concentricOrderRule.create(context);
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
run({
|
|
16
|
+
name: 'vanilla-extract/css-property-priority-map-tests',
|
|
17
|
+
rule: testPropertyPriorityMapRule,
|
|
18
|
+
languageOptions: {
|
|
19
|
+
parser: tsParser,
|
|
20
|
+
parserOptions: {
|
|
21
|
+
ecmaVersion: 2022,
|
|
22
|
+
sourceType: 'module',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
valid: [
|
|
26
|
+
// Simple test case to execute the rule
|
|
27
|
+
`
|
|
28
|
+
import { style } from '@vanilla-extract/css';
|
|
29
|
+
|
|
30
|
+
const myStyle = style({
|
|
31
|
+
backgroundColor: 'white',
|
|
32
|
+
color: 'blue'
|
|
33
|
+
});
|
|
34
|
+
`,
|
|
35
|
+
],
|
|
36
|
+
invalid: [],
|
|
37
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import tsParser from '@typescript-eslint/parser';
|
|
2
|
+
import { run } from 'eslint-vitest-rule-tester';
|
|
3
|
+
import alphabeticalOrderRule from '../../alphabetical-order/rule-definition.js';
|
|
4
|
+
import { enforceFontFaceOrder } from '../font-face-property-order-enforcer.js';
|
|
5
|
+
// A modified version of the rule that tests the edge cases
|
|
6
|
+
const fontFaceEdgeCasesRule = {
|
|
7
|
+
...alphabeticalOrderRule,
|
|
8
|
+
create(context) {
|
|
9
|
+
return {
|
|
10
|
+
// Test case for null/undefined fontFaceObject
|
|
11
|
+
CallExpression(node) {
|
|
12
|
+
if (node.callee.type === 'Identifier' && node.callee.name === 'testNullCase') {
|
|
13
|
+
// This will trigger the first early return
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
+
enforceFontFaceOrder(context, null);
|
|
16
|
+
}
|
|
17
|
+
// Test case for non-ObjectExpression node
|
|
18
|
+
if (node.callee.type === 'Identifier' && node.callee.name === 'testNonObjectCase') {
|
|
19
|
+
// This will trigger the first early return (wrong type)
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
+
enforceFontFaceOrder(context, { type: 'Literal' });
|
|
22
|
+
}
|
|
23
|
+
// Test case for empty or single property object
|
|
24
|
+
if (node.callee.type === 'Identifier' && node.callee.name === 'testSinglePropertyCase') {
|
|
25
|
+
// This will trigger the second early return (regularProperties.length <= 1)
|
|
26
|
+
enforceFontFaceOrder(context, {
|
|
27
|
+
type: 'ObjectExpression',
|
|
28
|
+
properties: [
|
|
29
|
+
{
|
|
30
|
+
type: 'Property',
|
|
31
|
+
key: { type: 'Identifier', name: 'fontFamily' },
|
|
32
|
+
value: { type: 'Literal', value: 'Arial' },
|
|
33
|
+
computed: false,
|
|
34
|
+
kind: 'init',
|
|
35
|
+
method: false,
|
|
36
|
+
shorthand: false,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
run({
|
|
47
|
+
name: 'vanilla-extract/font-face-edge-cases',
|
|
48
|
+
rule: fontFaceEdgeCasesRule,
|
|
49
|
+
languageOptions: {
|
|
50
|
+
parser: tsParser,
|
|
51
|
+
parserOptions: {
|
|
52
|
+
ecmaVersion: 2022,
|
|
53
|
+
sourceType: 'module',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
valid: [`testNullCase();`, `testNonObjectCase();`, `testSinglePropertyCase();`],
|
|
57
|
+
invalid: [],
|
|
58
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import tsParser from '@typescript-eslint/parser';
|
|
2
|
+
import { run } from 'eslint-vitest-rule-tester';
|
|
3
|
+
import alphabeticalOrderRule from '../../alphabetical-order/rule-definition.js';
|
|
4
|
+
import customGroupOrderRule from '../../custom-order/rule-definition.js';
|
|
5
|
+
import { createNodeVisitors } from '../order-strategy-visitor-creator.js';
|
|
6
|
+
// Modified version of the custom order rule with empty group order
|
|
7
|
+
const emptyGroupOrderRule = {
|
|
8
|
+
...customGroupOrderRule,
|
|
9
|
+
create(context) {
|
|
10
|
+
// Trigger the error for empty userDefinedGroupOrder
|
|
11
|
+
try {
|
|
12
|
+
return customGroupOrderRule.create({
|
|
13
|
+
...context,
|
|
14
|
+
options: [{ groupOrder: [], sortRemainingProperties: 'alphabetical' }],
|
|
15
|
+
});
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
// Just catch the error but continue with the test
|
|
20
|
+
return {};
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
// A rule that tests the default case in the switch statement
|
|
25
|
+
const defaultCaseRule = {
|
|
26
|
+
...alphabeticalOrderRule,
|
|
27
|
+
create(context) {
|
|
28
|
+
// Force the default case by passing an invalid ordering strategy
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
+
const visitors = createNodeVisitors(context, 'invalid-strategy');
|
|
31
|
+
return visitors;
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
// A rule that tests non-Identifier callee
|
|
35
|
+
const nonIdentifierCalleeRule = {
|
|
36
|
+
...alphabeticalOrderRule,
|
|
37
|
+
create(context) {
|
|
38
|
+
return {
|
|
39
|
+
CallExpression(node) {
|
|
40
|
+
// Original rule's visitor will be called first
|
|
41
|
+
const visitors = alphabeticalOrderRule.create(context);
|
|
42
|
+
if (visitors.CallExpression) {
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
|
+
visitors.CallExpression(node);
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
// Test the empty group order case
|
|
51
|
+
run({
|
|
52
|
+
name: 'vanilla-extract/empty-group-order-test',
|
|
53
|
+
rule: emptyGroupOrderRule,
|
|
54
|
+
languageOptions: {
|
|
55
|
+
parser: tsParser,
|
|
56
|
+
parserOptions: {
|
|
57
|
+
ecmaVersion: 2022,
|
|
58
|
+
sourceType: 'module',
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
valid: [
|
|
62
|
+
// Simple test case to execute the rule
|
|
63
|
+
`
|
|
64
|
+
import { style } from '@vanilla-extract/css';
|
|
65
|
+
|
|
66
|
+
const myStyle = style({
|
|
67
|
+
backgroundColor: 'white',
|
|
68
|
+
color: 'blue'
|
|
69
|
+
});
|
|
70
|
+
`,
|
|
71
|
+
],
|
|
72
|
+
invalid: [],
|
|
73
|
+
});
|
|
74
|
+
// Test the default case in the switch statement
|
|
75
|
+
run({
|
|
76
|
+
name: 'vanilla-extract/default-case-test',
|
|
77
|
+
rule: defaultCaseRule,
|
|
78
|
+
languageOptions: {
|
|
79
|
+
parser: tsParser,
|
|
80
|
+
parserOptions: {
|
|
81
|
+
ecmaVersion: 2022,
|
|
82
|
+
sourceType: 'module',
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
valid: [
|
|
86
|
+
// Simple test case to execute the rule
|
|
87
|
+
`
|
|
88
|
+
import { style } from '@vanilla-extract/css';
|
|
89
|
+
|
|
90
|
+
const myStyle = style({
|
|
91
|
+
backgroundColor: 'white',
|
|
92
|
+
color: 'blue'
|
|
93
|
+
});
|
|
94
|
+
`,
|
|
95
|
+
],
|
|
96
|
+
invalid: [],
|
|
97
|
+
});
|
|
98
|
+
// Test the non-Identifier callee case
|
|
99
|
+
run({
|
|
100
|
+
name: 'vanilla-extract/non-identifier-callee-test',
|
|
101
|
+
rule: nonIdentifierCalleeRule,
|
|
102
|
+
languageOptions: {
|
|
103
|
+
parser: tsParser,
|
|
104
|
+
parserOptions: {
|
|
105
|
+
ecmaVersion: 2022,
|
|
106
|
+
sourceType: 'module',
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
valid: [
|
|
110
|
+
// Test with a member expression callee (not an Identifier)
|
|
111
|
+
`
|
|
112
|
+
import { css } from '@vanilla-extract/css';
|
|
113
|
+
|
|
114
|
+
const utils = {
|
|
115
|
+
createStyle: function(obj) { return obj; }
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const myStyle = utils.createStyle({
|
|
119
|
+
backgroundColor: 'white',
|
|
120
|
+
color: 'blue'
|
|
121
|
+
});
|
|
122
|
+
`,
|
|
123
|
+
],
|
|
124
|
+
invalid: [],
|
|
125
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|