@antebudimir/eslint-plugin-vanilla-extract 1.11.1 → 1.13.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 +84 -14
- package/dist/css-rules/no-px-unit/_tests_/no-px-unit.test.d.ts +1 -0
- package/dist/css-rules/no-px-unit/_tests_/no-px-unit.test.js +163 -0
- package/dist/css-rules/no-px-unit/index.d.ts +2 -0
- package/dist/css-rules/no-px-unit/index.js +2 -0
- package/dist/css-rules/no-px-unit/no-px-unit-visitor-creator.d.ts +2 -0
- package/dist/css-rules/no-px-unit/no-px-unit-visitor-creator.js +55 -0
- package/dist/css-rules/no-px-unit/processor.d.ts +3 -0
- package/dist/css-rules/no-px-unit/processor.js +93 -0
- package/dist/css-rules/no-px-unit/px-unit-processor.d.ts +14 -0
- package/dist/css-rules/no-px-unit/px-unit-processor.js +104 -0
- package/dist/css-rules/no-px-unit/px-unit-visitor-creator.d.ts +11 -0
- package/dist/css-rules/no-px-unit/px-unit-visitor-creator.js +64 -0
- package/dist/css-rules/no-px-unit/rule-definition.d.ts +3 -0
- package/dist/css-rules/no-px-unit/rule-definition.js +37 -0
- package/dist/css-rules/no-px-unit/visitor-creator.d.ts +2 -0
- package/dist/css-rules/no-px-unit/visitor-creator.js +55 -0
- package/dist/css-rules/no-trailing-zero/_tests_/no-trailing-zero.test.d.ts +1 -0
- package/dist/css-rules/no-trailing-zero/_tests_/no-trailing-zero.test.js +537 -0
- package/dist/css-rules/no-trailing-zero/index.d.ts +1 -0
- package/dist/css-rules/no-trailing-zero/index.js +1 -0
- package/dist/css-rules/no-trailing-zero/rule-definition.d.ts +3 -0
- package/dist/css-rules/no-trailing-zero/rule-definition.js +20 -0
- package/dist/css-rules/no-trailing-zero/trailing-zero-processor.d.ts +31 -0
- package/dist/css-rules/no-trailing-zero/trailing-zero-processor.js +165 -0
- package/dist/css-rules/no-trailing-zero/trailing-zero-visitor-creator.d.ts +9 -0
- package/dist/css-rules/no-trailing-zero/trailing-zero-visitor-creator.js +85 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +6 -1
- package/package.json +2 -2
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
import { processRecipeProperties } from '../shared-utils/recipe-property-processor.js';
|
|
3
|
+
import { ReferenceTracker, createReferenceTrackingVisitor } from '../shared-utils/reference-tracker.js';
|
|
4
|
+
import { processStyleNode } from '../shared-utils/style-node-processor.js';
|
|
5
|
+
import { processNoPxUnitInStyleObject } from './px-unit-processor.js';
|
|
6
|
+
/**
|
|
7
|
+
* Creates ESLint rule visitors for detecting and reporting 'px' units in vanilla-extract style objects.
|
|
8
|
+
* - Tracks calls to vanilla-extract APIs (style, recipe, keyframes, globalStyle, fontFace, etc.).
|
|
9
|
+
* This visitor only orchestrates traversal; the actual reporting and suggestion logic lives in the processor.
|
|
10
|
+
* - Respects the `allow` option (camelCase or kebab-case) by passing it as a Set to the processor.
|
|
11
|
+
*
|
|
12
|
+
* @param context ESLint rule context used to read options and report diagnostics.
|
|
13
|
+
* @returns Rule listener that inspects vanilla-extract call expressions and processes style objects.
|
|
14
|
+
*/
|
|
15
|
+
export const createNoPxUnitVisitors = (context) => {
|
|
16
|
+
const tracker = new ReferenceTracker();
|
|
17
|
+
const trackingVisitor = createReferenceTrackingVisitor(tracker);
|
|
18
|
+
const options = context.options?.[0] || {};
|
|
19
|
+
const allowSet = new Set((options.allow ?? []).map((string) => string));
|
|
20
|
+
const process = (context, object) => processNoPxUnitInStyleObject(context, object, allowSet);
|
|
21
|
+
return {
|
|
22
|
+
...trackingVisitor,
|
|
23
|
+
CallExpression(node) {
|
|
24
|
+
if (node.callee.type !== AST_NODE_TYPES.Identifier)
|
|
25
|
+
return;
|
|
26
|
+
const functionName = node.callee.name;
|
|
27
|
+
if (!tracker.isTrackedFunction(functionName))
|
|
28
|
+
return;
|
|
29
|
+
const originalName = tracker.getOriginalName(functionName);
|
|
30
|
+
if (!originalName)
|
|
31
|
+
return;
|
|
32
|
+
switch (originalName) {
|
|
33
|
+
case 'fontFace':
|
|
34
|
+
if (node.arguments.length > 0 && node.arguments[0]?.type === AST_NODE_TYPES.ObjectExpression) {
|
|
35
|
+
process(context, node.arguments[0]);
|
|
36
|
+
}
|
|
37
|
+
break;
|
|
38
|
+
case 'globalFontFace':
|
|
39
|
+
if (node.arguments.length > 1 && node.arguments[1]?.type === AST_NODE_TYPES.ObjectExpression) {
|
|
40
|
+
process(context, node.arguments[1]);
|
|
41
|
+
}
|
|
42
|
+
break;
|
|
43
|
+
case 'style':
|
|
44
|
+
case 'styleVariants':
|
|
45
|
+
case 'keyframes':
|
|
46
|
+
if (node.arguments.length > 0) {
|
|
47
|
+
processStyleNode(context, node.arguments[0], (context, object) => process(context, object));
|
|
48
|
+
}
|
|
49
|
+
break;
|
|
50
|
+
case 'globalStyle':
|
|
51
|
+
case 'globalKeyframes':
|
|
52
|
+
if (node.arguments.length >= 2) {
|
|
53
|
+
processStyleNode(context, node.arguments[1], (context, object) => process(context, object));
|
|
54
|
+
}
|
|
55
|
+
break;
|
|
56
|
+
case 'recipe':
|
|
57
|
+
if (node.arguments.length > 0 && node.arguments[0]?.type === AST_NODE_TYPES.ObjectExpression) {
|
|
58
|
+
processRecipeProperties(context, node.arguments[0], (context, object) => process(context, object));
|
|
59
|
+
}
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { createNoPxUnitVisitors } from './px-unit-visitor-creator.js';
|
|
2
|
+
const noPxUnitRule = {
|
|
3
|
+
meta: {
|
|
4
|
+
type: 'suggestion',
|
|
5
|
+
docs: {
|
|
6
|
+
description: "disallow 'px' units in vanilla-extract style objects, with allowlist option",
|
|
7
|
+
category: 'Best Practices',
|
|
8
|
+
recommended: false,
|
|
9
|
+
},
|
|
10
|
+
// Suggestions are reported from helper modules, so static analysis in this file can’t detect them; disable the false positive.
|
|
11
|
+
// eslint-disable-next-line eslint-plugin/require-meta-has-suggestions
|
|
12
|
+
hasSuggestions: true,
|
|
13
|
+
schema: [
|
|
14
|
+
{
|
|
15
|
+
type: 'object',
|
|
16
|
+
properties: {
|
|
17
|
+
allow: {
|
|
18
|
+
type: 'array',
|
|
19
|
+
items: { type: 'string' },
|
|
20
|
+
uniqueItems: true,
|
|
21
|
+
default: [],
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
additionalProperties: false,
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
messages: {
|
|
28
|
+
noPxUnit: "Avoid using 'px' units. Use rem, em, or theme tokens instead.",
|
|
29
|
+
replaceWithRem: "Replace 'px' with 'rem'.",
|
|
30
|
+
removePx: "Remove 'px' unit.",
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
create(context) {
|
|
34
|
+
return createNoPxUnitVisitors(context);
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
export default noPxUnitRule;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
import { processRecipeProperties } from '../shared-utils/recipe-property-processor.js';
|
|
3
|
+
import { ReferenceTracker, createReferenceTrackingVisitor } from '../shared-utils/reference-tracker.js';
|
|
4
|
+
import { processStyleNode } from '../shared-utils/style-node-processor.js';
|
|
5
|
+
import { processNoPxUnitInStyleObject } from './processor.js';
|
|
6
|
+
export const createNoPxUnitVisitors = (context) => {
|
|
7
|
+
const tracker = new ReferenceTracker();
|
|
8
|
+
const trackingVisitor = createReferenceTrackingVisitor(tracker);
|
|
9
|
+
const options = context.options?.[0] || {};
|
|
10
|
+
const allowSet = new Set((options.allow ?? []).map((s) => s));
|
|
11
|
+
const process = (ctx, obj) => processNoPxUnitInStyleObject(ctx, obj, allowSet);
|
|
12
|
+
return {
|
|
13
|
+
...trackingVisitor,
|
|
14
|
+
CallExpression(node) {
|
|
15
|
+
if (node.callee.type !== AST_NODE_TYPES.Identifier)
|
|
16
|
+
return;
|
|
17
|
+
const functionName = node.callee.name;
|
|
18
|
+
if (!tracker.isTrackedFunction(functionName))
|
|
19
|
+
return;
|
|
20
|
+
const originalName = tracker.getOriginalName(functionName);
|
|
21
|
+
if (!originalName)
|
|
22
|
+
return;
|
|
23
|
+
switch (originalName) {
|
|
24
|
+
case 'fontFace':
|
|
25
|
+
if (node.arguments.length > 0 && node.arguments[0]?.type === AST_NODE_TYPES.ObjectExpression) {
|
|
26
|
+
process(context, node.arguments[0]);
|
|
27
|
+
}
|
|
28
|
+
break;
|
|
29
|
+
case 'globalFontFace':
|
|
30
|
+
if (node.arguments.length > 1 && node.arguments[1]?.type === AST_NODE_TYPES.ObjectExpression) {
|
|
31
|
+
process(context, node.arguments[1]);
|
|
32
|
+
}
|
|
33
|
+
break;
|
|
34
|
+
case 'style':
|
|
35
|
+
case 'styleVariants':
|
|
36
|
+
case 'keyframes':
|
|
37
|
+
if (node.arguments.length > 0) {
|
|
38
|
+
processStyleNode(context, node.arguments[0], (ctx, obj) => process(ctx, obj));
|
|
39
|
+
}
|
|
40
|
+
break;
|
|
41
|
+
case 'globalStyle':
|
|
42
|
+
case 'globalKeyframes':
|
|
43
|
+
if (node.arguments.length >= 2) {
|
|
44
|
+
processStyleNode(context, node.arguments[1], (ctx, obj) => process(ctx, obj));
|
|
45
|
+
}
|
|
46
|
+
break;
|
|
47
|
+
case 'recipe':
|
|
48
|
+
if (node.arguments.length > 0 && node.arguments[0]?.type === AST_NODE_TYPES.ObjectExpression) {
|
|
49
|
+
processRecipeProperties(context, node.arguments[0], (ctx, obj) => process(ctx, obj));
|
|
50
|
+
}
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
import tsParser from '@typescript-eslint/parser';
|
|
2
|
+
import { run } from 'eslint-vitest-rule-tester';
|
|
3
|
+
import noTrailingZeroRule from '../rule-definition.js';
|
|
4
|
+
run({
|
|
5
|
+
name: 'vanilla-extract/no-trailing-zero',
|
|
6
|
+
rule: noTrailingZeroRule,
|
|
7
|
+
languageOptions: {
|
|
8
|
+
parser: tsParser,
|
|
9
|
+
parserOptions: {
|
|
10
|
+
ecmaVersion: 2022,
|
|
11
|
+
sourceType: 'module',
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
valid: [
|
|
15
|
+
{
|
|
16
|
+
code: `
|
|
17
|
+
import { style } from '@vanilla-extract/css';
|
|
18
|
+
const myStyle = style({
|
|
19
|
+
margin: '0',
|
|
20
|
+
padding: '1px',
|
|
21
|
+
width: '1.5rem',
|
|
22
|
+
height: '0.5em',
|
|
23
|
+
fontSize: '2rem',
|
|
24
|
+
});
|
|
25
|
+
`,
|
|
26
|
+
name: 'should allow values without trailing zeros',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
code: `
|
|
30
|
+
import { style } from '@vanilla-extract/css';
|
|
31
|
+
const myStyle = style({
|
|
32
|
+
margin: 0,
|
|
33
|
+
padding: 1,
|
|
34
|
+
opacity: 0.5,
|
|
35
|
+
lineHeight: 1.5,
|
|
36
|
+
});
|
|
37
|
+
`,
|
|
38
|
+
name: 'should allow numeric literals without trailing zeros',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
code: `
|
|
42
|
+
import { recipe } from '@vanilla-extract/css';
|
|
43
|
+
const myRecipe = recipe({
|
|
44
|
+
base: {
|
|
45
|
+
margin: '1px',
|
|
46
|
+
padding: '0.5rem',
|
|
47
|
+
},
|
|
48
|
+
variants: {
|
|
49
|
+
size: {
|
|
50
|
+
small: {
|
|
51
|
+
height: '10px',
|
|
52
|
+
width: '0.75em',
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
`,
|
|
58
|
+
name: 'should allow recipe values without trailing zeros',
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
code: `
|
|
62
|
+
import { style } from '@vanilla-extract/css';
|
|
63
|
+
const myStyle = style({
|
|
64
|
+
...spreadProps,
|
|
65
|
+
margin: '1px',
|
|
66
|
+
'@media': {
|
|
67
|
+
'1.0rem': '0.5rem' // Key shouldn't be checked
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
`,
|
|
71
|
+
name: 'should ignore spread elements and object keys',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
code: `
|
|
75
|
+
import { style } from '@vanilla-extract/css';
|
|
76
|
+
const myStyle = style({
|
|
77
|
+
margin: \`1.0\${someUnit}\`, // Template literal
|
|
78
|
+
padding: someVariable,
|
|
79
|
+
width: calculateWidth(),
|
|
80
|
+
});
|
|
81
|
+
`,
|
|
82
|
+
name: 'should ignore non-literal values',
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
code: `
|
|
86
|
+
import { globalStyle } from '@vanilla-extract/css';
|
|
87
|
+
const callExpression = someObject.fontFace({ src: '...' }); // Non-Identifier callee
|
|
88
|
+
`,
|
|
89
|
+
name: 'should ignore member expression callees',
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
code: `
|
|
93
|
+
import { fontFace } from '@vanilla-extract/css';
|
|
94
|
+
fontFace(); // Missing arguments
|
|
95
|
+
`,
|
|
96
|
+
name: 'should handle missing fontFace arguments',
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
code: `
|
|
100
|
+
import { globalFontFace } from '@vanilla-extract/css';
|
|
101
|
+
globalFontFace('my-font'); // Missing style argument
|
|
102
|
+
`,
|
|
103
|
+
name: 'should handle missing globalFontFace style argument',
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
code: `
|
|
107
|
+
import { style } from '@vanilla-extract/css';
|
|
108
|
+
const myStyle = style({
|
|
109
|
+
margin: '10px',
|
|
110
|
+
padding: '100rem',
|
|
111
|
+
width: '1000%',
|
|
112
|
+
});
|
|
113
|
+
`,
|
|
114
|
+
name: 'should allow integers without decimal points',
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
code: `
|
|
118
|
+
import { style } from '@vanilla-extract/css';
|
|
119
|
+
const myStyle = style({
|
|
120
|
+
margin: '11.01rem',
|
|
121
|
+
padding: '2.05em',
|
|
122
|
+
width: '0.101%',
|
|
123
|
+
height: '10.001px',
|
|
124
|
+
});
|
|
125
|
+
`,
|
|
126
|
+
name: 'should not flag zeros in the middle of decimal numbers',
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
invalid: [
|
|
130
|
+
{
|
|
131
|
+
code: `
|
|
132
|
+
import { style } from '@vanilla-extract/css';
|
|
133
|
+
const myStyle = style({
|
|
134
|
+
margin: '1.0px',
|
|
135
|
+
padding: '2.50rem',
|
|
136
|
+
});
|
|
137
|
+
`,
|
|
138
|
+
errors: [{ messageId: 'trailingZero' }, { messageId: 'trailingZero' }],
|
|
139
|
+
output: `
|
|
140
|
+
import { style } from '@vanilla-extract/css';
|
|
141
|
+
const myStyle = style({
|
|
142
|
+
margin: '1px',
|
|
143
|
+
padding: '2.5rem',
|
|
144
|
+
});
|
|
145
|
+
`,
|
|
146
|
+
name: 'should fix trailing zeros in string values with units',
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
code: `
|
|
150
|
+
import { style } from '@vanilla-extract/css';
|
|
151
|
+
const myStyle = style({
|
|
152
|
+
opacity: 1.0,
|
|
153
|
+
lineHeight: 2.50,
|
|
154
|
+
});
|
|
155
|
+
`,
|
|
156
|
+
errors: [{ messageId: 'trailingZero' }, { messageId: 'trailingZero' }],
|
|
157
|
+
output: `
|
|
158
|
+
import { style } from '@vanilla-extract/css';
|
|
159
|
+
const myStyle = style({
|
|
160
|
+
opacity: 1,
|
|
161
|
+
lineHeight: 2.5,
|
|
162
|
+
});
|
|
163
|
+
`,
|
|
164
|
+
name: 'should fix trailing zeros in numeric literals',
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
code: `
|
|
168
|
+
import { style } from '@vanilla-extract/css';
|
|
169
|
+
const myStyle = style({
|
|
170
|
+
margin: '0.0',
|
|
171
|
+
padding: '0.00px',
|
|
172
|
+
width: '0.0rem',
|
|
173
|
+
});
|
|
174
|
+
`,
|
|
175
|
+
errors: [{ messageId: 'trailingZero' }, { messageId: 'trailingZero' }, { messageId: 'trailingZero' }],
|
|
176
|
+
output: `
|
|
177
|
+
import { style } from '@vanilla-extract/css';
|
|
178
|
+
const myStyle = style({
|
|
179
|
+
margin: '0',
|
|
180
|
+
padding: '0',
|
|
181
|
+
width: '0',
|
|
182
|
+
});
|
|
183
|
+
`,
|
|
184
|
+
name: 'should convert 0.0 to 0',
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
code: `
|
|
188
|
+
import { recipe } from '@vanilla-extract/css';
|
|
189
|
+
const myRecipe = recipe({
|
|
190
|
+
base: {
|
|
191
|
+
margin: '1.0px',
|
|
192
|
+
},
|
|
193
|
+
variants: {
|
|
194
|
+
size: {
|
|
195
|
+
small: {
|
|
196
|
+
height: '2.50vh',
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
`,
|
|
202
|
+
errors: [{ messageId: 'trailingZero' }, { messageId: 'trailingZero' }],
|
|
203
|
+
output: `
|
|
204
|
+
import { recipe } from '@vanilla-extract/css';
|
|
205
|
+
const myRecipe = recipe({
|
|
206
|
+
base: {
|
|
207
|
+
margin: '1px',
|
|
208
|
+
},
|
|
209
|
+
variants: {
|
|
210
|
+
size: {
|
|
211
|
+
small: {
|
|
212
|
+
height: '2.5vh',
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
`,
|
|
218
|
+
name: 'should handle recipe trailing zeros',
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
code: `
|
|
222
|
+
import { style } from '@vanilla-extract/css';
|
|
223
|
+
const myStyle = style({
|
|
224
|
+
margin: '1.0px',
|
|
225
|
+
'@media': {
|
|
226
|
+
'(min-width: 768px)': {
|
|
227
|
+
padding: '2.50rem'
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
`,
|
|
232
|
+
errors: 2,
|
|
233
|
+
output: `
|
|
234
|
+
import { style } from '@vanilla-extract/css';
|
|
235
|
+
const myStyle = style({
|
|
236
|
+
margin: '1px',
|
|
237
|
+
'@media': {
|
|
238
|
+
'(min-width: 768px)': {
|
|
239
|
+
padding: '2.5rem'
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
`,
|
|
244
|
+
name: 'should handle nested media queries',
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
code: `
|
|
248
|
+
import { style } from '@vanilla-extract/css';
|
|
249
|
+
const myStyle = style({
|
|
250
|
+
'::before': {
|
|
251
|
+
content: '""',
|
|
252
|
+
margin: '1.0px'
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
`,
|
|
256
|
+
errors: 1,
|
|
257
|
+
output: `
|
|
258
|
+
import { style } from '@vanilla-extract/css';
|
|
259
|
+
const myStyle = style({
|
|
260
|
+
'::before': {
|
|
261
|
+
content: '""',
|
|
262
|
+
margin: '1px'
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
`,
|
|
266
|
+
name: 'should handle pseudo-elements',
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
code: `
|
|
270
|
+
import { style } from '@vanilla-extract/css';
|
|
271
|
+
const myStyle = style({
|
|
272
|
+
margin: '1.0px',
|
|
273
|
+
nested: {
|
|
274
|
+
object: {
|
|
275
|
+
padding: '2.50rem',
|
|
276
|
+
deeper: {
|
|
277
|
+
width: '3.00%'
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
`,
|
|
283
|
+
errors: 3,
|
|
284
|
+
output: `
|
|
285
|
+
import { style } from '@vanilla-extract/css';
|
|
286
|
+
const myStyle = style({
|
|
287
|
+
margin: '1px',
|
|
288
|
+
nested: {
|
|
289
|
+
object: {
|
|
290
|
+
padding: '2.5rem',
|
|
291
|
+
deeper: {
|
|
292
|
+
width: '3%'
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
`,
|
|
298
|
+
name: 'should handle multiple levels of nesting',
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
code: `
|
|
302
|
+
import { fontFace, globalFontFace } from '@vanilla-extract/css';
|
|
303
|
+
|
|
304
|
+
fontFace({
|
|
305
|
+
src: '...',
|
|
306
|
+
lineGap: '1.0rem'
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
globalFontFace('my-font', {
|
|
310
|
+
src: '...',
|
|
311
|
+
sizeAdjust: '100.0%'
|
|
312
|
+
});
|
|
313
|
+
`,
|
|
314
|
+
errors: 2,
|
|
315
|
+
output: `
|
|
316
|
+
import { fontFace, globalFontFace } from '@vanilla-extract/css';
|
|
317
|
+
|
|
318
|
+
fontFace({
|
|
319
|
+
src: '...',
|
|
320
|
+
lineGap: '1rem'
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
globalFontFace('my-font', {
|
|
324
|
+
src: '...',
|
|
325
|
+
sizeAdjust: '100%'
|
|
326
|
+
});
|
|
327
|
+
`,
|
|
328
|
+
name: 'should handle fontFace and globalFontFace arguments',
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
code: `
|
|
332
|
+
import { globalKeyframes, globalStyle } from '@vanilla-extract/css';
|
|
333
|
+
|
|
334
|
+
globalKeyframes('spin', {
|
|
335
|
+
'0%': { transform: 'rotate(0deg)' },
|
|
336
|
+
'100%': { transform: 'rotate(360.0deg)' }
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
globalStyle('html', {
|
|
340
|
+
margin: '1.0px',
|
|
341
|
+
padding: '2.50rem'
|
|
342
|
+
});
|
|
343
|
+
`,
|
|
344
|
+
errors: 3,
|
|
345
|
+
output: `
|
|
346
|
+
import { globalKeyframes, globalStyle } from '@vanilla-extract/css';
|
|
347
|
+
|
|
348
|
+
globalKeyframes('spin', {
|
|
349
|
+
'0%': { transform: 'rotate(0deg)' },
|
|
350
|
+
'100%': { transform: 'rotate(360deg)' }
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
globalStyle('html', {
|
|
354
|
+
margin: '1px',
|
|
355
|
+
padding: '2.5rem'
|
|
356
|
+
});
|
|
357
|
+
`,
|
|
358
|
+
name: 'should handle globalKeyframes and globalStyle arguments',
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
code: `
|
|
362
|
+
import { globalStyle } from '@vanilla-extract/css';
|
|
363
|
+
globalStyle('html', {
|
|
364
|
+
'@media': {
|
|
365
|
+
'(min-width: 768px)': {
|
|
366
|
+
margin: '1.0px'
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
`,
|
|
371
|
+
errors: 1,
|
|
372
|
+
output: `
|
|
373
|
+
import { globalStyle } from '@vanilla-extract/css';
|
|
374
|
+
globalStyle('html', {
|
|
375
|
+
'@media': {
|
|
376
|
+
'(min-width: 768px)': {
|
|
377
|
+
margin: '1px'
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
`,
|
|
382
|
+
name: 'should handle nested globalStyle arguments',
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
code: `
|
|
386
|
+
import { style } from '@vanilla-extract/css';
|
|
387
|
+
const myStyle = style({
|
|
388
|
+
margin: '-1.0px',
|
|
389
|
+
padding: '-2.50rem',
|
|
390
|
+
top: '-0.0vh',
|
|
391
|
+
});
|
|
392
|
+
`,
|
|
393
|
+
errors: [{ messageId: 'trailingZero' }, { messageId: 'trailingZero' }, { messageId: 'trailingZero' }],
|
|
394
|
+
output: `
|
|
395
|
+
import { style } from '@vanilla-extract/css';
|
|
396
|
+
const myStyle = style({
|
|
397
|
+
margin: '-1px',
|
|
398
|
+
padding: '-2.5rem',
|
|
399
|
+
top: '0',
|
|
400
|
+
});
|
|
401
|
+
`,
|
|
402
|
+
name: 'should handle negative values with trailing zeros',
|
|
403
|
+
},
|
|
404
|
+
{
|
|
405
|
+
code: `
|
|
406
|
+
import { style } from '@vanilla-extract/css';
|
|
407
|
+
const myStyle = style({
|
|
408
|
+
margin: '1.50em',
|
|
409
|
+
padding: '0.50rem',
|
|
410
|
+
width: '10.00%',
|
|
411
|
+
});
|
|
412
|
+
`,
|
|
413
|
+
errors: [{ messageId: 'trailingZero' }, { messageId: 'trailingZero' }, { messageId: 'trailingZero' }],
|
|
414
|
+
output: `
|
|
415
|
+
import { style } from '@vanilla-extract/css';
|
|
416
|
+
const myStyle = style({
|
|
417
|
+
margin: '1.5em',
|
|
418
|
+
padding: '0.5rem',
|
|
419
|
+
width: '10%',
|
|
420
|
+
});
|
|
421
|
+
`,
|
|
422
|
+
name: 'should remove trailing zeros from decimal values',
|
|
423
|
+
},
|
|
424
|
+
{
|
|
425
|
+
code: `
|
|
426
|
+
import { style } from '@vanilla-extract/css';
|
|
427
|
+
const myStyle = style({
|
|
428
|
+
padding: '1.0px 2.50rem 3.00em 0.50vh',
|
|
429
|
+
});
|
|
430
|
+
`,
|
|
431
|
+
errors: 1,
|
|
432
|
+
output: `
|
|
433
|
+
import { style } from '@vanilla-extract/css';
|
|
434
|
+
const myStyle = style({
|
|
435
|
+
padding: '1px 2.5rem 3em 0.5vh',
|
|
436
|
+
});
|
|
437
|
+
`,
|
|
438
|
+
name: 'should handle multiple values in a single string',
|
|
439
|
+
},
|
|
440
|
+
{
|
|
441
|
+
code: `
|
|
442
|
+
import { style } from '@vanilla-extract/css';
|
|
443
|
+
const myStyle = style({
|
|
444
|
+
transition: 'all 0.30s ease',
|
|
445
|
+
animation: 'spin 2.0s linear',
|
|
446
|
+
});
|
|
447
|
+
`,
|
|
448
|
+
errors: 2,
|
|
449
|
+
output: `
|
|
450
|
+
import { style } from '@vanilla-extract/css';
|
|
451
|
+
const myStyle = style({
|
|
452
|
+
transition: 'all 0.3s ease',
|
|
453
|
+
animation: 'spin 2s linear',
|
|
454
|
+
});
|
|
455
|
+
`,
|
|
456
|
+
name: 'should handle time units',
|
|
457
|
+
},
|
|
458
|
+
{
|
|
459
|
+
code: `
|
|
460
|
+
import { style } from '@vanilla-extract/css';
|
|
461
|
+
const myStyle = style({
|
|
462
|
+
transform: 'rotate(45.0deg)',
|
|
463
|
+
filter: 'hue-rotate(180.00deg)',
|
|
464
|
+
});
|
|
465
|
+
`,
|
|
466
|
+
errors: 2,
|
|
467
|
+
output: `
|
|
468
|
+
import { style } from '@vanilla-extract/css';
|
|
469
|
+
const myStyle = style({
|
|
470
|
+
transform: 'rotate(45deg)',
|
|
471
|
+
filter: 'hue-rotate(180deg)',
|
|
472
|
+
});
|
|
473
|
+
`,
|
|
474
|
+
name: 'should handle angle units',
|
|
475
|
+
},
|
|
476
|
+
{
|
|
477
|
+
code: `
|
|
478
|
+
import { styleVariants } from '@vanilla-extract/css';
|
|
479
|
+
const variants = styleVariants({
|
|
480
|
+
small: { padding: '1.0px' },
|
|
481
|
+
medium: { padding: '2.50px' },
|
|
482
|
+
large: { padding: '3.00px' },
|
|
483
|
+
});
|
|
484
|
+
`,
|
|
485
|
+
errors: 3,
|
|
486
|
+
output: `
|
|
487
|
+
import { styleVariants } from '@vanilla-extract/css';
|
|
488
|
+
const variants = styleVariants({
|
|
489
|
+
small: { padding: '1px' },
|
|
490
|
+
medium: { padding: '2.5px' },
|
|
491
|
+
large: { padding: '3px' },
|
|
492
|
+
});
|
|
493
|
+
`,
|
|
494
|
+
name: 'should handle styleVariants',
|
|
495
|
+
},
|
|
496
|
+
{
|
|
497
|
+
code: `
|
|
498
|
+
import { keyframes } from '@vanilla-extract/css';
|
|
499
|
+
const spin = keyframes({
|
|
500
|
+
'0%': { transform: 'rotate(0.0deg)' },
|
|
501
|
+
'50%': { transform: 'rotate(180.0deg)' },
|
|
502
|
+
'100%': { transform: 'rotate(360.0deg)' },
|
|
503
|
+
});
|
|
504
|
+
`,
|
|
505
|
+
errors: 3,
|
|
506
|
+
output: `
|
|
507
|
+
import { keyframes } from '@vanilla-extract/css';
|
|
508
|
+
const spin = keyframes({
|
|
509
|
+
'0%': { transform: 'rotate(0deg)' },
|
|
510
|
+
'50%': { transform: 'rotate(180deg)' },
|
|
511
|
+
'100%': { transform: 'rotate(360deg)' },
|
|
512
|
+
});
|
|
513
|
+
`,
|
|
514
|
+
name: 'should handle keyframes',
|
|
515
|
+
},
|
|
516
|
+
{
|
|
517
|
+
code: `
|
|
518
|
+
import { style } from '@vanilla-extract/css';
|
|
519
|
+
const myStyle = style({
|
|
520
|
+
margin: '1.000px',
|
|
521
|
+
padding: '2.5000rem',
|
|
522
|
+
width: '0.00000em',
|
|
523
|
+
});
|
|
524
|
+
`,
|
|
525
|
+
errors: 3,
|
|
526
|
+
output: `
|
|
527
|
+
import { style } from '@vanilla-extract/css';
|
|
528
|
+
const myStyle = style({
|
|
529
|
+
margin: '1px',
|
|
530
|
+
padding: '2.5rem',
|
|
531
|
+
width: '0',
|
|
532
|
+
});
|
|
533
|
+
`,
|
|
534
|
+
name: 'should handle multiple trailing zeros',
|
|
535
|
+
},
|
|
536
|
+
],
|
|
537
|
+
});
|