@antebudimir/eslint-plugin-vanilla-extract 1.17.0 → 1.17.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 +29 -4
- package/dist/css-rules/no-empty-blocks/fix-utils.d.ts +4 -0
- package/dist/css-rules/no-empty-blocks/fix-utils.js +71 -22
- package/dist/css-rules/no-px-unit/no-px-unit-visitor-creator.d.ts +2 -0
- package/dist/css-rules/no-px-unit/no-px-unit-visitor-creator.js +55 -0
- package/dist/css-rules/no-px-unit/processor.d.ts +3 -0
- package/dist/css-rules/no-px-unit/processor.js +93 -0
- package/dist/css-rules/no-px-unit/visitor-creator.d.ts +2 -0
- package/dist/css-rules/no-px-unit/visitor-creator.js +55 -0
- package/dist/demo-bad-example.css.d.ts +4 -0
- package/dist/demo-bad-example.css.js +45 -0
- package/dist/demo-good-example.css.d.ts +5 -0
- package/dist/demo-good-example.css.js +48 -0
- package/dist/demo-theme.css.d.ts +37 -0
- package/dist/demo-theme.css.js +39 -0
- package/dist/index.js +1 -1
- package/dist/sample-bad.css.d.ts +26 -0
- package/dist/sample-bad.css.js +85 -0
- package/dist/sample-good.css.d.ts +27 -0
- package/dist/sample-good.css.js +94 -0
- package/dist/sample-theme.css.d.ts +37 -0
- package/dist/sample-theme.css.js +38 -0
- package/dist/sample.css.d.ts +75 -0
- package/dist/sample.css.js +530 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -366,7 +366,7 @@ export const myStyle = style({
|
|
|
366
366
|
});
|
|
367
367
|
```
|
|
368
368
|
|
|
369
|
-
#### Global setting: `settings['vanilla-extract'].style`
|
|
369
|
+
#### Global setting for alphabetical-order: `settings['vanilla-extract'].style`
|
|
370
370
|
|
|
371
371
|
`vanilla-extract/alphabetical-order` reads wrapper names from global ESLint settings.
|
|
372
372
|
|
|
@@ -420,7 +420,7 @@ export const myStyle = style({
|
|
|
420
420
|
});
|
|
421
421
|
```
|
|
422
422
|
|
|
423
|
-
#### Global setting: `settings['vanilla-extract'].style`
|
|
423
|
+
#### Global setting for concentric-order: `settings['vanilla-extract'].style`
|
|
424
424
|
|
|
425
425
|
Use this setting when style wrappers are imported from local modules (for example `componentStyle`, `layerStyle`).
|
|
426
426
|
If a wrapper function name is listed, the rule treats calls to that function like `style(...)` calls.
|
|
@@ -471,7 +471,7 @@ To configure the rule, add it to your ESLint configuration file with your desire
|
|
|
471
471
|
`groups` array to include any number of available CSS property groups you want to enforce, with a minimum of one group
|
|
472
472
|
required.
|
|
473
473
|
|
|
474
|
-
#### Global setting: `settings['vanilla-extract'].style`
|
|
474
|
+
#### Global setting for custom-order: `settings['vanilla-extract'].style`
|
|
475
475
|
|
|
476
476
|
`vanilla-extract/custom-order` also reads `style` from global settings together with
|
|
477
477
|
`groupOrder` and `sortRemainingProperties`.
|
|
@@ -580,6 +580,31 @@ export const recipeWithEmptyVariants = recipe({
|
|
|
580
580
|
});
|
|
581
581
|
```
|
|
582
582
|
|
|
583
|
+
#### Autofix safety
|
|
584
|
+
|
|
585
|
+
Rule only auto-removes a declaration when it's safe to do so. Declarations are **reported without an
|
|
586
|
+
autofix** (you must resolve them manually) when:
|
|
587
|
+
|
|
588
|
+
- the declaration's **exported** (`export const x = style({})`) — exported identifiers can be imported and
|
|
589
|
+
used as a `className` in other files the rule can't see.
|
|
590
|
+
- the identifier's **still referenced elsewhere in the same file** — e.g. used as a class-name hook inside a
|
|
591
|
+
`globalStyle()` selector template literal:
|
|
592
|
+
|
|
593
|
+
```typescript
|
|
594
|
+
// ❌ Reported, but not auto-fixed (the identifier's still referenced)
|
|
595
|
+
import { globalStyle, style } from '@vanilla-extract/css';
|
|
596
|
+
|
|
597
|
+
// used only as a class-name hook, not for its own props
|
|
598
|
+
export const buttonWrapper = style({});
|
|
599
|
+
|
|
600
|
+
globalStyle(`${buttonWrapper} > svg`, {
|
|
601
|
+
color: 'red',
|
|
602
|
+
});
|
|
603
|
+
```
|
|
604
|
+
|
|
605
|
+
Empty blocks that declare no identifier (e.g. `globalStyle('ul', {})`) and unreferenced, non-exported
|
|
606
|
+
declarations remain fully auto-fixable.
|
|
607
|
+
|
|
583
608
|
### vanilla-extract/no-px-unit
|
|
584
609
|
|
|
585
610
|
This rule disallows the use of hard-coded `px` units in vanilla-extract style declarations. Prefer `rem`, `em`, or theme tokens. A configurable allowlist lets you permit specific properties to use `px` where necessary. Allowlist supports both camelCase and kebab-case property names.
|
|
@@ -837,7 +862,7 @@ Enforces theme tokens instead of hard-coded CSS values. Analyzes your theme cont
|
|
|
837
862
|
**Options:**
|
|
838
863
|
|
|
839
864
|
| Option | Type | Default | Description |
|
|
840
|
-
|
|
865
|
+
| -------- | ------ | --------- | ------------- |
|
|
841
866
|
| `themeContracts` | `string[]` | `[]` | Theme contract file paths (relative to project root or absolute) |
|
|
842
867
|
| `checkColors` | `boolean` | `true` | Check colors (hex, rgb, hsl, named) |
|
|
843
868
|
| `checkSpacing` | `boolean` | `true` | Check spacing (margin, padding, gap, width, height) |
|
|
@@ -15,6 +15,10 @@ import { TSESTree } from '@typescript-eslint/utils';
|
|
|
15
15
|
export declare const findTargetDeclarationNode: (callNode: TSESTree.CallExpression, isGlobalApi: boolean) => TSESTree.Node | null;
|
|
16
16
|
/**
|
|
17
17
|
* Reports an issue for an empty style declaration, and provides a fix to remove the declaration.
|
|
18
|
+
*
|
|
19
|
+
* The removal autofix is only provided when the declaration is not exported and its
|
|
20
|
+
* identifier is not referenced anywhere else in the file - otherwise the fix would break
|
|
21
|
+
* those references (e.g. a `globalStyle()` selector or an import in another file).
|
|
18
22
|
* @param ruleContext The ESLint rule context.
|
|
19
23
|
* @param node The node to report the issue on.
|
|
20
24
|
* @param callNode The CallExpression node of the style() function.
|
|
@@ -32,8 +32,58 @@ export const findTargetDeclarationNode = (callNode, isGlobalApi) => {
|
|
|
32
32
|
}
|
|
33
33
|
return null;
|
|
34
34
|
};
|
|
35
|
+
/**
|
|
36
|
+
* Determines whether the given declaration node can safely be removed by the autofix.
|
|
37
|
+
*
|
|
38
|
+
* The autofix must NOT remove a declaration when doing so would leave dangling
|
|
39
|
+
* references to its identifier:
|
|
40
|
+
*
|
|
41
|
+
* 1. Exported declarations (`export const x = style({})`) are never auto-removed.
|
|
42
|
+
* Exported identifiers can be consumed in other files (e.g. as a `className`)
|
|
43
|
+
* that this rule has no visibility into.
|
|
44
|
+
*
|
|
45
|
+
* 2. Declarations whose identifier is still referenced elsewhere in the same file
|
|
46
|
+
* (e.g. interpolated into a `globalStyle()` selector template literal, or listed
|
|
47
|
+
* in a separate `export { x }` statement) are never auto-removed.
|
|
48
|
+
*
|
|
49
|
+
* In both cases the empty style block is still reported, just without a fix, so the
|
|
50
|
+
* developer can resolve the usages manually.
|
|
51
|
+
*/
|
|
52
|
+
const isDeclarationSafeToAutoRemove = (ruleContext, declarationNode) => {
|
|
53
|
+
// Exported bindings may be used in other files - never auto-remove them.
|
|
54
|
+
if (declarationNode.type === 'ExportNamedDeclaration' || declarationNode.type === 'ExportDefaultDeclaration') {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
if (declarationNode.type !== 'VariableDeclaration') {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
const sourceCode = ruleContext.sourceCode;
|
|
61
|
+
const declarationRange = declarationNode.range;
|
|
62
|
+
if (!declarationRange) {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
return declarationNode.declarations.every((declarator) => {
|
|
66
|
+
const declaredVariables = sourceCode.getDeclaredVariables(declarator);
|
|
67
|
+
return declaredVariables.every((variable) => {
|
|
68
|
+
return !variable.references.some((reference) => {
|
|
69
|
+
const identifier = reference.identifier;
|
|
70
|
+
if (!identifier || !identifier.range) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
// The binding identifier itself lives inside the declaration - only
|
|
74
|
+
// references outside of it are actual usages of the identifier.
|
|
75
|
+
const isInsideDeclaration = identifier.range[0] >= declarationRange[0] && identifier.range[1] <= declarationRange[1];
|
|
76
|
+
return !isInsideDeclaration;
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
};
|
|
35
81
|
/**
|
|
36
82
|
* Reports an issue for an empty style declaration, and provides a fix to remove the declaration.
|
|
83
|
+
*
|
|
84
|
+
* The removal autofix is only provided when the declaration is not exported and its
|
|
85
|
+
* identifier is not referenced anywhere else in the file - otherwise the fix would break
|
|
86
|
+
* those references (e.g. a `globalStyle()` selector or an import in another file).
|
|
37
87
|
* @param ruleContext The ESLint rule context.
|
|
38
88
|
* @param node The node to report the issue on.
|
|
39
89
|
* @param callNode The CallExpression node of the style() function.
|
|
@@ -44,32 +94,31 @@ export const reportEmptyDeclaration = (ruleContext, node, callNode) => {
|
|
|
44
94
|
['globalStyle', 'globalFontFace', 'globalKeyframes'].includes(callNode.callee.name);
|
|
45
95
|
// Find the parent declaration node
|
|
46
96
|
const targetDeclarationNode = findTargetDeclarationNode(callNode, isGlobalApi);
|
|
47
|
-
if (targetDeclarationNode) {
|
|
48
|
-
ruleContext.report({
|
|
49
|
-
node: node,
|
|
50
|
-
messageId: 'emptyStyleDeclaration',
|
|
51
|
-
fix(fixer) {
|
|
52
|
-
const sourceCode = ruleContext.sourceCode;
|
|
53
|
-
const startLine = sourceCode.getLocFromIndex(targetDeclarationNode.range[0]).line;
|
|
54
|
-
const lineStart = sourceCode.getIndexFromLoc({
|
|
55
|
-
line: startLine,
|
|
56
|
-
column: 0,
|
|
57
|
-
});
|
|
58
|
-
// Find next line after the declaration
|
|
59
|
-
const endLine = sourceCode.getLocFromIndex(targetDeclarationNode.range[1]).line;
|
|
60
|
-
const nextLineStart = sourceCode.getIndexFromLoc({
|
|
61
|
-
line: endLine + 1,
|
|
62
|
-
column: 0,
|
|
63
|
-
});
|
|
64
|
-
return fixer.removeRange([lineStart, nextLineStart]);
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
97
|
+
if (!targetDeclarationNode || !isDeclarationSafeToAutoRemove(ruleContext, targetDeclarationNode)) {
|
|
69
98
|
// Report the issue without providing a fix
|
|
70
99
|
ruleContext.report({
|
|
71
100
|
node: node,
|
|
72
101
|
messageId: 'emptyStyleDeclaration',
|
|
73
102
|
});
|
|
103
|
+
return;
|
|
74
104
|
}
|
|
105
|
+
ruleContext.report({
|
|
106
|
+
node: node,
|
|
107
|
+
messageId: 'emptyStyleDeclaration',
|
|
108
|
+
fix(fixer) {
|
|
109
|
+
const sourceCode = ruleContext.sourceCode;
|
|
110
|
+
const startLine = sourceCode.getLocFromIndex(targetDeclarationNode.range[0]).line;
|
|
111
|
+
const lineStart = sourceCode.getIndexFromLoc({
|
|
112
|
+
line: startLine,
|
|
113
|
+
column: 0,
|
|
114
|
+
});
|
|
115
|
+
// Find next line after the declaration
|
|
116
|
+
const endLine = sourceCode.getLocFromIndex(targetDeclarationNode.range[1]).line;
|
|
117
|
+
const nextLineStart = sourceCode.getIndexFromLoc({
|
|
118
|
+
line: endLine + 1,
|
|
119
|
+
column: 0,
|
|
120
|
+
});
|
|
121
|
+
return fixer.removeRange([lineStart, nextLineStart]);
|
|
122
|
+
},
|
|
123
|
+
});
|
|
75
124
|
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
import { processRecipeProperties } from '../shared-utils/recipe-property-processor.js';
|
|
3
|
+
import { ReferenceTracker, createReferenceTrackingVisitor } from '../shared-utils/reference-tracker.js';
|
|
4
|
+
import { processStyleNode } from '../shared-utils/style-node-processor.js';
|
|
5
|
+
import { processNoPxUnitInStyleObject } from './processor.js';
|
|
6
|
+
export const createNoPxUnitVisitors = (context) => {
|
|
7
|
+
const tracker = new ReferenceTracker();
|
|
8
|
+
const trackingVisitor = createReferenceTrackingVisitor(tracker);
|
|
9
|
+
const options = context.options?.[0] || {};
|
|
10
|
+
const allowSet = new Set((options.allow ?? []).map((s) => s));
|
|
11
|
+
const process = (ctx, obj) => processNoPxUnitInStyleObject(ctx, obj, allowSet);
|
|
12
|
+
return {
|
|
13
|
+
...trackingVisitor,
|
|
14
|
+
CallExpression(node) {
|
|
15
|
+
if (node.callee.type !== AST_NODE_TYPES.Identifier)
|
|
16
|
+
return;
|
|
17
|
+
const functionName = node.callee.name;
|
|
18
|
+
if (!tracker.isTrackedFunction(functionName))
|
|
19
|
+
return;
|
|
20
|
+
const originalName = tracker.getOriginalName(functionName);
|
|
21
|
+
if (!originalName)
|
|
22
|
+
return;
|
|
23
|
+
switch (originalName) {
|
|
24
|
+
case 'fontFace':
|
|
25
|
+
if (node.arguments.length > 0 && node.arguments[0]?.type === AST_NODE_TYPES.ObjectExpression) {
|
|
26
|
+
process(context, node.arguments[0]);
|
|
27
|
+
}
|
|
28
|
+
break;
|
|
29
|
+
case 'globalFontFace':
|
|
30
|
+
if (node.arguments.length > 1 && node.arguments[1]?.type === AST_NODE_TYPES.ObjectExpression) {
|
|
31
|
+
process(context, node.arguments[1]);
|
|
32
|
+
}
|
|
33
|
+
break;
|
|
34
|
+
case 'style':
|
|
35
|
+
case 'styleVariants':
|
|
36
|
+
case 'keyframes':
|
|
37
|
+
if (node.arguments.length > 0) {
|
|
38
|
+
processStyleNode(context, node.arguments[0], (ctx, obj) => process(ctx, obj));
|
|
39
|
+
}
|
|
40
|
+
break;
|
|
41
|
+
case 'globalStyle':
|
|
42
|
+
case 'globalKeyframes':
|
|
43
|
+
if (node.arguments.length >= 2) {
|
|
44
|
+
processStyleNode(context, node.arguments[1], (ctx, obj) => process(ctx, obj));
|
|
45
|
+
}
|
|
46
|
+
break;
|
|
47
|
+
case 'recipe':
|
|
48
|
+
if (node.arguments.length > 0 && node.arguments[0]?.type === AST_NODE_TYPES.ObjectExpression) {
|
|
49
|
+
processRecipeProperties(context, node.arguments[0], (ctx, obj) => process(ctx, obj));
|
|
50
|
+
}
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
import { processRecipeProperties } from '../shared-utils/recipe-property-processor.js';
|
|
3
|
+
import { ReferenceTracker, createReferenceTrackingVisitor } from '../shared-utils/reference-tracker.js';
|
|
4
|
+
import { processStyleNode } from '../shared-utils/style-node-processor.js';
|
|
5
|
+
import { processNoPxUnitInStyleObject } from './processor.js';
|
|
6
|
+
export const createNoPxUnitVisitors = (context) => {
|
|
7
|
+
const tracker = new ReferenceTracker();
|
|
8
|
+
const trackingVisitor = createReferenceTrackingVisitor(tracker);
|
|
9
|
+
const options = context.options?.[0] || {};
|
|
10
|
+
const allowSet = new Set((options.allow ?? []).map((s) => s));
|
|
11
|
+
const process = (ctx, obj) => processNoPxUnitInStyleObject(ctx, obj, allowSet);
|
|
12
|
+
return {
|
|
13
|
+
...trackingVisitor,
|
|
14
|
+
CallExpression(node) {
|
|
15
|
+
if (node.callee.type !== AST_NODE_TYPES.Identifier)
|
|
16
|
+
return;
|
|
17
|
+
const functionName = node.callee.name;
|
|
18
|
+
if (!tracker.isTrackedFunction(functionName))
|
|
19
|
+
return;
|
|
20
|
+
const originalName = tracker.getOriginalName(functionName);
|
|
21
|
+
if (!originalName)
|
|
22
|
+
return;
|
|
23
|
+
switch (originalName) {
|
|
24
|
+
case 'fontFace':
|
|
25
|
+
if (node.arguments.length > 0 && node.arguments[0]?.type === AST_NODE_TYPES.ObjectExpression) {
|
|
26
|
+
process(context, node.arguments[0]);
|
|
27
|
+
}
|
|
28
|
+
break;
|
|
29
|
+
case 'globalFontFace':
|
|
30
|
+
if (node.arguments.length > 1 && node.arguments[1]?.type === AST_NODE_TYPES.ObjectExpression) {
|
|
31
|
+
process(context, node.arguments[1]);
|
|
32
|
+
}
|
|
33
|
+
break;
|
|
34
|
+
case 'style':
|
|
35
|
+
case 'styleVariants':
|
|
36
|
+
case 'keyframes':
|
|
37
|
+
if (node.arguments.length > 0) {
|
|
38
|
+
processStyleNode(context, node.arguments[0], (ctx, obj) => process(ctx, obj));
|
|
39
|
+
}
|
|
40
|
+
break;
|
|
41
|
+
case 'globalStyle':
|
|
42
|
+
case 'globalKeyframes':
|
|
43
|
+
if (node.arguments.length >= 2) {
|
|
44
|
+
processStyleNode(context, node.arguments[1], (ctx, obj) => process(ctx, obj));
|
|
45
|
+
}
|
|
46
|
+
break;
|
|
47
|
+
case 'recipe':
|
|
48
|
+
if (node.arguments.length > 0 && node.arguments[0]?.type === AST_NODE_TYPES.ObjectExpression) {
|
|
49
|
+
processRecipeProperties(context, node.arguments[0], (ctx, obj) => process(ctx, obj));
|
|
50
|
+
}
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
};
|
|
@@ -0,0 +1,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,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.js
CHANGED
|
@@ -12,7 +12,7 @@ import preferThemeTokensRule from './css-rules/prefer-theme-tokens/index.js';
|
|
|
12
12
|
const vanillaExtract = {
|
|
13
13
|
meta: {
|
|
14
14
|
name: '@antebudimir/eslint-plugin-vanilla-extract',
|
|
15
|
-
version: '1.17.
|
|
15
|
+
version: '1.17.1',
|
|
16
16
|
},
|
|
17
17
|
rules: {
|
|
18
18
|
'alphabetical-order': alphabeticalOrderRule,
|
|
@@ -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;
|