@antebudimir/eslint-plugin-vanilla-extract 1.15.0 → 1.16.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.
Files changed (39) hide show
  1. package/README.md +73 -4
  2. package/dist/css-rules/no-empty-blocks/empty-style-visitor-creator.js +8 -2
  3. package/dist/css-rules/no-empty-blocks/recipe-processor.js +23 -3
  4. package/dist/css-rules/no-trailing-zero/index.d.ts +2 -1
  5. package/dist/css-rules/no-trailing-zero/index.js +2 -1
  6. package/dist/css-rules/no-unitless-values/_tests_/no-unitless-values.test.d.ts +1 -0
  7. package/dist/css-rules/no-unitless-values/_tests_/no-unitless-values.test.js +444 -0
  8. package/dist/css-rules/no-unitless-values/index.d.ts +2 -0
  9. package/dist/css-rules/no-unitless-values/index.js +2 -0
  10. package/dist/css-rules/no-unitless-values/rule-definition.d.ts +3 -0
  11. package/dist/css-rules/no-unitless-values/rule-definition.js +35 -0
  12. package/dist/css-rules/no-unitless-values/unitless-value-processor.d.ts +13 -0
  13. package/dist/css-rules/no-unitless-values/unitless-value-processor.js +330 -0
  14. package/dist/css-rules/no-unitless-values/unitless-value-visitor-creator.d.ts +11 -0
  15. package/dist/css-rules/{no-px-unit/visitor-creator.js → no-unitless-values/unitless-value-visitor-creator.js} +26 -13
  16. package/dist/css-rules/shared-utils/empty-object-processor.d.ts +5 -0
  17. package/dist/css-rules/shared-utils/empty-object-processor.js +11 -0
  18. package/dist/index.d.ts +1 -0
  19. package/dist/index.js +3 -1
  20. package/package.json +2 -1
  21. package/dist/css-rules/no-px-unit/no-px-unit-visitor-creator.d.ts +0 -2
  22. package/dist/css-rules/no-px-unit/no-px-unit-visitor-creator.js +0 -55
  23. package/dist/css-rules/no-px-unit/processor.d.ts +0 -3
  24. package/dist/css-rules/no-px-unit/processor.js +0 -93
  25. package/dist/css-rules/no-px-unit/visitor-creator.d.ts +0 -2
  26. package/dist/demo-bad-example.css.d.ts +0 -4
  27. package/dist/demo-bad-example.css.js +0 -45
  28. package/dist/demo-good-example.css.d.ts +0 -5
  29. package/dist/demo-good-example.css.js +0 -48
  30. package/dist/demo-theme.css.d.ts +0 -37
  31. package/dist/demo-theme.css.js +0 -39
  32. package/dist/sample-bad.css.d.ts +0 -26
  33. package/dist/sample-bad.css.js +0 -85
  34. package/dist/sample-good.css.d.ts +0 -27
  35. package/dist/sample-good.css.js +0 -94
  36. package/dist/sample-theme.css.d.ts +0 -37
  37. package/dist/sample-theme.css.js +0 -38
  38. package/dist/sample.css.d.ts +0 -75
  39. package/dist/sample.css.js +0 -530
package/README.md CHANGED
@@ -264,6 +264,7 @@ The recommended configuration enables the following rules with error severity:
264
264
  - `vanilla-extract/alphabetical-order`: Alternative ordering rule (alphabetical sorting)
265
265
  - `vanilla-extract/custom-order`: Alternative ordering rule (custom group-based sorting)
266
266
  - `vanilla-extract/no-px-unit`: Disallows px units with an optional allowlist
267
+ - `vanilla-extract/no-unitless-values`: Disallows unitless numeric values for CSS properties that require units
267
268
  - `vanilla-extract/prefer-logical-properties`: Enforces logical CSS properties over physical directional properties
268
269
  - `vanilla-extract/prefer-theme-tokens`: Enforces theme tokens instead of hard-coded values for colors, spacing, font sizes, border radius, border widths, shadows, z-index, opacity, font weights, and transitions/animations (optionally evaluates helper functions and template literals)
269
270
 
@@ -536,6 +537,77 @@ export const myStyle = style({
536
537
  });
537
538
  ```
538
539
 
540
+ ### vanilla-extract/no-unitless-values
541
+
542
+ This rule disallows unitless numeric values for CSS properties that require units in vanilla-extract style objects. It helps teams that prefer explicit units avoid confusion, as vanilla-extract automatically converts unitless numbers to `px` at runtime.
543
+
544
+ **Note:** This is an optional rule (not enabled in recommended config). Enable it only if your team prefers explicit units over vanilla-extract's automatic `px` conversion.
545
+
546
+ Configuration with allowed properties:
547
+
548
+ ```json
549
+ {
550
+ "rules": {
551
+ "vanilla-extract/no-unitless-values": ["warn", { "allow": ["width", "height"] }]
552
+ }
553
+ }
554
+ ```
555
+
556
+ ```typescript
557
+ // ❌ Incorrect
558
+ import { style } from '@vanilla-extract/css';
559
+
560
+ export const myStyle = style({
561
+ width: 100,
562
+ margin: 20,
563
+ padding: 10.5,
564
+ height: '50',
565
+ top: '-10',
566
+ });
567
+
568
+ // ✅ Correct
569
+ import { style } from '@vanilla-extract/css';
570
+
571
+ export const myStyle = style({
572
+ width: '100px',
573
+ margin: '20px',
574
+ padding: 0,
575
+ height: '50rem',
576
+ opacity: 0.5, // opacity accepts unitless values
577
+ lineHeight: 1.5, // line-height accepts unitless values
578
+ zIndex: 10, // z-index accepts unitless values
579
+ });
580
+ ```
581
+
582
+ **Properties that require units:**
583
+
584
+ - **Box model:** `width`, `height`, `minWidth`, `maxWidth`, `minHeight`, `maxHeight`, `min-width`, `max-width`, `min-height`, `max-height`
585
+ - **Spacing:** `margin`, `marginTop`, `marginRight`, `marginBottom`, `marginLeft`, `marginBlock`, `marginBlockStart`, `marginBlockEnd`, `marginInline`, `marginInlineStart`, `marginInlineEnd`, `margin-top`, `margin-right`, `margin-bottom`, `margin-left`, `margin-block`, `margin-block-start`, `margin-block-end`, `margin-inline`, `margin-inline-start`, `margin-inline-end`, `padding`, `paddingTop`, `paddingRight`, `paddingBottom`, `paddingLeft`, `paddingBlock`, `paddingBlockStart`, `paddingBlockEnd`, `paddingInline`, `paddingInlineStart`, `paddingInlineEnd`, `padding-top`, `padding-right`, `padding-bottom`, `padding-left`, `padding-block`, `padding-block-start`, `padding-block-end`, `padding-inline`, `padding-inline-start`, `padding-inline-end`
586
+ - **Positioning:** `top`, `right`, `bottom`, `left`, `inset`, `insetBlock`, `insetBlockStart`, `insetBlockEnd`, `insetInline`, `insetInlineStart`, `insetInlineEnd`, `inset-block`, `inset-block-start`, `inset-block-end`, `inset-inline`, `inset-inline-start`, `inset-inline-end`
587
+ - **Border:** `borderWidth`, `borderTopWidth`, `borderRightWidth`, `borderBottomWidth`, `borderLeftWidth`, `borderBlockWidth`, `borderBlockStartWidth`, `borderBlockEndWidth`, `borderInlineWidth`, `borderInlineStartWidth`, `borderInlineEndWidth`, `border-width`, `border-top-width`, `border-right-width`, `border-bottom-width`, `border-left-width`, `border-block-width`, `border-block-start-width`, `border-block-end-width`, `border-inline-width`, `border-inline-start-width`, `border-inline-end-width`, `borderRadius`, `borderTopLeftRadius`, `borderTopRightRadius`, `borderBottomLeftRadius`, `borderBottomRightRadius`, `borderStartStartRadius`, `borderStartEndRadius`, `borderEndStartRadius`, `borderEndEndRadius`, `border-radius`, `border-top-left-radius`, `border-top-right-radius`, `border-bottom-left-radius`, `border-bottom-right-radius`, `border-start-start-radius`, `border-start-end-radius`, `border-end-start-radius`, `border-end-end-radius`
588
+ - **Typography:** `fontSize`, `font-size`, `letterSpacing`, `letter-spacing`, `wordSpacing`, `word-spacing`, `textIndent`, `text-indent`
589
+ - **Layout:** `gap`, `rowGap`, `columnGap`, `row-gap`, `column-gap`, `flexBasis`, `flex-basis`
590
+ - **Outline:** `outlineWidth`, `outline-width`, `outlineOffset`, `outline-offset`
591
+ - **Other:** `blockSize`, `inlineSize`, `minBlockSize`, `maxBlockSize`, `minInlineSize`, `maxInlineSize`, `block-size`, `inline-size`, `min-block-size`, `max-block-size`, `min-inline-size`, `max-inline-size`
592
+
593
+ **Properties that accept unitless values:**
594
+
595
+ - **Common:** `opacity`, `zIndex`, `z-index`, `lineHeight`, `line-height`, `flexGrow`, `flex-grow`, `flexShrink`, `flex-shrink`, `order`, `fontWeight`, `font-weight`, `zoom`
596
+ - **Animation:** `animationIterationCount`, `animation-iteration-count`
597
+ - **Layout:** `columnCount`, `column-count`, `orphans`, `widows`
598
+ - **Grid:** `gridColumn`, `grid-column`, `gridColumnEnd`, `grid-column-end`, `gridColumnStart`, `grid-column-start`, `gridRow`, `grid-row`, `gridRowEnd`, `grid-row-end`, `gridRowStart`, `grid-row-start`
599
+ - **SVG:** `fillOpacity`, `fill-opacity`, `strokeOpacity`, `stroke-opacity`, `strokeMiterlimit`, `stroke-miterlimit`
600
+
601
+ **Why use this rule?**
602
+
603
+ While vanilla-extract safely converts unitless numbers to `px`, some teams prefer explicit units because:
604
+
605
+ 1. It makes the intended unit clear (px, rem, em, %, etc.)
606
+ 2. It prevents accidental use of px when rem or other units are preferred
607
+ 3. It aligns with CSS best practices of being explicit about units
608
+
609
+ **Auto-fix:** Not available. Since different teams prefer different units (px, rem, em, %), you must manually add your preferred unit.
610
+
539
611
  ### vanilla-extract/no-unknown-unit
540
612
 
541
613
  This rule enforces the use of valid CSS units in vanilla-extract style objects. It prevents typos and non-standard units
@@ -835,10 +907,7 @@ The roadmap outlines the project's current status and future plans:
835
907
  - `no-px-unit` rule to disallow use of `px` units with configurable whitelist.
836
908
  - `prefer-logical-properties` rule to enforce use of logical properties.
837
909
  - `prefer-theme-tokens` rule to enforce theme tokens instead of hard-coded values for colors, spacing, font sizes, border radius, border widths, shadows, z-index, opacity, font weights, and transitions/animations (optionally evaluates helper functions and template literals).
838
-
839
- ### Current Work
840
-
841
- - `no-unitless-values` rule that disallows numeric literals for CSS properties that are not unitless in CSS.
910
+ - `no-unitless-values` rule to disallow unitless numeric values for CSS properties that require units.
842
911
 
843
912
  ### Upcoming Features
844
913
 
@@ -1,5 +1,5 @@
1
1
  import { TSESTree } from '@typescript-eslint/utils';
2
- import { isEmptyObject } from '../shared-utils/empty-object-processor.js';
2
+ import { isCallExpressionWithEmptyObject, isEmptyObject } from '../shared-utils/empty-object-processor.js';
3
3
  import { ReferenceTracker, createReferenceTrackingVisitor } from '../shared-utils/reference-tracker.js';
4
4
  import { processConditionalExpression } from './conditional-processor.js';
5
5
  import { processEmptyNestedStyles } from './empty-nested-style-processor.js';
@@ -48,7 +48,13 @@ export const isEffectivelyEmptyStylesObject = (stylesObject) => {
48
48
  }
49
49
  if (propertyName === 'base') {
50
50
  hasBaseProperty = true;
51
- if (property.value.type === 'ObjectExpression' && !isEmptyObject(property.value)) {
51
+ // CallExpression (e.g., sprinkles(), style()) is considered non-empty unless it has an empty object argument, e.g. sprinkles({})
52
+ if (property.value.type === 'CallExpression') {
53
+ if (!isCallExpressionWithEmptyObject(property.value)) {
54
+ isBaseEmpty = false;
55
+ }
56
+ }
57
+ else if (property.value.type === 'ObjectExpression' && !isEmptyObject(property.value)) {
52
58
  isBaseEmpty = false;
53
59
  }
54
60
  }
@@ -1,5 +1,5 @@
1
1
  import { TSESTree } from '@typescript-eslint/utils';
2
- import { isEmptyObject } from '../shared-utils/empty-object-processor.js';
2
+ import { isCallExpressionWithEmptyObject, isEmptyObject } from '../shared-utils/empty-object-processor.js';
3
3
  import { processEmptyNestedStyles } from './empty-nested-style-processor.js';
4
4
  import { removeNodeWithComma } from './node-remover.js';
5
5
  import { areAllChildrenEmpty, getStyleKeyName } from './property-utils.js';
@@ -71,8 +71,28 @@ export const processRecipeProperties = (ruleContext, recipeNode, reportedNodes)
71
71
  if (variantValueProperty.type !== 'Property') {
72
72
  return;
73
73
  }
74
- // Check for non-object variant values
75
- if (variantValueProperty.value.type !== 'ObjectExpression') {
74
+ const valueType = variantValueProperty.value.type;
75
+ // Allow CallExpression (e.g., sprinkles(), style()) as valid variant values unless it has an empty object argument, e.g. sprinkles({})
76
+ if (valueType === 'CallExpression') {
77
+ const callExpression = variantValueProperty.value;
78
+ if (isCallExpressionWithEmptyObject(callExpression)) {
79
+ // Treat sprinkles({}) or style({}) as empty
80
+ if (!reportedNodes.has(variantValueProperty)) {
81
+ reportedNodes.add(variantValueProperty);
82
+ ruleContext.report({
83
+ node: variantValueProperty,
84
+ messageId: 'emptyVariantValue',
85
+ fix(fixer) {
86
+ return removeNodeWithComma(ruleContext, variantValueProperty, fixer);
87
+ },
88
+ });
89
+ }
90
+ }
91
+ // Valid CallExpressions with arguments are fine
92
+ return;
93
+ }
94
+ // Check for non-object variant values (excluding CallExpression)
95
+ if (valueType !== 'ObjectExpression') {
76
96
  if (!reportedNodes.has(variantValueProperty)) {
77
97
  reportedNodes.add(variantValueProperty);
78
98
  // Get a user-friendly type description as a string
@@ -1 +1,2 @@
1
- export { default } from './rule-definition.js';
1
+ import noTrailingZeroRule from './rule-definition.js';
2
+ export default noTrailingZeroRule;
@@ -1 +1,2 @@
1
- export { default } from './rule-definition.js';
1
+ import noTrailingZeroRule from './rule-definition.js';
2
+ export default noTrailingZeroRule;
@@ -0,0 +1,444 @@
1
+ import tsParser from '@typescript-eslint/parser';
2
+ import { run } from 'eslint-vitest-rule-tester';
3
+ import noUnitlessValuesRule from '../rule-definition.js';
4
+ run({
5
+ name: 'vanilla-extract/no-unitless-values',
6
+ rule: noUnitlessValuesRule,
7
+ languageOptions: {
8
+ parser: tsParser,
9
+ parserOptions: {
10
+ ecmaVersion: 2022,
11
+ sourceType: 'module',
12
+ },
13
+ },
14
+ valid: [
15
+ // Zero values are allowed
16
+ {
17
+ code: `
18
+ import { style } from '@vanilla-extract/css';
19
+ const myStyle = style({
20
+ margin: 0,
21
+ padding: 0,
22
+ width: 0,
23
+ });
24
+ `,
25
+ name: 'should allow zero values without units',
26
+ },
27
+ // String values with units
28
+ {
29
+ code: `
30
+ import { style } from '@vanilla-extract/css';
31
+ const myStyle = style({
32
+ width: '100px',
33
+ margin: '20px',
34
+ padding: '1rem',
35
+ fontSize: '16px',
36
+ });
37
+ `,
38
+ name: 'should allow string values with units',
39
+ },
40
+ // String zero values
41
+ {
42
+ code: `
43
+ import { style } from '@vanilla-extract/css';
44
+ const myStyle = style({
45
+ margin: '0',
46
+ padding: '0',
47
+ });
48
+ `,
49
+ name: 'should allow string zero values without units',
50
+ },
51
+ // Unitless-valid properties
52
+ {
53
+ code: `
54
+ import { style } from '@vanilla-extract/css';
55
+ const myStyle = style({
56
+ opacity: 0.5,
57
+ zIndex: 10,
58
+ lineHeight: 1.5,
59
+ flexGrow: 1,
60
+ flexShrink: 0,
61
+ order: 2,
62
+ fontWeight: 700,
63
+ zoom: 1.2,
64
+ });
65
+ `,
66
+ name: 'should allow unitless values for properties that accept them',
67
+ },
68
+ // Recipe with valid values
69
+ {
70
+ code: `
71
+ import { recipe } from '@vanilla-extract/css';
72
+ const myRecipe = recipe({
73
+ base: {
74
+ margin: '0',
75
+ padding: 0,
76
+ opacity: 0.8,
77
+ },
78
+ variants: {
79
+ size: {
80
+ small: {
81
+ height: '10px',
82
+ width: '10px',
83
+ zIndex: 1,
84
+ },
85
+ },
86
+ },
87
+ });
88
+ `,
89
+ name: 'should allow valid values in recipe',
90
+ },
91
+ // Template literals (not checked)
92
+ {
93
+ code: `
94
+ import { style } from '@vanilla-extract/css';
95
+ const myStyle = style({
96
+ margin: \`\${someValue}px\`,
97
+ padding: someVariable,
98
+ });
99
+ `,
100
+ name: 'should ignore template literals and variables',
101
+ },
102
+ // Nested selectors with valid values
103
+ {
104
+ code: `
105
+ import { style } from '@vanilla-extract/css';
106
+ const myStyle = style({
107
+ width: '100px',
108
+ ':hover': {
109
+ margin: '20px',
110
+ opacity: 0.8,
111
+ },
112
+ });
113
+ `,
114
+ name: 'should allow valid values in nested selectors',
115
+ },
116
+ // Media queries with valid values
117
+ {
118
+ code: `
119
+ import { style } from '@vanilla-extract/css';
120
+ const myStyle = style({
121
+ margin: 0,
122
+ '@media': {
123
+ '(min-width: 768px)': {
124
+ padding: '20px',
125
+ zIndex: 10,
126
+ }
127
+ }
128
+ });
129
+ `,
130
+ name: 'should allow valid values in media queries',
131
+ },
132
+ // globalStyle with valid values
133
+ {
134
+ code: `
135
+ import { globalStyle } from '@vanilla-extract/css';
136
+ globalStyle('html', {
137
+ margin: '0',
138
+ padding: 0,
139
+ lineHeight: 1.5,
140
+ });
141
+ `,
142
+ name: 'should allow valid values in globalStyle',
143
+ },
144
+ // fontFace with valid values
145
+ {
146
+ code: `
147
+ import { fontFace } from '@vanilla-extract/css';
148
+ fontFace({
149
+ src: 'url(...)',
150
+ fontWeight: 400,
151
+ });
152
+ `,
153
+ name: 'should allow valid values in fontFace',
154
+ },
155
+ // keyframes (animation values are strings)
156
+ {
157
+ code: `
158
+ import { keyframes } from '@vanilla-extract/css';
159
+ const spin = keyframes({
160
+ '0%': { transform: 'rotate(0deg)' },
161
+ '100%': { transform: 'rotate(360deg)' }
162
+ });
163
+ `,
164
+ name: 'should allow keyframes with string values',
165
+ },
166
+ // allow option
167
+ {
168
+ code: `
169
+ import { style } from '@vanilla-extract/css';
170
+ const myStyle = style({
171
+ width: 100,
172
+ margin: '20px',
173
+ });
174
+ `,
175
+ options: [{ allow: ['width'] }],
176
+ name: 'should allow properties specified in allow option',
177
+ },
178
+ // Kebab-case unitless-valid properties
179
+ {
180
+ code: `
181
+ import { style } from '@vanilla-extract/css';
182
+ const myStyle = style({
183
+ 'z-index': 10,
184
+ 'line-height': 1.5,
185
+ 'flex-grow': 1,
186
+ });
187
+ `,
188
+ name: 'should allow unitless values for kebab-case unitless-valid properties',
189
+ },
190
+ ],
191
+ invalid: [
192
+ // Basic unitless values
193
+ {
194
+ code: `
195
+ import { style } from '@vanilla-extract/css';
196
+ const myStyle = style({
197
+ width: 100,
198
+ margin: 20,
199
+ });
200
+ `,
201
+ errors: [
202
+ { messageId: 'noUnitlessValue', data: { property: 'width', value: '100' } },
203
+ { messageId: 'noUnitlessValue', data: { property: 'margin', value: '20' } },
204
+ ],
205
+ name: 'should flag unitless numeric values for length properties',
206
+ },
207
+ // Decimal values
208
+ {
209
+ code: `
210
+ import { style } from '@vanilla-extract/css';
211
+ const myStyle = style({
212
+ padding: 10.5,
213
+ fontSize: 16.5,
214
+ });
215
+ `,
216
+ errors: [
217
+ { messageId: 'noUnitlessValue', data: { property: 'padding', value: '10.5' } },
218
+ { messageId: 'noUnitlessValue', data: { property: 'fontSize', value: '16.5' } },
219
+ ],
220
+ name: 'should flag decimal unitless values',
221
+ },
222
+ // Recipe with unitless values
223
+ {
224
+ code: `
225
+ import { recipe } from '@vanilla-extract/css';
226
+ const myRecipe = recipe({
227
+ base: {
228
+ margin: 10,
229
+ },
230
+ variants: {
231
+ size: {
232
+ small: {
233
+ height: 20,
234
+ },
235
+ },
236
+ },
237
+ });
238
+ `,
239
+ errors: [
240
+ { messageId: 'noUnitlessValue', data: { property: 'margin', value: '10' } },
241
+ { messageId: 'noUnitlessValue', data: { property: 'height', value: '20' } },
242
+ ],
243
+ name: 'should flag unitless values in recipe',
244
+ },
245
+ // Nested selectors with unitless values
246
+ {
247
+ code: `
248
+ import { style } from '@vanilla-extract/css';
249
+ const myStyle = style({
250
+ width: 100,
251
+ ':hover': {
252
+ margin: 20,
253
+ },
254
+ });
255
+ `,
256
+ errors: [
257
+ { messageId: 'noUnitlessValue', data: { property: 'width', value: '100' } },
258
+ { messageId: 'noUnitlessValue', data: { property: 'margin', value: '20' } },
259
+ ],
260
+ name: 'should flag unitless values in nested selectors',
261
+ },
262
+ // Media queries with unitless values
263
+ {
264
+ code: `
265
+ import { style } from '@vanilla-extract/css';
266
+ const myStyle = style({
267
+ '@media': {
268
+ '(min-width: 768px)': {
269
+ padding: 20,
270
+ }
271
+ }
272
+ });
273
+ `,
274
+ errors: [{ messageId: 'noUnitlessValue', data: { property: 'padding', value: '20' } }],
275
+ name: 'should flag unitless values in media queries',
276
+ },
277
+ // Multiple levels of nesting
278
+ {
279
+ code: `
280
+ import { style } from '@vanilla-extract/css';
281
+ const myStyle = style({
282
+ margin: 10,
283
+ nested: {
284
+ object: {
285
+ padding: 20,
286
+ deeper: {
287
+ width: 30
288
+ }
289
+ }
290
+ }
291
+ });
292
+ `,
293
+ errors: [
294
+ { messageId: 'noUnitlessValue', data: { property: 'margin', value: '10' } },
295
+ { messageId: 'noUnitlessValue', data: { property: 'padding', value: '20' } },
296
+ { messageId: 'noUnitlessValue', data: { property: 'width', value: '30' } },
297
+ ],
298
+ name: 'should flag unitless values in deeply nested objects',
299
+ },
300
+ // globalStyle with unitless values
301
+ {
302
+ code: `
303
+ import { globalStyle } from '@vanilla-extract/css';
304
+ globalStyle('html', {
305
+ margin: 10,
306
+ padding: 20,
307
+ });
308
+ `,
309
+ errors: [
310
+ { messageId: 'noUnitlessValue', data: { property: 'margin', value: '10' } },
311
+ { messageId: 'noUnitlessValue', data: { property: 'padding', value: '20' } },
312
+ ],
313
+ name: 'should flag unitless values in globalStyle',
314
+ },
315
+ // Various length properties
316
+ {
317
+ code: `
318
+ import { style } from '@vanilla-extract/css';
319
+ const myStyle = style({
320
+ width: 100,
321
+ height: 200,
322
+ minWidth: 50,
323
+ maxWidth: 500,
324
+ top: 10,
325
+ left: 20,
326
+ borderWidth: 2,
327
+ borderRadius: 5,
328
+ gap: 15,
329
+ fontSize: 16,
330
+ });
331
+ `,
332
+ errors: 10,
333
+ name: 'should flag all unitless values for various length properties',
334
+ },
335
+ // Kebab-case properties
336
+ {
337
+ code: `
338
+ import { style } from '@vanilla-extract/css';
339
+ const myStyle = style({
340
+ 'margin-top': 10,
341
+ 'padding-left': 20,
342
+ 'font-size': 16,
343
+ });
344
+ `,
345
+ errors: [
346
+ { messageId: 'noUnitlessValue', data: { property: 'margin-top', value: '10' } },
347
+ { messageId: 'noUnitlessValue', data: { property: 'padding-left', value: '20' } },
348
+ { messageId: 'noUnitlessValue', data: { property: 'font-size', value: '16' } },
349
+ ],
350
+ name: 'should flag unitless values for kebab-case properties',
351
+ },
352
+ // Logical properties
353
+ {
354
+ code: `
355
+ import { style } from '@vanilla-extract/css';
356
+ const myStyle = style({
357
+ marginBlock: 10,
358
+ paddingInline: 20,
359
+ insetBlockStart: 5,
360
+ });
361
+ `,
362
+ errors: [
363
+ { messageId: 'noUnitlessValue', data: { property: 'marginBlock', value: '10' } },
364
+ { messageId: 'noUnitlessValue', data: { property: 'paddingInline', value: '20' } },
365
+ { messageId: 'noUnitlessValue', data: { property: 'insetBlockStart', value: '5' } },
366
+ ],
367
+ name: 'should flag unitless values for logical properties',
368
+ },
369
+ // styleVariants
370
+ {
371
+ code: `
372
+ import { styleVariants } from '@vanilla-extract/css';
373
+ const variants = styleVariants({
374
+ small: { width: 10 },
375
+ large: { width: 100 },
376
+ });
377
+ `,
378
+ errors: [
379
+ { messageId: 'noUnitlessValue', data: { property: 'width', value: '10' } },
380
+ { messageId: 'noUnitlessValue', data: { property: 'width', value: '100' } },
381
+ ],
382
+ name: 'should flag unitless values in styleVariants',
383
+ },
384
+ // globalKeyframes
385
+ {
386
+ code: `
387
+ import { globalKeyframes } from '@vanilla-extract/css';
388
+ globalKeyframes('slide', {
389
+ '0%': { left: 0 },
390
+ '100%': { left: 100 }
391
+ });
392
+ `,
393
+ errors: [{ messageId: 'noUnitlessValue', data: { property: 'left', value: '100' } }],
394
+ name: 'should flag unitless values in globalKeyframes',
395
+ },
396
+ // Negative values
397
+ {
398
+ code: `
399
+ import { style } from '@vanilla-extract/css';
400
+ const myStyle = style({
401
+ margin: -10,
402
+ top: -5,
403
+ });
404
+ `,
405
+ errors: [
406
+ { messageId: 'noUnitlessValue', data: { property: 'margin', value: '-10' } },
407
+ { messageId: 'noUnitlessValue', data: { property: 'top', value: '-5' } },
408
+ ],
409
+ name: 'should flag negative unitless values',
410
+ },
411
+ // String unitless values
412
+ {
413
+ code: `
414
+ import { style } from '@vanilla-extract/css';
415
+ const myStyle = style({
416
+ width: '100',
417
+ margin: '20',
418
+ padding: '10.5',
419
+ });
420
+ `,
421
+ errors: [
422
+ { messageId: 'noUnitlessValue', data: { property: 'width', value: '100' } },
423
+ { messageId: 'noUnitlessValue', data: { property: 'margin', value: '20' } },
424
+ { messageId: 'noUnitlessValue', data: { property: 'padding', value: '10.5' } },
425
+ ],
426
+ name: 'should flag string unitless values',
427
+ },
428
+ // String negative unitless values
429
+ {
430
+ code: `
431
+ import { style } from '@vanilla-extract/css';
432
+ const myStyle = style({
433
+ margin: '-10',
434
+ top: '-5.5',
435
+ });
436
+ `,
437
+ errors: [
438
+ { messageId: 'noUnitlessValue', data: { property: 'margin', value: '-10' } },
439
+ { messageId: 'noUnitlessValue', data: { property: 'top', value: '-5.5' } },
440
+ ],
441
+ name: 'should flag string negative unitless values',
442
+ },
443
+ ],
444
+ });
@@ -0,0 +1,2 @@
1
+ import noUnitlessValuesRule from './rule-definition.js';
2
+ export default noUnitlessValuesRule;
@@ -0,0 +1,2 @@
1
+ import noUnitlessValuesRule from './rule-definition.js';
2
+ export default noUnitlessValuesRule;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ declare const noUnitlessValuesRule: Rule.RuleModule;
3
+ export default noUnitlessValuesRule;
@@ -0,0 +1,35 @@
1
+ import { createUnitlessValueVisitors } from './unitless-value-visitor-creator.js';
2
+ const noUnitlessValuesRule = {
3
+ meta: {
4
+ type: 'suggestion',
5
+ docs: {
6
+ description: 'disallow unitless numeric values for CSS properties that require units',
7
+ category: 'Stylistic Issues',
8
+ recommended: false,
9
+ },
10
+ schema: [
11
+ {
12
+ type: 'object',
13
+ properties: {
14
+ allow: {
15
+ type: 'array',
16
+ items: {
17
+ type: 'string',
18
+ },
19
+ uniqueItems: true,
20
+ default: [],
21
+ },
22
+ },
23
+ additionalProperties: false,
24
+ },
25
+ ],
26
+ messages: {
27
+ noUnitlessValue: 'Property "{{ property }}" has unitless value {{ value }}. Add an explicit unit (e.g., "{{ value }}px", "{{ value }}rem").',
28
+ },
29
+ },
30
+ create(context) {
31
+ const options = context.options[0] || {};
32
+ return createUnitlessValueVisitors(context, options);
33
+ },
34
+ };
35
+ export default noUnitlessValuesRule;
@@ -0,0 +1,13 @@
1
+ import type { Rule } from 'eslint';
2
+ import { TSESTree } from '@typescript-eslint/utils';
3
+ export interface NoUnitlessValuesOptions {
4
+ allow?: string[];
5
+ }
6
+ /**
7
+ * Recursively processes a style object, reporting instances of unitless numeric values for properties that require units.
8
+ *
9
+ * @param ruleContext The ESLint rule context.
10
+ * @param node The ObjectExpression node representing the style object to be processed.
11
+ * @param options Rule options including allow list.
12
+ */
13
+ export declare const processUnitlessValueInStyleObject: (ruleContext: Rule.RuleContext, node: TSESTree.ObjectExpression, options?: NoUnitlessValuesOptions) => void;