@antebudimir/eslint-plugin-vanilla-extract 1.14.0 → 1.15.1
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 +111 -3
- package/dist/css-rules/no-empty-blocks/empty-style-visitor-creator.js +8 -2
- package/dist/css-rules/no-empty-blocks/recipe-processor.js +23 -3
- package/dist/css-rules/prefer-theme-tokens/index.d.ts +2 -0
- package/dist/css-rules/prefer-theme-tokens/index.js +2 -0
- package/dist/css-rules/prefer-theme-tokens/rule-definition.d.ts +3 -0
- package/dist/css-rules/prefer-theme-tokens/rule-definition.js +119 -0
- package/dist/css-rules/prefer-theme-tokens/theme-contract-analyzer.d.ts +60 -0
- package/dist/css-rules/prefer-theme-tokens/theme-contract-analyzer.js +322 -0
- package/dist/css-rules/prefer-theme-tokens/theme-token-processor.d.ts +26 -0
- package/dist/css-rules/prefer-theme-tokens/theme-token-processor.js +562 -0
- package/dist/css-rules/prefer-theme-tokens/theme-token-visitor-creator.d.ts +6 -0
- package/dist/css-rules/{no-px-unit/visitor-creator.js → prefer-theme-tokens/theme-token-visitor-creator.js} +36 -10
- package/dist/css-rules/prefer-theme-tokens/value-evaluator.d.ts +43 -0
- package/dist/css-rules/prefer-theme-tokens/value-evaluator.js +190 -0
- package/dist/css-rules/shared-utils/empty-object-processor.d.ts +5 -0
- package/dist/css-rules/shared-utils/empty-object-processor.js +11 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/package.json +6 -1
- package/dist/css-rules/no-px-unit/no-px-unit-visitor-creator.d.ts +0 -2
- package/dist/css-rules/no-px-unit/no-px-unit-visitor-creator.js +0 -55
- package/dist/css-rules/no-px-unit/processor.d.ts +0 -3
- package/dist/css-rules/no-px-unit/processor.js +0 -93
- package/dist/css-rules/no-px-unit/visitor-creator.d.ts +0 -2
- package/dist/sample.css.d.ts +0 -75
- package/dist/sample.css.js +0 -540
|
@@ -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
|
+
}
|
|
@@ -9,3 +9,8 @@ export declare const isObjectExpression: (node: TSESTree.Node) => node is TSESTr
|
|
|
9
9
|
* @returns True if the node is an ObjectExpression with no properties.
|
|
10
10
|
*/
|
|
11
11
|
export declare const isEmptyObject: (node: TSESTree.Node) => boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Checks if a CallExpression has an empty object as its first argument.
|
|
14
|
+
* Examples: sprinkles({}), style({}), recipe({})
|
|
15
|
+
*/
|
|
16
|
+
export declare const isCallExpressionWithEmptyObject: (node: TSESTree.CallExpression) => boolean;
|
|
@@ -13,3 +13,14 @@ export const isObjectExpression = (node) => {
|
|
|
13
13
|
export const isEmptyObject = (node) => {
|
|
14
14
|
return isObjectExpression(node) && node.properties.length === 0;
|
|
15
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* Checks if a CallExpression has an empty object as its first argument.
|
|
18
|
+
* Examples: sprinkles({}), style({}), recipe({})
|
|
19
|
+
*/
|
|
20
|
+
export const isCallExpressionWithEmptyObject = (node) => {
|
|
21
|
+
if (node.arguments.length === 0) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
const firstArgument = node.arguments[0];
|
|
25
|
+
return firstArgument?.type === 'ObjectExpression' && isEmptyObject(firstArgument);
|
|
26
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ declare const vanillaExtract: {
|
|
|
13
13
|
'no-unknown-unit': import("eslint").Rule.RuleModule;
|
|
14
14
|
'no-zero-unit': import("eslint").Rule.RuleModule;
|
|
15
15
|
'prefer-logical-properties': import("eslint").Rule.RuleModule;
|
|
16
|
+
'prefer-theme-tokens': import("eslint").Rule.RuleModule;
|
|
16
17
|
};
|
|
17
18
|
configs: {};
|
|
18
19
|
};
|
package/dist/index.js
CHANGED
|
@@ -7,10 +7,11 @@ 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
9
|
import preferLogicalPropertiesRule from './css-rules/prefer-logical-properties/index.js';
|
|
10
|
+
import preferThemeTokensRule from './css-rules/prefer-theme-tokens/index.js';
|
|
10
11
|
const vanillaExtract = {
|
|
11
12
|
meta: {
|
|
12
13
|
name: '@antebudimir/eslint-plugin-vanilla-extract',
|
|
13
|
-
version: '1.
|
|
14
|
+
version: '1.15.1',
|
|
14
15
|
},
|
|
15
16
|
rules: {
|
|
16
17
|
'alphabetical-order': alphabeticalOrderRule,
|
|
@@ -22,6 +23,7 @@ const vanillaExtract = {
|
|
|
22
23
|
'no-unknown-unit': noUnknownUnitRule,
|
|
23
24
|
'no-zero-unit': noZeroUnitRule,
|
|
24
25
|
'prefer-logical-properties': preferLogicalPropertiesRule,
|
|
26
|
+
'prefer-theme-tokens': preferThemeTokensRule,
|
|
25
27
|
},
|
|
26
28
|
configs: {},
|
|
27
29
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antebudimir/eslint-plugin-vanilla-extract",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.15.1",
|
|
4
4
|
"description": "Comprehensive ESLint plugin for vanilla-extract with CSS property ordering, style validation, and best practices enforcement. Supports alphabetical, concentric and custom CSS ordering, auto-fixing, and zero-runtime safety.",
|
|
5
5
|
"author": "Ante Budimir",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,6 +47,10 @@
|
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"eslint": ">=8.57.0"
|
|
49
49
|
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@babel/parser": "^7.28.5",
|
|
52
|
+
"@babel/types": "^7.28.5"
|
|
53
|
+
},
|
|
50
54
|
"devDependencies": {
|
|
51
55
|
"@eslint/eslintrc": "^3.3.0",
|
|
52
56
|
"@types/node": "^20.17.24",
|
|
@@ -56,6 +60,7 @@
|
|
|
56
60
|
"@typescript-eslint/utils": "^8.26.1",
|
|
57
61
|
"@vanilla-extract/css": "^1.17.1",
|
|
58
62
|
"@vanilla-extract/recipes": "^0.5.5",
|
|
63
|
+
"@vanilla-extract/sprinkles": "^1.6.0",
|
|
59
64
|
"@vitest/coverage-v8": "3.0.8",
|
|
60
65
|
"eslint": "^9.22.0",
|
|
61
66
|
"eslint-config-prettier": "^10.1.1",
|
|
@@ -1,55 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';
|
|
2
|
-
const containsPx = (text) => /(^|\W)-?\d*\.?\d*px(?![a-zA-Z])/i.test(text);
|
|
3
|
-
const replacePxWith = (text, replacement) => text.replace(/px(?![a-zA-Z])/g, replacement);
|
|
4
|
-
const toKebab = (name) => name.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
|
|
5
|
-
const getValueText = (node) => {
|
|
6
|
-
if (node.type === AST_NODE_TYPES.Literal && typeof node.value === 'string') {
|
|
7
|
-
return node.value;
|
|
8
|
-
}
|
|
9
|
-
if (node.type === AST_NODE_TYPES.TemplateLiteral) {
|
|
10
|
-
// Join all quasis (ignore expressions content)
|
|
11
|
-
const raw = node.quasis.map((q) => q.value.raw ?? '').join('');
|
|
12
|
-
return raw;
|
|
13
|
-
}
|
|
14
|
-
return null;
|
|
15
|
-
};
|
|
16
|
-
const canSuggestFix = (node) => {
|
|
17
|
-
if (node.type === AST_NODE_TYPES.Literal && typeof node.value === 'string')
|
|
18
|
-
return 'literal';
|
|
19
|
-
if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0)
|
|
20
|
-
return 'simple-template';
|
|
21
|
-
return null;
|
|
22
|
-
};
|
|
23
|
-
export const processNoPxUnitInStyleObject = (context, node, allowSet) => {
|
|
24
|
-
for (const property of node.properties) {
|
|
25
|
-
if (property.type !== AST_NODE_TYPES.Property)
|
|
26
|
-
continue;
|
|
27
|
-
// Determine property name when possible
|
|
28
|
-
let propertyName = null;
|
|
29
|
-
if (property.key.type === AST_NODE_TYPES.Identifier) {
|
|
30
|
-
propertyName = property.key.name;
|
|
31
|
-
}
|
|
32
|
-
else if (property.key.type === AST_NODE_TYPES.Literal && typeof property.key.value === 'string') {
|
|
33
|
-
propertyName = property.key.value;
|
|
34
|
-
}
|
|
35
|
-
// Recurse into known nested containers
|
|
36
|
-
if (propertyName === '@media' || propertyName === 'selectors') {
|
|
37
|
-
if (property.value.type === AST_NODE_TYPES.ObjectExpression) {
|
|
38
|
-
for (const nested of property.value.properties) {
|
|
39
|
-
if (nested.type === AST_NODE_TYPES.Property && nested.value.type === AST_NODE_TYPES.ObjectExpression) {
|
|
40
|
-
processNoPxUnitInStyleObject(context, nested.value, allowSet);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
// Traverse any nested object
|
|
47
|
-
if (property.value.type === AST_NODE_TYPES.ObjectExpression) {
|
|
48
|
-
processNoPxUnitInStyleObject(context, property.value, allowSet);
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
// Skip if property is whitelisted (supports both camelCase and kebab-case)
|
|
52
|
-
if (propertyName) {
|
|
53
|
-
const kebab = toKebab(propertyName);
|
|
54
|
-
if (allowSet.has(propertyName) || allowSet.has(kebab)) {
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
// Check string or template literal values
|
|
59
|
-
const text = getValueText(property.value);
|
|
60
|
-
if (text && containsPx(text)) {
|
|
61
|
-
const fixability = canSuggestFix(property.value);
|
|
62
|
-
context.report({
|
|
63
|
-
node: property.value,
|
|
64
|
-
messageId: 'noPxUnit',
|
|
65
|
-
suggest: fixability
|
|
66
|
-
? [
|
|
67
|
-
{
|
|
68
|
-
messageId: 'removePx',
|
|
69
|
-
fix: (fixer) => {
|
|
70
|
-
const newText = replacePxWith(text, '');
|
|
71
|
-
if (fixability === 'literal') {
|
|
72
|
-
return fixer.replaceText(property.value, `'${newText}'`);
|
|
73
|
-
}
|
|
74
|
-
// simple template with no expressions
|
|
75
|
-
return fixer.replaceText(property.value, `\`${newText}\``);
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
messageId: 'replaceWithRem',
|
|
80
|
-
fix: (fixer) => {
|
|
81
|
-
const newText = replacePxWith(text, 'rem');
|
|
82
|
-
if (fixability === 'literal') {
|
|
83
|
-
return fixer.replaceText(property.value, `'${newText}'`);
|
|
84
|
-
}
|
|
85
|
-
return fixer.replaceText(property.value, `\`${newText}\``);
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
]
|
|
89
|
-
: undefined,
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
};
|
package/dist/sample.css.d.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
export declare const theFont: string;
|
|
2
|
-
export declare const spinster: void;
|
|
3
|
-
export declare const starter: string;
|
|
4
|
-
export declare const accordionContent: import("@vanilla-extract/recipes").RuntimeFn<{
|
|
5
|
-
isOpen: {
|
|
6
|
-
false: {
|
|
7
|
-
boxSizing: "inherit";
|
|
8
|
-
position: "relative";
|
|
9
|
-
insetInlineEnd: "inherit";
|
|
10
|
-
display: "flex";
|
|
11
|
-
gap: "revert";
|
|
12
|
-
transform: "none";
|
|
13
|
-
margin: "11rem";
|
|
14
|
-
outline: "none";
|
|
15
|
-
border: "Background";
|
|
16
|
-
borderRadius: "initial";
|
|
17
|
-
borderEndStartRadius: "initial";
|
|
18
|
-
borderEndEndRadius: "initial";
|
|
19
|
-
borderInlineStart: "ActiveBorder";
|
|
20
|
-
borderInlineEnd: "ActiveBorder";
|
|
21
|
-
boxShadow: "none";
|
|
22
|
-
backgroundColor: "initial";
|
|
23
|
-
cursor: "pointer";
|
|
24
|
-
inlineSize: "100%";
|
|
25
|
-
color: "red";
|
|
26
|
-
fontSize: "large";
|
|
27
|
-
};
|
|
28
|
-
true: {
|
|
29
|
-
boxSizing: "inherit";
|
|
30
|
-
position: "relative";
|
|
31
|
-
insetInlineEnd: "inherit";
|
|
32
|
-
display: "flex";
|
|
33
|
-
gap: "revert";
|
|
34
|
-
transform: "none";
|
|
35
|
-
margin: "11rem";
|
|
36
|
-
outline: "none";
|
|
37
|
-
border: "Background";
|
|
38
|
-
borderRadius: "initial";
|
|
39
|
-
borderEndStartRadius: "initial";
|
|
40
|
-
borderEndEndRadius: "initial";
|
|
41
|
-
borderInlineStart: "ActiveBorder";
|
|
42
|
-
borderInlineEnd: "ActiveBorder";
|
|
43
|
-
boxShadow: "none";
|
|
44
|
-
backgroundColor: "initial";
|
|
45
|
-
cursor: "pointer";
|
|
46
|
-
inlineSize: "100%";
|
|
47
|
-
color: "red";
|
|
48
|
-
fontSize: "large";
|
|
49
|
-
':hover': {
|
|
50
|
-
boxSizing: "inherit";
|
|
51
|
-
position: "relative";
|
|
52
|
-
insetInlineEnd: "inherit";
|
|
53
|
-
display: "flex";
|
|
54
|
-
gap: "revert";
|
|
55
|
-
transform: "none";
|
|
56
|
-
margin: "11rem";
|
|
57
|
-
outline: "none";
|
|
58
|
-
border: "Background";
|
|
59
|
-
borderRadius: "initial";
|
|
60
|
-
borderEndStartRadius: "initial";
|
|
61
|
-
borderEndEndRadius: "initial";
|
|
62
|
-
borderInlineStart: "ActiveBorder";
|
|
63
|
-
borderInlineEnd: "ActiveBorder";
|
|
64
|
-
boxShadow: "none";
|
|
65
|
-
backgroundColor: "initial";
|
|
66
|
-
cursor: "pointer";
|
|
67
|
-
inlineSize: "100%";
|
|
68
|
-
color: "red";
|
|
69
|
-
fontSize: "large";
|
|
70
|
-
};
|
|
71
|
-
};
|
|
72
|
-
};
|
|
73
|
-
}>;
|
|
74
|
-
export declare const item: string;
|
|
75
|
-
export declare const selectButtonVariants: Record<"bordered" | "borderless", string>;
|