@antebudimir/eslint-plugin-vanilla-extract 1.13.0 → 1.15.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 (42) hide show
  1. package/README.md +150 -4
  2. package/dist/css-rules/prefer-logical-properties/_tests_/prefer-logical-properties.test.d.ts +1 -0
  3. package/dist/css-rules/prefer-logical-properties/_tests_/prefer-logical-properties.test.js +572 -0
  4. package/dist/css-rules/prefer-logical-properties/index.d.ts +2 -0
  5. package/dist/css-rules/prefer-logical-properties/index.js +2 -0
  6. package/dist/css-rules/prefer-logical-properties/logical-properties-processor.d.ts +19 -0
  7. package/dist/css-rules/prefer-logical-properties/logical-properties-processor.js +202 -0
  8. package/dist/css-rules/prefer-logical-properties/logical-properties-visitor-creator.d.ts +14 -0
  9. package/dist/css-rules/prefer-logical-properties/logical-properties-visitor-creator.js +67 -0
  10. package/dist/css-rules/prefer-logical-properties/property-mappings.d.ts +44 -0
  11. package/dist/css-rules/prefer-logical-properties/property-mappings.js +179 -0
  12. package/dist/css-rules/prefer-logical-properties/rule-definition.d.ts +3 -0
  13. package/dist/css-rules/prefer-logical-properties/rule-definition.js +35 -0
  14. package/dist/css-rules/prefer-theme-tokens/index.d.ts +2 -0
  15. package/dist/css-rules/prefer-theme-tokens/index.js +2 -0
  16. package/dist/css-rules/prefer-theme-tokens/rule-definition.d.ts +3 -0
  17. package/dist/css-rules/prefer-theme-tokens/rule-definition.js +119 -0
  18. package/dist/css-rules/prefer-theme-tokens/theme-contract-analyzer.d.ts +60 -0
  19. package/dist/css-rules/prefer-theme-tokens/theme-contract-analyzer.js +322 -0
  20. package/dist/css-rules/prefer-theme-tokens/theme-token-processor.d.ts +26 -0
  21. package/dist/css-rules/prefer-theme-tokens/theme-token-processor.js +562 -0
  22. package/dist/css-rules/prefer-theme-tokens/theme-token-visitor-creator.d.ts +6 -0
  23. package/dist/css-rules/prefer-theme-tokens/theme-token-visitor-creator.js +81 -0
  24. package/dist/css-rules/prefer-theme-tokens/value-evaluator.d.ts +43 -0
  25. package/dist/css-rules/prefer-theme-tokens/value-evaluator.js +190 -0
  26. package/dist/demo-bad-example.css.d.ts +4 -0
  27. package/dist/demo-bad-example.css.js +45 -0
  28. package/dist/demo-good-example.css.d.ts +5 -0
  29. package/dist/demo-good-example.css.js +48 -0
  30. package/dist/demo-theme.css.d.ts +37 -0
  31. package/dist/demo-theme.css.js +39 -0
  32. package/dist/index.d.ts +2 -0
  33. package/dist/index.js +5 -1
  34. package/dist/sample-bad.css.d.ts +26 -0
  35. package/dist/sample-bad.css.js +85 -0
  36. package/dist/sample-good.css.d.ts +27 -0
  37. package/dist/sample-good.css.js +94 -0
  38. package/dist/sample-theme.css.d.ts +37 -0
  39. package/dist/sample-theme.css.js +38 -0
  40. package/dist/sample.css.d.ts +75 -0
  41. package/dist/sample.css.js +530 -0
  42. package/package.json +5 -1
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Safe evaluator for static theme values with support for:
3
+ * - rem() from polished
4
+ * - clsx() for combining values
5
+ * - Template literals with expressions
6
+ * - Basic arithmetic
7
+ */
8
+ export declare class ValueEvaluator {
9
+ private remBase;
10
+ constructor(remBase?: number);
11
+ /**
12
+ * Evaluate a string expression to a concrete value
13
+ */
14
+ evaluate(expression: string): string | null;
15
+ /**
16
+ * Evaluate an AST node
17
+ */
18
+ private evaluateNode;
19
+ /**
20
+ * Evaluate a template literal
21
+ */
22
+ private evaluateTemplateLiteral;
23
+ /**
24
+ * Evaluate a call expression (rem, clsx, etc.)
25
+ */
26
+ private evaluateCallExpression;
27
+ /**
28
+ * Evaluate rem() function from polished
29
+ */
30
+ private evaluateRem;
31
+ /**
32
+ * Evaluate clsx() function
33
+ */
34
+ private evaluateClsx;
35
+ /**
36
+ * Evaluate binary expression (mainly for string concatenation)
37
+ */
38
+ private evaluateBinaryExpression;
39
+ /**
40
+ * Set rem base for evaluation
41
+ */
42
+ setRemBase(base: number): void;
43
+ }
@@ -0,0 +1,190 @@
1
+ import { parseExpression } from '@babel/parser';
2
+ /**
3
+ * Safe evaluator for static theme values with support for:
4
+ * - rem() from polished
5
+ * - clsx() for combining values
6
+ * - Template literals with expressions
7
+ * - Basic arithmetic
8
+ */
9
+ export class ValueEvaluator {
10
+ constructor(remBase = 16) {
11
+ this.remBase = remBase;
12
+ }
13
+ /**
14
+ * Evaluate a string expression to a concrete value
15
+ */
16
+ evaluate(expression) {
17
+ try {
18
+ const ast = parseExpression(expression, {
19
+ sourceType: 'module',
20
+ plugins: ['typescript'],
21
+ });
22
+ return this.evaluateNode(ast);
23
+ }
24
+ catch {
25
+ // If parsing fails, return the original expression if it's a simple string
26
+ const trimmed = expression.trim();
27
+ if ((trimmed.startsWith("'") && trimmed.endsWith("'")) ||
28
+ (trimmed.startsWith('"') && trimmed.endsWith('"')) ||
29
+ (trimmed.startsWith('`') && trimmed.endsWith('`'))) {
30
+ return trimmed.slice(1, -1);
31
+ }
32
+ return null;
33
+ }
34
+ }
35
+ /**
36
+ * Evaluate an AST node
37
+ */
38
+ evaluateNode(node) {
39
+ if (!node)
40
+ return null;
41
+ switch (node.type) {
42
+ case 'StringLiteral':
43
+ return node.value;
44
+ case 'NumericLiteral':
45
+ return String(node.value);
46
+ case 'TemplateLiteral':
47
+ return this.evaluateTemplateLiteral(node);
48
+ case 'CallExpression':
49
+ return this.evaluateCallExpression(node);
50
+ case 'BinaryExpression':
51
+ return this.evaluateBinaryExpression(node);
52
+ case 'Identifier':
53
+ // Only allow known safe identifiers
54
+ return null;
55
+ case 'MemberExpression':
56
+ // Don't evaluate member expressions for security
57
+ return null;
58
+ default:
59
+ return null;
60
+ }
61
+ }
62
+ /**
63
+ * Evaluate a template literal
64
+ */
65
+ evaluateTemplateLiteral(node) {
66
+ const parts = [];
67
+ for (let i = 0; i < node.quasis.length; i++) {
68
+ // Add the string part
69
+ const quasi = node.quasis[i];
70
+ if (!quasi)
71
+ continue;
72
+ parts.push(quasi.value.cooked || quasi.value.raw);
73
+ // Add the expression part if it exists
74
+ if (i < node.expressions.length) {
75
+ const exprValue = this.evaluateNode(node.expressions[i]);
76
+ if (exprValue === null) {
77
+ return null; // Can't evaluate this expression
78
+ }
79
+ parts.push(exprValue);
80
+ }
81
+ }
82
+ return parts.join('');
83
+ }
84
+ /**
85
+ * Evaluate a call expression (rem, clsx, etc.)
86
+ */
87
+ evaluateCallExpression(node) {
88
+ // Get function name
89
+ let functionName = null;
90
+ if (node.callee.type === 'Identifier') {
91
+ functionName = node.callee.name;
92
+ }
93
+ else if (node.callee.type === 'MemberExpression' &&
94
+ node.callee.property.type === 'Identifier') {
95
+ functionName = node.callee.property.name;
96
+ }
97
+ if (!functionName)
98
+ return null;
99
+ switch (functionName) {
100
+ case 'rem':
101
+ return this.evaluateRem(node);
102
+ case 'clsx':
103
+ return this.evaluateClsx(node);
104
+ default:
105
+ return null;
106
+ }
107
+ }
108
+ /**
109
+ * Evaluate rem() function from polished
110
+ */
111
+ evaluateRem(node) {
112
+ if (node.arguments.length === 0)
113
+ return null;
114
+ const arg = node.arguments[0];
115
+ if (!arg || arg.type === 'SpreadElement')
116
+ return null;
117
+ const value = this.evaluateNode(arg);
118
+ if (value === null)
119
+ return null;
120
+ const numValue = parseFloat(value);
121
+ if (isNaN(numValue))
122
+ return null;
123
+ // Convert pixels to rem
124
+ const remValue = numValue / this.remBase;
125
+ return `${remValue}rem`;
126
+ }
127
+ /**
128
+ * Evaluate clsx() function
129
+ */
130
+ evaluateClsx(node) {
131
+ const parts = [];
132
+ for (const arg of node.arguments) {
133
+ if (arg.type === 'SpreadElement')
134
+ return null;
135
+ const value = this.evaluateNode(arg);
136
+ if (value === null)
137
+ return null;
138
+ parts.push(value);
139
+ }
140
+ return parts.join(' ');
141
+ }
142
+ /**
143
+ * Evaluate binary expression (mainly for string concatenation)
144
+ */
145
+ evaluateBinaryExpression(node) {
146
+ const left = this.evaluateNode(node.left);
147
+ const right = this.evaluateNode(node.right);
148
+ if (left === null || right === null)
149
+ return null;
150
+ switch (node.operator) {
151
+ case '+':
152
+ // String concatenation or addition
153
+ const leftNum = parseFloat(left);
154
+ const rightNum = parseFloat(right);
155
+ if (!isNaN(leftNum) && !isNaN(rightNum)) {
156
+ return String(leftNum + rightNum);
157
+ }
158
+ return left + right;
159
+ case '-':
160
+ const leftNum2 = parseFloat(left);
161
+ const rightNum2 = parseFloat(right);
162
+ if (!isNaN(leftNum2) && !isNaN(rightNum2)) {
163
+ return String(leftNum2 - rightNum2);
164
+ }
165
+ return null;
166
+ case '*':
167
+ const leftNum3 = parseFloat(left);
168
+ const rightNum3 = parseFloat(right);
169
+ if (!isNaN(leftNum3) && !isNaN(rightNum3)) {
170
+ return String(leftNum3 * rightNum3);
171
+ }
172
+ return null;
173
+ case '/':
174
+ const leftNum4 = parseFloat(left);
175
+ const rightNum4 = parseFloat(right);
176
+ if (!isNaN(leftNum4) && !isNaN(rightNum4) && rightNum4 !== 0) {
177
+ return String(leftNum4 / rightNum4);
178
+ }
179
+ return null;
180
+ default:
181
+ return null;
182
+ }
183
+ }
184
+ /**
185
+ * Set rem base for evaluation
186
+ */
187
+ setRemBase(base) {
188
+ this.remBase = base;
189
+ }
190
+ }
@@ -0,0 +1,4 @@
1
+ export declare const button: string;
2
+ export declare const card: string;
3
+ export declare const text: string;
4
+ export declare const container: string;
@@ -0,0 +1,45 @@
1
+ import { style } from '@vanilla-extract/css';
2
+ // This file has hard-coded values that will trigger eslint errors
3
+ // when the prefer-theme-tokens rule is enabled
4
+ export const button = style({
5
+ // ❌ Hard-coded color - should use theme.colors.text
6
+ color: '#ffffff',
7
+ // ❌ Hard-coded color - should use theme.colors.primary
8
+ backgroundColor: '#3b82f6',
9
+ // ❌ Hard-coded spacing - should use theme.spacing
10
+ padding: '12px 24px',
11
+ // ❌ Hard-coded font size - should use theme.fontSizes
12
+ fontSize: '14px',
13
+ // ❌ Hard-coded border radius - should use theme.radii
14
+ borderRadius: '6px',
15
+ // ❌ Hard-coded color in border
16
+ border: '1px solid #e5e7eb',
17
+ });
18
+ export const card = style({
19
+ // ❌ Multiple hard-coded colors
20
+ backgroundColor: 'white',
21
+ color: 'black',
22
+ // ❌ Hard-coded spacing values
23
+ padding: '16px',
24
+ margin: '8px',
25
+ gap: '12px',
26
+ // ❌ Hard-coded border radius
27
+ borderRadius: '8px',
28
+ });
29
+ export const text = style({
30
+ // ❌ Hard-coded font sizes
31
+ fontSize: '16px',
32
+ lineHeight: '24px',
33
+ // ❌ Hard-coded colors
34
+ color: 'rgb(31, 41, 55)',
35
+ });
36
+ export const container = style({
37
+ // ❌ Hard-coded spacing in multiple properties
38
+ marginTop: '20px',
39
+ paddingLeft: '16px',
40
+ paddingRight: '16px',
41
+ // ❌ Hard-coded width (though percentages are allowed)
42
+ width: '300px',
43
+ // ❌ Hard-coded color
44
+ borderColor: '#e5e7eb',
45
+ });
@@ -0,0 +1,5 @@
1
+ export declare const button: string;
2
+ export declare const card: string;
3
+ export declare const text: string;
4
+ export declare const container: string;
5
+ export declare const allowedValues: string;
@@ -0,0 +1,48 @@
1
+ import { style } from '@vanilla-extract/css';
2
+ import { theme } from './demo-theme.css';
3
+ // This file uses theme tokens - no eslint errors!
4
+ export const button = style({
5
+ // ✅ Using theme tokens for colors
6
+ color: theme.colors.text,
7
+ backgroundColor: theme.colors.primary,
8
+ // ✅ Using theme tokens for spacing
9
+ padding: `${theme.spacing.sm} ${theme.spacing.md}`,
10
+ // ✅ Using theme tokens for font size
11
+ fontSize: theme.fontSizes.sm,
12
+ // ✅ Using theme tokens for border radius
13
+ borderRadius: theme.radii.md,
14
+ // ✅ Using theme tokens in border
15
+ border: `1px solid ${theme.colors.border}`,
16
+ });
17
+ export const card = style({
18
+ // ✅ All theme tokens
19
+ backgroundColor: theme.colors.background,
20
+ color: theme.colors.text,
21
+ padding: theme.spacing.md,
22
+ margin: theme.spacing.sm,
23
+ gap: theme.spacing.sm,
24
+ borderRadius: theme.radii.lg,
25
+ });
26
+ export const text = style({
27
+ // ✅ Theme tokens for typography
28
+ fontSize: theme.fontSizes.base,
29
+ lineHeight: theme.fontSizes.lg,
30
+ color: theme.colors.text,
31
+ });
32
+ export const container = style({
33
+ // ✅ Theme tokens for spacing
34
+ marginTop: theme.spacing.lg,
35
+ paddingLeft: theme.spacing.md,
36
+ paddingRight: theme.spacing.md,
37
+ // ✅ Percentages are allowed by default
38
+ width: '100%',
39
+ // ✅ Theme token for color
40
+ borderColor: theme.colors.border,
41
+ });
42
+ export const allowedValues = style({
43
+ // ✅ These special values are allowed by default
44
+ margin: '0', // Zero is allowed
45
+ padding: 'auto', // Auto is allowed
46
+ width: '100%', // Percentages are allowed
47
+ height: 'inherit', // CSS keywords are allowed
48
+ });
@@ -0,0 +1,37 @@
1
+ export declare const themeClass: string, theme: {
2
+ colors: {
3
+ primary: `var(--${string})` | `var(--${string}, ${string})` | `var(--${string}, ${number})`;
4
+ secondary: `var(--${string})` | `var(--${string}, ${string})` | `var(--${string}, ${number})`;
5
+ background: `var(--${string})` | `var(--${string}, ${string})` | `var(--${string}, ${number})`;
6
+ text: `var(--${string})` | `var(--${string}, ${string})` | `var(--${string}, ${number})`;
7
+ error: `var(--${string})` | `var(--${string}, ${string})` | `var(--${string}, ${number})`;
8
+ success: `var(--${string})` | `var(--${string}, ${string})` | `var(--${string}, ${number})`;
9
+ warning: `var(--${string})` | `var(--${string}, ${string})` | `var(--${string}, ${number})`;
10
+ hover: `var(--${string})` | `var(--${string}, ${string})` | `var(--${string}, ${number})`;
11
+ border: `var(--${string})` | `var(--${string}, ${string})` | `var(--${string}, ${number})`;
12
+ };
13
+ spacing: {
14
+ xs: `var(--${string})` | `var(--${string}, ${string})` | `var(--${string}, ${number})`;
15
+ sm: `var(--${string})` | `var(--${string}, ${string})` | `var(--${string}, ${number})`;
16
+ md: `var(--${string})` | `var(--${string}, ${string})` | `var(--${string}, ${number})`;
17
+ lg: `var(--${string})` | `var(--${string}, ${string})` | `var(--${string}, ${number})`;
18
+ xl: `var(--${string})` | `var(--${string}, ${string})` | `var(--${string}, ${number})`;
19
+ '2xl': `var(--${string})` | `var(--${string}, ${string})` | `var(--${string}, ${number})`;
20
+ };
21
+ fontSizes: {
22
+ xs: `var(--${string})` | `var(--${string}, ${string})` | `var(--${string}, ${number})`;
23
+ sm: `var(--${string})` | `var(--${string}, ${string})` | `var(--${string}, ${number})`;
24
+ base: `var(--${string})` | `var(--${string}, ${string})` | `var(--${string}, ${number})`;
25
+ lg: `var(--${string})` | `var(--${string}, ${string})` | `var(--${string}, ${number})`;
26
+ xl: `var(--${string})` | `var(--${string}, ${string})` | `var(--${string}, ${number})`;
27
+ '2xl': `var(--${string})` | `var(--${string}, ${string})` | `var(--${string}, ${number})`;
28
+ '3xl': `var(--${string})` | `var(--${string}, ${string})` | `var(--${string}, ${number})`;
29
+ };
30
+ radii: {
31
+ none: `var(--${string})` | `var(--${string}, ${string})` | `var(--${string}, ${number})`;
32
+ sm: `var(--${string})` | `var(--${string}, ${string})` | `var(--${string}, ${number})`;
33
+ md: `var(--${string})` | `var(--${string}, ${string})` | `var(--${string}, ${number})`;
34
+ lg: `var(--${string})` | `var(--${string}, ${string})` | `var(--${string}, ${number})`;
35
+ full: `var(--${string})` | `var(--${string}, ${string})` | `var(--${string}, ${number})`;
36
+ };
37
+ };
@@ -0,0 +1,39 @@
1
+ import { createTheme } from '@vanilla-extract/css';
2
+ // Create a theme with design tokens
3
+ export const [themeClass, theme] = createTheme({
4
+ colors: {
5
+ primary: '#3b82f6',
6
+ secondary: '#8b5cf6',
7
+ background: '#ffffff',
8
+ text: '#1f2937',
9
+ error: '#ef4444',
10
+ success: '#10b981',
11
+ warning: '#f59e0b',
12
+ hover: '#2563eb',
13
+ border: '#e5e7eb',
14
+ },
15
+ spacing: {
16
+ xs: '0.25rem',
17
+ sm: '0.5rem',
18
+ md: '1rem',
19
+ lg: '1.5rem',
20
+ xl: '2rem',
21
+ '2xl': '3rem',
22
+ },
23
+ fontSizes: {
24
+ xs: '0.75rem',
25
+ sm: '0.875rem',
26
+ base: '1rem',
27
+ lg: '1.125rem',
28
+ xl: '1.25rem',
29
+ '2xl': '1.5rem',
30
+ '3xl': '1.875rem',
31
+ },
32
+ radii: {
33
+ none: '0',
34
+ sm: '0.125rem',
35
+ md: '0.375rem',
36
+ lg: '0.5rem',
37
+ full: '9999px',
38
+ },
39
+ });
package/dist/index.d.ts CHANGED
@@ -12,6 +12,8 @@ declare const vanillaExtract: {
12
12
  'no-trailing-zero': import("eslint").Rule.RuleModule;
13
13
  'no-unknown-unit': import("eslint").Rule.RuleModule;
14
14
  'no-zero-unit': import("eslint").Rule.RuleModule;
15
+ 'prefer-logical-properties': import("eslint").Rule.RuleModule;
16
+ 'prefer-theme-tokens': import("eslint").Rule.RuleModule;
15
17
  };
16
18
  configs: {};
17
19
  };
package/dist/index.js CHANGED
@@ -6,10 +6,12 @@ import noPxUnitRule from './css-rules/no-px-unit/index.js';
6
6
  import noTrailingZeroRule from './css-rules/no-trailing-zero/rule-definition.js';
7
7
  import noUnknownUnitRule from './css-rules/no-unknown-unit/rule-definition.js';
8
8
  import noZeroUnitRule from './css-rules/no-zero-unit/rule-definition.js';
9
+ import preferLogicalPropertiesRule from './css-rules/prefer-logical-properties/index.js';
10
+ import preferThemeTokensRule from './css-rules/prefer-theme-tokens/index.js';
9
11
  const vanillaExtract = {
10
12
  meta: {
11
13
  name: '@antebudimir/eslint-plugin-vanilla-extract',
12
- version: '1.13.0',
14
+ version: '1.15.0',
13
15
  },
14
16
  rules: {
15
17
  'alphabetical-order': alphabeticalOrderRule,
@@ -20,6 +22,8 @@ const vanillaExtract = {
20
22
  'no-trailing-zero': noTrailingZeroRule,
21
23
  'no-unknown-unit': noUnknownUnitRule,
22
24
  'no-zero-unit': noZeroUnitRule,
25
+ 'prefer-logical-properties': preferLogicalPropertiesRule,
26
+ 'prefer-theme-tokens': preferThemeTokensRule,
23
27
  },
24
28
  configs: {},
25
29
  };
@@ -0,0 +1,26 @@
1
+ export declare const badButton: string;
2
+ export declare const badCard: string;
3
+ export declare const badText: string;
4
+ export declare const badBox: string;
5
+ export declare const badComponent: string;
6
+ export declare const badRecipe: import("@vanilla-extract/recipes").RuntimeFn<{
7
+ size: {
8
+ small: {
9
+ fontSize: "12px";
10
+ padding: "8px";
11
+ };
12
+ large: {
13
+ fontSize: "18px";
14
+ padding: "24px";
15
+ };
16
+ };
17
+ variant: {
18
+ primary: {
19
+ backgroundColor: "#3b82f6";
20
+ };
21
+ danger: {
22
+ backgroundColor: "#ef4444";
23
+ };
24
+ };
25
+ }>;
26
+ export declare const badResponsive: string;
@@ -0,0 +1,85 @@
1
+ import { style, globalStyle } from '@vanilla-extract/css';
2
+ import { recipe } from '@vanilla-extract/recipes';
3
+ // ❌ BAD: Hard-coded colors
4
+ export const badButton = style({
5
+ color: '#ffffff', // Should use theme.colors.text
6
+ backgroundColor: '#3b82f6', // Should use theme.colors.primary
7
+ borderColor: 'rgb(59, 130, 246)', // Should use theme.colors.primary
8
+ });
9
+ // ❌ BAD: Hard-coded spacing
10
+ export const badCard = style({
11
+ padding: '16px', // Should use theme.spacing.md
12
+ margin: '8px', // Should use theme.spacing.sm
13
+ gap: '12px', // Should use theme.spacing between sm and md
14
+ width: '200px', // Should use theme or percentage
15
+ });
16
+ // ❌ BAD: Hard-coded font sizes
17
+ export const badText = style({
18
+ fontSize: '14px', // Should use theme.fontSizes.sm
19
+ lineHeight: '1.5rem', // Should use theme.fontSizes
20
+ });
21
+ // ❌ BAD: Hard-coded border radius
22
+ export const badBox = style({
23
+ borderRadius: '8px', // Should use theme.radii.md
24
+ borderTopLeftRadius: '4px', // Should use theme.radii.sm
25
+ });
26
+ // ❌ BAD: Multiple violations
27
+ export const badComponent = style({
28
+ color: 'red', // Hard-coded color
29
+ backgroundColor: '#f0f0f0', // Hard-coded color
30
+ padding: '20px', // Hard-coded spacing
31
+ margin: '10px 15px', // Hard-coded spacing
32
+ fontSize: '16px', // Hard-coded font size
33
+ borderRadius: '6px', // Hard-coded border radius
34
+ border: '1px solid #ccc', // Hard-coded color in border
35
+ });
36
+ // ❌ BAD: Recipe with hard-coded values
37
+ export const badRecipe = recipe({
38
+ base: {
39
+ color: '#000000', // Hard-coded color
40
+ padding: '12px', // Hard-coded spacing
41
+ },
42
+ variants: {
43
+ size: {
44
+ small: {
45
+ fontSize: '12px', // Hard-coded font size
46
+ padding: '8px', // Hard-coded spacing
47
+ },
48
+ large: {
49
+ fontSize: '18px', // Hard-coded font size
50
+ padding: '24px', // Hard-coded spacing
51
+ },
52
+ },
53
+ variant: {
54
+ primary: {
55
+ backgroundColor: '#3b82f6', // Hard-coded color
56
+ },
57
+ danger: {
58
+ backgroundColor: '#ef4444', // Hard-coded color
59
+ },
60
+ },
61
+ },
62
+ });
63
+ // ❌ BAD: Nested structures with hard-coded values
64
+ export const badResponsive = style({
65
+ color: '#333',
66
+ '@media': {
67
+ '(min-width: 768px)': {
68
+ padding: '32px', // Hard-coded spacing
69
+ fontSize: '20px', // Hard-coded font size
70
+ },
71
+ },
72
+ selectors: {
73
+ '&:hover': {
74
+ backgroundColor: '#e0e0e0', // Hard-coded color
75
+ borderColor: 'blue', // Hard-coded color
76
+ },
77
+ },
78
+ });
79
+ // ❌ BAD: Global styles with hard-coded values
80
+ globalStyle('body', {
81
+ color: '#1f2937', // Hard-coded color
82
+ backgroundColor: '#ffffff', // Hard-coded color
83
+ margin: '0px', // Hard-coded spacing (though 0 is often allowed)
84
+ padding: '0px', // Hard-coded spacing
85
+ });
@@ -0,0 +1,27 @@
1
+ export declare const goodButton: string;
2
+ export declare const goodCard: string;
3
+ export declare const goodText: string;
4
+ export declare const goodBox: string;
5
+ export declare const goodComponent: string;
6
+ export declare const goodRecipe: import("@vanilla-extract/recipes").RuntimeFn<{
7
+ size: {
8
+ small: {
9
+ fontSize: any;
10
+ padding: any;
11
+ };
12
+ large: {
13
+ fontSize: any;
14
+ padding: any;
15
+ };
16
+ };
17
+ variant: {
18
+ primary: {
19
+ backgroundColor: any;
20
+ };
21
+ danger: {
22
+ backgroundColor: any;
23
+ };
24
+ };
25
+ }>;
26
+ export declare const goodResponsive: string;
27
+ export declare const goodMixed: string;
@@ -0,0 +1,94 @@
1
+ import { style, globalStyle } from '@vanilla-extract/css';
2
+ import { recipe } from '@vanilla-extract/recipes';
3
+ import { theme } from './sample-theme.css';
4
+ // ✅ GOOD: Using theme tokens for colors
5
+ export const goodButton = style({
6
+ color: theme.colors.text,
7
+ backgroundColor: theme.colors.primary,
8
+ borderColor: theme.colors.border,
9
+ });
10
+ // ✅ GOOD: Using theme tokens for spacing
11
+ export const goodCard = style({
12
+ padding: theme.spacing.md,
13
+ margin: theme.spacing.sm,
14
+ gap: theme.spacing.md,
15
+ width: '100%', // Percentages are allowed
16
+ });
17
+ // ✅ GOOD: Using theme tokens for font sizes
18
+ export const goodText = style({
19
+ fontSize: theme.fontSizes.sm,
20
+ lineHeight: theme.fontSizes.base,
21
+ });
22
+ // ✅ GOOD: Using theme tokens for border radius
23
+ export const goodBox = style({
24
+ borderRadius: theme.radii.md,
25
+ borderTopLeftRadius: theme.radii.sm,
26
+ });
27
+ // ✅ GOOD: All theme tokens
28
+ export const goodComponent = style({
29
+ color: theme.colors.text,
30
+ backgroundColor: theme.colors.background,
31
+ padding: theme.spacing.lg,
32
+ margin: `${theme.spacing.sm} ${theme.spacing.md}`,
33
+ fontSize: theme.fontSizes.base,
34
+ borderRadius: theme.radii.md,
35
+ border: `1px solid ${theme.colors.border}`,
36
+ });
37
+ // ✅ GOOD: Recipe with theme tokens
38
+ export const goodRecipe = recipe({
39
+ base: {
40
+ color: theme.colors.text,
41
+ padding: theme.spacing.md,
42
+ },
43
+ variants: {
44
+ size: {
45
+ small: {
46
+ fontSize: theme.fontSizes.sm,
47
+ padding: theme.spacing.sm,
48
+ },
49
+ large: {
50
+ fontSize: theme.fontSizes.xl,
51
+ padding: theme.spacing.xl,
52
+ },
53
+ },
54
+ variant: {
55
+ primary: {
56
+ backgroundColor: theme.colors.primary,
57
+ },
58
+ danger: {
59
+ backgroundColor: theme.colors.error,
60
+ },
61
+ },
62
+ },
63
+ });
64
+ // ✅ GOOD: Nested structures with theme tokens
65
+ export const goodResponsive = style({
66
+ color: theme.colors.text,
67
+ '@media': {
68
+ '(min-width: 768px)': {
69
+ padding: theme.spacing['2xl'],
70
+ fontSize: theme.fontSizes['2xl'],
71
+ },
72
+ },
73
+ selectors: {
74
+ '&:hover': {
75
+ backgroundColor: theme.colors.hover,
76
+ borderColor: theme.colors.primary,
77
+ },
78
+ },
79
+ });
80
+ // ✅ GOOD: Global styles with theme tokens
81
+ globalStyle('body', {
82
+ color: theme.colors.text,
83
+ backgroundColor: theme.colors.background,
84
+ margin: '0', // Special values like '0' are allowed
85
+ padding: '0',
86
+ });
87
+ // ✅ GOOD: Mixed with allowed values
88
+ export const goodMixed = style({
89
+ color: theme.colors.text,
90
+ margin: '0', // '0' is allowed
91
+ padding: 'auto', // 'auto' is allowed
92
+ width: '100%', // Percentages are allowed
93
+ height: 'inherit', // CSS keywords are allowed
94
+ });