@antebudimir/eslint-plugin-vanilla-extract 1.17.0 → 1.18.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 +50 -4
- package/dist/css-rules/no-empty-blocks/fix-utils.d.ts +10 -0
- package/dist/css-rules/no-empty-blocks/fix-utils.js +82 -21
- package/dist/css-rules/no-empty-blocks/rule-definition.js +13 -1
- 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/css-rules/sample.css.d.ts +76 -0
- package/dist/css-rules/sample.css.js +548 -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,52 @@ 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
|
+
|
|
608
|
+
If you intentionally use empty declarations as class-name hooks and don't want them reported at all, enable the
|
|
609
|
+
`ignoreReferenced` option:
|
|
610
|
+
|
|
611
|
+
#### Options
|
|
612
|
+
|
|
613
|
+
| Option | Type | Default | Description |
|
|
614
|
+
| ------------------ | --------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------ |
|
|
615
|
+
| `ignoreReferenced` | `boolean` | `false` | Don't report empty style declarations that are exported or still referenced elsewhere (e.g. intentional class-name hooks). |
|
|
616
|
+
|
|
617
|
+
```json
|
|
618
|
+
{
|
|
619
|
+
"rules": {
|
|
620
|
+
"vanilla-extract/no-empty-style-blocks": ["error", { "ignoreReferenced": true }]
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
```
|
|
624
|
+
|
|
625
|
+
Genuinely unused empty declarations are still reported and auto-removed with this option. Property-level detections
|
|
626
|
+
(empty selectors, `@media`/`@supports` objects, empty variant values, etc.) remain active too — only the
|
|
627
|
+
whole-declaration report for exported/referenced declarations is suppressed.
|
|
628
|
+
|
|
583
629
|
### vanilla-extract/no-px-unit
|
|
584
630
|
|
|
585
631
|
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 +883,7 @@ Enforces theme tokens instead of hard-coded CSS values. Analyzes your theme cont
|
|
|
837
883
|
**Options:**
|
|
838
884
|
|
|
839
885
|
| Option | Type | Default | Description |
|
|
840
|
-
|
|
886
|
+
| -------- | ------ | --------- | ------------- |
|
|
841
887
|
| `themeContracts` | `string[]` | `[]` | Theme contract file paths (relative to project root or absolute) |
|
|
842
888
|
| `checkColors` | `boolean` | `true` | Check colors (hex, rgb, hsl, named) |
|
|
843
889
|
| `checkSpacing` | `boolean` | `true` | Check spacing (margin, padding, gap, width, height) |
|
|
@@ -15,6 +15,16 @@ 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 isn't exported and its
|
|
20
|
+
* identifier isn't referenced anywhere else in the file
|
|
21
|
+
* those references (e.g. a `globalStyle()` selector or an import in another file).
|
|
22
|
+
*
|
|
23
|
+
* With the `ignoreReferenced` option enabled, declarations that can't be safely auto-removed
|
|
24
|
+
* are not reported at all (useful when empty declarations are used intentionally as
|
|
25
|
+
* class-name hooks). Property-level reports (empty selectors, variant values, etc.) are
|
|
26
|
+
* unaffected by this option.
|
|
27
|
+
*
|
|
18
28
|
* @param ruleContext The ESLint rule context.
|
|
19
29
|
* @param node The node to report the issue on.
|
|
20
30
|
* @param callNode The CallExpression node of the style() function.
|
|
@@ -32,8 +32,64 @@ 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 isn't exported and its
|
|
85
|
+
* identifier isn't referenced anywhere else in the file
|
|
86
|
+
* those references (e.g. a `globalStyle()` selector or an import in another file).
|
|
87
|
+
*
|
|
88
|
+
* With the `ignoreReferenced` option enabled, declarations that can't be safely auto-removed
|
|
89
|
+
* are not reported at all (useful when empty declarations are used intentionally as
|
|
90
|
+
* class-name hooks). Property-level reports (empty selectors, variant values, etc.) are
|
|
91
|
+
* unaffected by this option.
|
|
92
|
+
*
|
|
37
93
|
* @param ruleContext The ESLint rule context.
|
|
38
94
|
* @param node The node to report the issue on.
|
|
39
95
|
* @param callNode The CallExpression node of the style() function.
|
|
@@ -44,32 +100,37 @@ export const reportEmptyDeclaration = (ruleContext, node, callNode) => {
|
|
|
44
100
|
['globalStyle', 'globalFontFace', 'globalKeyframes'].includes(callNode.callee.name);
|
|
45
101
|
// Find the parent declaration node
|
|
46
102
|
const targetDeclarationNode = findTargetDeclarationNode(callNode, isGlobalApi);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
});
|
|
103
|
+
const isSafeToAutoRemove = targetDeclarationNode !== null && isDeclarationSafeToAutoRemove(ruleContext, targetDeclarationNode);
|
|
104
|
+
// With `ignoreReferenced`, declarations that can't be safely auto-removed (exported or still referenced elsewhere - e.g. intentional class-name hooks) are treated as intentional and not reported at all.
|
|
105
|
+
const options = ruleContext.options[0];
|
|
106
|
+
if (options?.ignoreReferenced === true && !isSafeToAutoRemove) {
|
|
107
|
+
return;
|
|
67
108
|
}
|
|
68
|
-
|
|
109
|
+
if (!isSafeToAutoRemove) {
|
|
69
110
|
// Report the issue without providing a fix
|
|
70
111
|
ruleContext.report({
|
|
71
112
|
node: node,
|
|
72
113
|
messageId: 'emptyStyleDeclaration',
|
|
73
114
|
});
|
|
115
|
+
return;
|
|
74
116
|
}
|
|
117
|
+
ruleContext.report({
|
|
118
|
+
node: node,
|
|
119
|
+
messageId: 'emptyStyleDeclaration',
|
|
120
|
+
fix(fixer) {
|
|
121
|
+
const sourceCode = ruleContext.sourceCode;
|
|
122
|
+
const startLine = sourceCode.getLocFromIndex(targetDeclarationNode.range[0]).line;
|
|
123
|
+
const lineStart = sourceCode.getIndexFromLoc({
|
|
124
|
+
line: startLine,
|
|
125
|
+
column: 0,
|
|
126
|
+
});
|
|
127
|
+
// Find next line after the declaration
|
|
128
|
+
const endLine = sourceCode.getLocFromIndex(targetDeclarationNode.range[1]).line;
|
|
129
|
+
const nextLineStart = sourceCode.getIndexFromLoc({
|
|
130
|
+
line: endLine + 1,
|
|
131
|
+
column: 0,
|
|
132
|
+
});
|
|
133
|
+
return fixer.removeRange([lineStart, nextLineStart]);
|
|
134
|
+
},
|
|
135
|
+
});
|
|
75
136
|
};
|
|
@@ -8,7 +8,19 @@ const noEmptyStyleBlocksRule = {
|
|
|
8
8
|
recommended: true,
|
|
9
9
|
},
|
|
10
10
|
fixable: 'code',
|
|
11
|
-
schema: [
|
|
11
|
+
schema: [
|
|
12
|
+
{
|
|
13
|
+
type: 'object',
|
|
14
|
+
properties: {
|
|
15
|
+
ignoreReferenced: {
|
|
16
|
+
type: 'boolean',
|
|
17
|
+
default: false,
|
|
18
|
+
description: `Don't report empty style declarations that are exported or still referenced elsewhere (e.g. intentional class-name hooks).`,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
additionalProperties: false,
|
|
22
|
+
},
|
|
23
|
+
],
|
|
12
24
|
messages: {
|
|
13
25
|
emptyConditionalStyle: 'Empty conditional style object should be removed.',
|
|
14
26
|
emptyMedia: 'Empty @media object should be removed.',
|
|
@@ -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,76 @@
|
|
|
1
|
+
export declare const theFont: string;
|
|
2
|
+
export declare const spinster: void;
|
|
3
|
+
export declare const buttonWrapper: string;
|
|
4
|
+
export declare const starter: string;
|
|
5
|
+
export declare const accordionContent: import("@vanilla-extract/recipes").RuntimeFn<{
|
|
6
|
+
isOpen: {
|
|
7
|
+
false: {
|
|
8
|
+
boxSizing: "inherit";
|
|
9
|
+
position: "relative";
|
|
10
|
+
right: "inherit";
|
|
11
|
+
display: "flex";
|
|
12
|
+
gap: "revert";
|
|
13
|
+
transform: "none";
|
|
14
|
+
margin: "11rem";
|
|
15
|
+
outline: "none";
|
|
16
|
+
border: "Background";
|
|
17
|
+
borderRight: "ActiveBorder";
|
|
18
|
+
borderLeft: "ActiveBorder";
|
|
19
|
+
borderRadius: "initial";
|
|
20
|
+
borderBottomLeftRadius: "initial";
|
|
21
|
+
borderBottomRightRadius: "initial";
|
|
22
|
+
boxShadow: "none";
|
|
23
|
+
backgroundColor: "initial";
|
|
24
|
+
cursor: "pointer";
|
|
25
|
+
width: "100%";
|
|
26
|
+
color: "red";
|
|
27
|
+
fontSize: "large";
|
|
28
|
+
};
|
|
29
|
+
true: {
|
|
30
|
+
boxSizing: "inherit";
|
|
31
|
+
position: "relative";
|
|
32
|
+
right: "inherit";
|
|
33
|
+
display: "flex";
|
|
34
|
+
gap: "revert";
|
|
35
|
+
transform: "none";
|
|
36
|
+
margin: "11rem";
|
|
37
|
+
outline: "none";
|
|
38
|
+
border: "Background";
|
|
39
|
+
borderRight: "ActiveBorder";
|
|
40
|
+
borderLeft: "ActiveBorder";
|
|
41
|
+
borderRadius: "initial";
|
|
42
|
+
borderBottomLeftRadius: "initial";
|
|
43
|
+
borderBottomRightRadius: "initial";
|
|
44
|
+
boxShadow: "none";
|
|
45
|
+
backgroundColor: "initial";
|
|
46
|
+
cursor: "pointer";
|
|
47
|
+
width: "100%";
|
|
48
|
+
color: "red";
|
|
49
|
+
fontSize: "large";
|
|
50
|
+
':hover': {
|
|
51
|
+
boxSizing: "inherit";
|
|
52
|
+
position: "relative";
|
|
53
|
+
right: "inherit";
|
|
54
|
+
display: "flex";
|
|
55
|
+
gap: "revert";
|
|
56
|
+
transform: "none";
|
|
57
|
+
margin: "11rem";
|
|
58
|
+
outline: "none";
|
|
59
|
+
border: "Background";
|
|
60
|
+
borderRight: "ActiveBorder";
|
|
61
|
+
borderLeft: "ActiveBorder";
|
|
62
|
+
borderRadius: "initial";
|
|
63
|
+
borderBottomLeftRadius: "initial";
|
|
64
|
+
borderBottomRightRadius: "initial";
|
|
65
|
+
boxShadow: "none";
|
|
66
|
+
backgroundColor: "initial";
|
|
67
|
+
cursor: "pointer";
|
|
68
|
+
width: "100%";
|
|
69
|
+
color: "red";
|
|
70
|
+
fontSize: "large";
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
}>;
|
|
75
|
+
export declare const item: string;
|
|
76
|
+
export declare const selectButtonVariants: Record<"bordered" | "borderless", string>;
|