@antebudimir/eslint-plugin-vanilla-extract 1.13.0 → 1.14.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 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/prefer-logical-properties`: Enforces logical CSS properties over physical directional properties
267
268
 
268
269
  You can use the recommended configuration as a starting point and override rules as needed for your project. See the configuration examples above for how to switch between ordering rules.
269
270
 
@@ -602,6 +603,43 @@ export const myStyle = style({
602
603
  });
603
604
  ```
604
605
 
606
+ ### vanilla-extract/prefer-logical-properties
607
+
608
+ This rule enforces the use of CSS logical properties instead of physical (directional) properties in vanilla-extract style declarations. Logical properties adapt to different writing directions (LTR/RTL) and writing modes, making your styles more internationalization-friendly. Supports 140+ property mappings across margin, padding, border, inset, size, overflow, and scroll properties. Configurable allowlist lets you permit specific properties via the `allow` option (supports both camelCase and kebab-case).
609
+
610
+ Configuration with an allowlist:
611
+
612
+ ```json
613
+ {
614
+ "rules": {
615
+ "vanilla-extract/prefer-logical-properties": ["error", { "allow": ["top", "left"] }]
616
+ }
617
+ }
618
+ ```
619
+
620
+ ```typescript
621
+ // ❌ Incorrect
622
+ import { style } from '@vanilla-extract/css';
623
+
624
+ export const box = style({
625
+ marginLeft: '1rem',
626
+ paddingTop: '2rem',
627
+ width: '100%',
628
+ borderRight: '1px solid',
629
+ textAlign: 'left',
630
+ });
631
+
632
+ // ✅ Correct
633
+ import { style } from '@vanilla-extract/css';
634
+
635
+ export const box = style({
636
+ marginInlineStart: '1rem',
637
+ paddingBlockStart: '2rem',
638
+ inlineSize: '100%',
639
+ borderInlineEnd: '1px solid',
640
+ textAlign: 'start',
641
+ });
642
+
605
643
  ## Font Face Declarations
606
644
 
607
645
  For `fontFace` and `globalFontFace` API calls, all three ordering rules (alphabetical, concentric, and custom) enforce
@@ -686,14 +724,14 @@ The roadmap outlines the project's current status and future plans:
686
724
  - Support for using the plugin's recommended config via the extends field (as discussed in
687
725
  [issue #3](https://github.com/antebudimir/eslint-plugin-vanilla-extract/issues/3))
688
726
  - Comprehensive rule testing.
727
+ - `no-px-unit` rule to disallow use of `px` units with configurable whitelist.
689
728
 
690
729
  ### Current Work
691
730
 
692
- - `no-px-unit` rule to disallow use of `px` units with configurable whitelist.
731
+ - TBA
693
732
 
694
733
  ### Upcoming Features
695
734
 
696
- - `prefer-logical-properties` rule to enforce use of logical properties.
697
735
  - `prefer-theme-tokens` rule to enforce use of theme tokens instead of hard-coded values when available.
698
736
  - `no-global-style` rule to disallow use of `globalStyle` function.
699
737
  - `property-unit-match` rule to enforce valid units per CSS property specs. **Note**: This feature will only be
@@ -0,0 +1,572 @@
1
+ import tsParser from '@typescript-eslint/parser';
2
+ import { run } from 'eslint-vitest-rule-tester';
3
+ import preferLogicalPropertiesRule from '../rule-definition.js';
4
+ run({
5
+ name: 'vanilla-extract/prefer-logical-properties',
6
+ rule: preferLogicalPropertiesRule,
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
+ marginInlineStart: '1rem',
20
+ marginInlineEnd: '1rem',
21
+ marginBlockStart: '2rem',
22
+ marginBlockEnd: '2rem',
23
+ });
24
+ `,
25
+ name: 'allows logical properties in camelCase',
26
+ },
27
+ {
28
+ code: `
29
+ import { style } from '@vanilla-extract/css';
30
+ const myStyle = style({
31
+ 'margin-inline-start': '1rem',
32
+ 'margin-inline-end': '1rem',
33
+ 'margin-block-start': '2rem',
34
+ 'margin-block-end': '2rem',
35
+ });
36
+ `,
37
+ name: 'allows logical properties in kebab-case',
38
+ },
39
+ {
40
+ code: `
41
+ import { style } from '@vanilla-extract/css';
42
+ const myStyle = style({
43
+ insetInlineStart: 0,
44
+ insetInlineEnd: 0,
45
+ insetBlockStart: 0,
46
+ insetBlockEnd: 0,
47
+ });
48
+ `,
49
+ name: 'allows logical inset properties',
50
+ },
51
+ {
52
+ code: `
53
+ import { style } from '@vanilla-extract/css';
54
+ const myStyle = style({
55
+ borderInlineStartWidth: '1px',
56
+ borderInlineEndColor: 'red',
57
+ borderBlockStartStyle: 'solid',
58
+ });
59
+ `,
60
+ name: 'allows logical border properties',
61
+ },
62
+ {
63
+ code: `
64
+ import { style } from '@vanilla-extract/css';
65
+ const myStyle = style({
66
+ inlineSize: '100%',
67
+ blockSize: '50vh',
68
+ minInlineSize: '200px',
69
+ maxBlockSize: '800px',
70
+ });
71
+ `,
72
+ name: 'allows logical size properties',
73
+ },
74
+ {
75
+ code: `
76
+ import { style } from '@vanilla-extract/css';
77
+ const myStyle = style({
78
+ textAlign: 'start',
79
+ float: 'inline-start',
80
+ clear: 'inline-end',
81
+ });
82
+ `,
83
+ name: 'allows logical values for directional properties',
84
+ },
85
+ {
86
+ code: `
87
+ import { style } from '@vanilla-extract/css';
88
+ const myStyle = style({
89
+ marginLeft: '1rem',
90
+ paddingTop: '2rem',
91
+ top: 0,
92
+ left: 0,
93
+ });
94
+ `,
95
+ options: [{ allow: ['marginLeft', 'paddingTop', 'top', 'left'] }],
96
+ name: 'respects allowlist for camelCase properties',
97
+ },
98
+ {
99
+ code: `
100
+ import { style } from '@vanilla-extract/css';
101
+ const myStyle = style({
102
+ 'margin-left': '1rem',
103
+ 'padding-top': '2rem',
104
+ });
105
+ `,
106
+ options: [{ allow: ['margin-left', 'padding-top'] }],
107
+ name: 'respects allowlist for kebab-case properties',
108
+ },
109
+ {
110
+ code: `
111
+ import { style } from '@vanilla-extract/css';
112
+ const myStyle = style({
113
+ marginLeft: '1rem',
114
+ });
115
+ `,
116
+ options: [{ allow: ['margin-left'] }],
117
+ name: 'allowlist works with mixed case (kebab in config, camel in code)',
118
+ },
119
+ {
120
+ code: `
121
+ import { recipe } from '@vanilla-extract/css';
122
+ const myRecipe = recipe({
123
+ base: {
124
+ marginInlineStart: '1rem',
125
+ paddingBlockEnd: '2rem',
126
+ },
127
+ variants: {
128
+ size: {
129
+ sm: { insetInlineStart: 0 },
130
+ lg: { borderInlineEndWidth: '2px' },
131
+ },
132
+ },
133
+ });
134
+ `,
135
+ name: 'allows logical properties in recipe base and variants',
136
+ },
137
+ {
138
+ code: `
139
+ import { style } from '@vanilla-extract/css';
140
+ const myStyle = style({
141
+ '@media': {
142
+ '(min-width: 768px)': {
143
+ marginInlineStart: '2rem',
144
+ },
145
+ },
146
+ selectors: {
147
+ '&:hover': {
148
+ paddingBlockStart: '1rem',
149
+ },
150
+ },
151
+ });
152
+ `,
153
+ name: 'allows logical properties in nested @media and selectors',
154
+ },
155
+ {
156
+ code: `
157
+ import { style } from '@vanilla-extract/css';
158
+ const myStyle = style({
159
+ color: 'red',
160
+ display: 'flex',
161
+ fontSize: '16px',
162
+ });
163
+ `,
164
+ name: 'ignores non-directional properties',
165
+ },
166
+ ],
167
+ invalid: [
168
+ {
169
+ code: `
170
+ import { style } from '@vanilla-extract/css';
171
+ const myStyle = style({
172
+ marginTop: '1rem',
173
+ marginBottom: '2rem',
174
+ });
175
+ `,
176
+ output: `
177
+ import { style } from '@vanilla-extract/css';
178
+ const myStyle = style({
179
+ marginBlockStart: '1rem',
180
+ marginBlockEnd: '2rem',
181
+ });
182
+ `,
183
+ errors: [
184
+ {
185
+ messageId: 'preferLogicalProperty',
186
+ data: { physical: 'marginTop', logical: 'marginBlockStart' },
187
+ },
188
+ {
189
+ messageId: 'preferLogicalProperty',
190
+ data: { physical: 'marginBottom', logical: 'marginBlockEnd' },
191
+ },
192
+ ],
193
+ name: 'reports and fixes margin properties',
194
+ },
195
+ {
196
+ code: `
197
+ import { style } from '@vanilla-extract/css';
198
+ const myStyle = style({
199
+ 'padding-left': '1rem',
200
+ 'padding-right': '2rem',
201
+ });
202
+ `,
203
+ output: `
204
+ import { style } from '@vanilla-extract/css';
205
+ const myStyle = style({
206
+ 'padding-inline-start': '1rem',
207
+ 'padding-inline-end': '2rem',
208
+ });
209
+ `,
210
+ errors: [
211
+ {
212
+ messageId: 'preferLogicalProperty',
213
+ data: { physical: 'padding-left', logical: 'padding-inline-start' },
214
+ },
215
+ {
216
+ messageId: 'preferLogicalProperty',
217
+ data: { physical: 'padding-right', logical: 'padding-inline-end' },
218
+ },
219
+ ],
220
+ name: 'reports and fixes kebab-case padding properties',
221
+ },
222
+ {
223
+ code: `
224
+ import { style } from '@vanilla-extract/css';
225
+ const myStyle = style({
226
+ top: 0,
227
+ left: 0,
228
+ right: 0,
229
+ bottom: 0,
230
+ });
231
+ `,
232
+ output: `
233
+ import { style } from '@vanilla-extract/css';
234
+ const myStyle = style({
235
+ insetBlockStart: 0,
236
+ insetInlineStart: 0,
237
+ insetInlineEnd: 0,
238
+ insetBlockEnd: 0,
239
+ });
240
+ `,
241
+ errors: [
242
+ { messageId: 'preferLogicalProperty' },
243
+ { messageId: 'preferLogicalProperty' },
244
+ { messageId: 'preferLogicalProperty' },
245
+ { messageId: 'preferLogicalProperty' },
246
+ ],
247
+ name: 'reports and fixes positioning properties',
248
+ },
249
+ {
250
+ code: `
251
+ import { style } from '@vanilla-extract/css';
252
+ const myStyle = style({
253
+ borderLeftWidth: '1px',
254
+ borderRightColor: 'red',
255
+ borderTopStyle: 'solid',
256
+ });
257
+ `,
258
+ output: `
259
+ import { style } from '@vanilla-extract/css';
260
+ const myStyle = style({
261
+ borderInlineStartWidth: '1px',
262
+ borderInlineEndColor: 'red',
263
+ borderBlockStartStyle: 'solid',
264
+ });
265
+ `,
266
+ errors: [
267
+ { messageId: 'preferLogicalProperty' },
268
+ { messageId: 'preferLogicalProperty' },
269
+ { messageId: 'preferLogicalProperty' },
270
+ ],
271
+ name: 'reports and fixes border sub-properties',
272
+ },
273
+ {
274
+ code: `
275
+ import { style } from '@vanilla-extract/css';
276
+ const myStyle = style({
277
+ borderLeft: '1px solid red',
278
+ borderRight: '2px dashed blue',
279
+ });
280
+ `,
281
+ output: `
282
+ import { style } from '@vanilla-extract/css';
283
+ const myStyle = style({
284
+ borderInlineStart: '1px solid red',
285
+ borderInlineEnd: '2px dashed blue',
286
+ });
287
+ `,
288
+ errors: [
289
+ { messageId: 'preferLogicalProperty' },
290
+ { messageId: 'preferLogicalProperty' },
291
+ ],
292
+ name: 'reports and fixes border shorthand properties',
293
+ },
294
+ {
295
+ code: `
296
+ import { style } from '@vanilla-extract/css';
297
+ const myStyle = style({
298
+ borderTopLeftRadius: '4px',
299
+ borderBottomRightRadius: '8px',
300
+ });
301
+ `,
302
+ output: `
303
+ import { style } from '@vanilla-extract/css';
304
+ const myStyle = style({
305
+ borderStartStartRadius: '4px',
306
+ borderEndEndRadius: '8px',
307
+ });
308
+ `,
309
+ errors: [
310
+ { messageId: 'preferLogicalProperty' },
311
+ { messageId: 'preferLogicalProperty' },
312
+ ],
313
+ name: 'reports and fixes border radius properties',
314
+ },
315
+ {
316
+ code: `
317
+ import { style } from '@vanilla-extract/css';
318
+ const myStyle = style({
319
+ width: '100px',
320
+ height: '200px',
321
+ minWidth: '50px',
322
+ maxHeight: '400px',
323
+ });
324
+ `,
325
+ output: `
326
+ import { style } from '@vanilla-extract/css';
327
+ const myStyle = style({
328
+ inlineSize: '100px',
329
+ blockSize: '200px',
330
+ minInlineSize: '50px',
331
+ maxBlockSize: '400px',
332
+ });
333
+ `,
334
+ errors: [
335
+ { messageId: 'preferLogicalProperty' },
336
+ { messageId: 'preferLogicalProperty' },
337
+ { messageId: 'preferLogicalProperty' },
338
+ { messageId: 'preferLogicalProperty' },
339
+ ],
340
+ name: 'reports and fixes size properties',
341
+ },
342
+ {
343
+ code: `
344
+ import { style } from '@vanilla-extract/css';
345
+ const myStyle = style({
346
+ overflowX: 'auto',
347
+ overflowY: 'hidden',
348
+ });
349
+ `,
350
+ output: `
351
+ import { style } from '@vanilla-extract/css';
352
+ const myStyle = style({
353
+ overflowInline: 'auto',
354
+ overflowBlock: 'hidden',
355
+ });
356
+ `,
357
+ errors: [
358
+ { messageId: 'preferLogicalProperty' },
359
+ { messageId: 'preferLogicalProperty' },
360
+ ],
361
+ name: 'reports and fixes overflow properties',
362
+ },
363
+ {
364
+ code: `
365
+ import { style } from '@vanilla-extract/css';
366
+ const myStyle = style({
367
+ textAlign: 'left',
368
+ float: 'right',
369
+ clear: 'left',
370
+ resize: 'horizontal',
371
+ });
372
+ `,
373
+ output: `
374
+ import { style } from '@vanilla-extract/css';
375
+ const myStyle = style({
376
+ textAlign: 'start',
377
+ float: 'inline-end',
378
+ clear: 'inline-start',
379
+ resize: 'inline',
380
+ });
381
+ `,
382
+ errors: [
383
+ {
384
+ messageId: 'preferLogicalValue',
385
+ data: { property: 'textAlign', physical: 'left', logical: 'start' },
386
+ },
387
+ {
388
+ messageId: 'preferLogicalValue',
389
+ data: { property: 'float', physical: 'right', logical: 'inline-end' },
390
+ },
391
+ {
392
+ messageId: 'preferLogicalValue',
393
+ data: { property: 'clear', physical: 'left', logical: 'inline-start' },
394
+ },
395
+ {
396
+ messageId: 'preferLogicalValue',
397
+ data: { property: 'resize', physical: 'horizontal', logical: 'inline' },
398
+ },
399
+ ],
400
+ name: 'reports and fixes directional values',
401
+ },
402
+ {
403
+ code: `
404
+ import { recipe } from '@vanilla-extract/css';
405
+ const myRecipe = recipe({
406
+ base: {
407
+ marginLeft: '1rem',
408
+ paddingTop: '2rem',
409
+ },
410
+ variants: {
411
+ size: {
412
+ sm: { left: 0 },
413
+ lg: { borderRightWidth: '2px' },
414
+ },
415
+ },
416
+ });
417
+ `,
418
+ output: `
419
+ import { recipe } from '@vanilla-extract/css';
420
+ const myRecipe = recipe({
421
+ base: {
422
+ marginInlineStart: '1rem',
423
+ paddingBlockStart: '2rem',
424
+ },
425
+ variants: {
426
+ size: {
427
+ sm: { insetInlineStart: 0 },
428
+ lg: { borderInlineEndWidth: '2px' },
429
+ },
430
+ },
431
+ });
432
+ `,
433
+ errors: [
434
+ { messageId: 'preferLogicalProperty' },
435
+ { messageId: 'preferLogicalProperty' },
436
+ { messageId: 'preferLogicalProperty' },
437
+ { messageId: 'preferLogicalProperty' },
438
+ ],
439
+ name: 'reports and fixes physical properties in recipe base and variants',
440
+ },
441
+ {
442
+ code: `
443
+ import { style } from '@vanilla-extract/css';
444
+ const myStyle = style({
445
+ '@media': {
446
+ '(min-width: 768px)': {
447
+ marginLeft: '2rem',
448
+ paddingTop: '1rem',
449
+ },
450
+ },
451
+ selectors: {
452
+ '&:hover': {
453
+ right: 0,
454
+ bottom: 0,
455
+ },
456
+ },
457
+ });
458
+ `,
459
+ output: `
460
+ import { style } from '@vanilla-extract/css';
461
+ const myStyle = style({
462
+ '@media': {
463
+ '(min-width: 768px)': {
464
+ marginInlineStart: '2rem',
465
+ paddingBlockStart: '1rem',
466
+ },
467
+ },
468
+ selectors: {
469
+ '&:hover': {
470
+ insetInlineEnd: 0,
471
+ insetBlockEnd: 0,
472
+ },
473
+ },
474
+ });
475
+ `,
476
+ errors: [
477
+ { messageId: 'preferLogicalProperty' },
478
+ { messageId: 'preferLogicalProperty' },
479
+ { messageId: 'preferLogicalProperty' },
480
+ { messageId: 'preferLogicalProperty' },
481
+ ],
482
+ name: 'reports and fixes physical properties in nested @media and selectors',
483
+ },
484
+ {
485
+ code: `
486
+ import { style } from '@vanilla-extract/css';
487
+ const myStyle = style({
488
+ scrollMarginLeft: '10px',
489
+ scrollPaddingTop: '20px',
490
+ });
491
+ `,
492
+ output: `
493
+ import { style } from '@vanilla-extract/css';
494
+ const myStyle = style({
495
+ scrollMarginInlineStart: '10px',
496
+ scrollPaddingBlockStart: '20px',
497
+ });
498
+ `,
499
+ errors: [
500
+ { messageId: 'preferLogicalProperty' },
501
+ { messageId: 'preferLogicalProperty' },
502
+ ],
503
+ name: 'reports and fixes scroll margin and padding properties',
504
+ },
505
+ {
506
+ code: `
507
+ import { style } from '@vanilla-extract/css';
508
+ const myStyle = style({
509
+ overscrollBehaviorX: 'contain',
510
+ overscrollBehaviorY: 'auto',
511
+ });
512
+ `,
513
+ output: `
514
+ import { style } from '@vanilla-extract/css';
515
+ const myStyle = style({
516
+ overscrollBehaviorInline: 'contain',
517
+ overscrollBehaviorBlock: 'auto',
518
+ });
519
+ `,
520
+ errors: [
521
+ { messageId: 'preferLogicalProperty' },
522
+ { messageId: 'preferLogicalProperty' },
523
+ ],
524
+ name: 'reports and fixes overscroll behavior properties',
525
+ },
526
+ {
527
+ code: `
528
+ import { style } from '@vanilla-extract/css';
529
+ const myStyle = style({
530
+ marginLeft: \`1rem\`,
531
+ textAlign: \`left\`,
532
+ });
533
+ `,
534
+ output: `
535
+ import { style } from '@vanilla-extract/css';
536
+ const myStyle = style({
537
+ marginInlineStart: \`1rem\`,
538
+ textAlign: \`start\`,
539
+ });
540
+ `,
541
+ errors: [
542
+ { messageId: 'preferLogicalProperty' },
543
+ { messageId: 'preferLogicalValue' },
544
+ ],
545
+ name: 'handles template literals',
546
+ },
547
+ {
548
+ code: `
549
+ import { style } from '@vanilla-extract/css';
550
+ const myStyle = style({
551
+ marginLeft: '1rem',
552
+ paddingTop: '2rem',
553
+ });
554
+ `,
555
+ options: [{ allow: ['paddingTop'] }],
556
+ output: `
557
+ import { style } from '@vanilla-extract/css';
558
+ const myStyle = style({
559
+ marginInlineStart: '1rem',
560
+ paddingTop: '2rem',
561
+ });
562
+ `,
563
+ errors: [
564
+ {
565
+ messageId: 'preferLogicalProperty',
566
+ data: { physical: 'marginLeft', logical: 'marginInlineStart' },
567
+ },
568
+ ],
569
+ name: 'only reports non-allowlisted properties',
570
+ },
571
+ ],
572
+ });
@@ -0,0 +1,2 @@
1
+ import preferLogicalPropertiesRule from './rule-definition.js';
2
+ export default preferLogicalPropertiesRule;
@@ -0,0 +1,2 @@
1
+ import preferLogicalPropertiesRule from './rule-definition.js';
2
+ export default preferLogicalPropertiesRule;
@@ -0,0 +1,19 @@
1
+ import type { Rule } from 'eslint';
2
+ import { TSESTree } from '@typescript-eslint/utils';
3
+ export interface LogicalPropertiesOptions {
4
+ allow?: string[];
5
+ }
6
+ /**
7
+ * Recursively processes a vanilla-extract style object and reports physical CSS properties.
8
+ *
9
+ * - Detects physical property names and suggests logical equivalents
10
+ * - Detects physical directional values (e.g., text-align: left)
11
+ * - Skips properties in the allow list
12
+ * - Provides auto-fixes where unambiguous
13
+ * - Traverses nested objects, @media, and selectors
14
+ *
15
+ * @param context ESLint rule context
16
+ * @param node The ObjectExpression node representing the style object
17
+ * @param allowSet Set of property names to skip
18
+ */
19
+ export declare const processLogicalPropertiesInStyleObject: (context: Rule.RuleContext, node: TSESTree.ObjectExpression, allowSet: Set<string>) => void;