@antebudimir/eslint-plugin-vanilla-extract 1.1.2 → 1.4.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 +44 -7
- package/dist/css-rules/alphabetical-order/property-order-enforcer.js +1 -11
- package/dist/css-rules/alphabetical-order/rule-definition.js +2 -1
- package/dist/css-rules/concentric-order/property-order-enforcer.js +2 -2
- package/dist/css-rules/concentric-order/rule-definition.js +3 -1
- package/dist/css-rules/custom-order/rule-definition.js +1 -0
- package/dist/css-rules/shared-utils/alphabetical-property-comparator.d.ts +8 -0
- package/dist/css-rules/shared-utils/alphabetical-property-comparator.js +19 -0
- package/dist/css-rules/shared-utils/font-face-property-order-enforcer.d.ts +10 -0
- package/dist/css-rules/shared-utils/font-face-property-order-enforcer.js +39 -0
- package/dist/css-rules/shared-utils/font-face-style-processor.d.ts +10 -0
- package/dist/css-rules/shared-utils/font-face-style-processor.js +17 -0
- package/dist/css-rules/shared-utils/order-strategy-visitor-creator.js +22 -7
- package/dist/css-rules/theme-tokens/ast-helpers.d.ts +12 -0
- package/dist/css-rules/theme-tokens/ast-helpers.js +80 -0
- package/dist/css-rules/theme-tokens/index.d.ts +2 -0
- package/dist/css-rules/theme-tokens/index.js +2 -0
- package/dist/css-rules/theme-tokens/rule-definition.d.ts +3 -0
- package/dist/css-rules/theme-tokens/rule-definition.js +29 -0
- package/dist/css-rules/theme-tokens/theme-loader.d.ts +10 -0
- package/dist/css-rules/theme-tokens/theme-loader.js +71 -0
- package/dist/css-rules/theme-tokens/theme-token-visitor.d.ts +2 -0
- package/dist/css-rules/theme-tokens/theme-token-visitor.js +113 -0
- package/dist/css-rules/theme-tokens/theme-tokens-enforcer.d.ts +1 -0
- package/dist/css-rules/theme-tokens/theme-tokens-enforcer.js +1 -0
- package/dist/css-rules/theme-tokens/value-comparison.d.ts +1 -0
- package/dist/css-rules/theme-tokens/value-comparison.js +1 -0
- package/dist/index.js +1 -1
- package/package.json +4 -5
- package/dist/css-sample/sample.css.d.ts +0 -161
- package/dist/css-sample/sample.css.js +0 -551
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// /* eslint-disable no-console */
|
|
2
|
+
// import type { Rule } from 'eslint';
|
|
3
|
+
// import { TSESTree } from '@typescript-eslint/utils';
|
|
4
|
+
// import { isVanillaExtractStyleCall, findThemeTokenForValue } from './ast-helpers.js';
|
|
5
|
+
// import { loadThemeTokens } from './theme-loader.js';
|
|
6
|
+
import { TSESTree } from '@typescript-eslint/utils';
|
|
7
|
+
import { createNodeVisitors } from '../shared-utils/order-strategy-visitor-creator.js';
|
|
8
|
+
import { isVanillaExtractStyleCall, findThemeTokenForValue, findThemeTokenForPropertyValue, } from './ast-helpers.js';
|
|
9
|
+
import { loadThemeTokens } from './theme-loader.js';
|
|
10
|
+
/**
|
|
11
|
+
* Helper to extract a static property name from a node’s key.
|
|
12
|
+
*/
|
|
13
|
+
function getStaticPropertyKey(key) {
|
|
14
|
+
if (key.type === 'Identifier') {
|
|
15
|
+
return key.name;
|
|
16
|
+
}
|
|
17
|
+
if (key.type === 'Literal' && typeof key.value === 'string') {
|
|
18
|
+
return key.value;
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Recursively traverse an AST node representing a style definition.
|
|
24
|
+
*/
|
|
25
|
+
function traverseStyleNode(node, themeTokens, context, themeVarName, propertyContext) {
|
|
26
|
+
switch (node.type) {
|
|
27
|
+
case 'ObjectExpression':
|
|
28
|
+
node.properties.forEach((prop) => {
|
|
29
|
+
if (prop.type === 'Property') {
|
|
30
|
+
const propKey = getStaticPropertyKey(prop.key);
|
|
31
|
+
const newContext = propKey && !propKey.startsWith(':') && !propKey.startsWith('@') ? propKey : propertyContext;
|
|
32
|
+
if (prop.value.type === 'Literal') {
|
|
33
|
+
const value = prop.value.value;
|
|
34
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
35
|
+
const matchingToken = newContext && themeTokens
|
|
36
|
+
? findThemeTokenForPropertyValue(newContext, value, themeTokens)
|
|
37
|
+
: findThemeTokenForValue(value, themeTokens);
|
|
38
|
+
if (matchingToken) {
|
|
39
|
+
context.report({
|
|
40
|
+
node: prop.value,
|
|
41
|
+
messageId: 'preferThemeTokens',
|
|
42
|
+
data: {
|
|
43
|
+
token: matchingToken.token,
|
|
44
|
+
value: String(value),
|
|
45
|
+
},
|
|
46
|
+
fix(fixer) {
|
|
47
|
+
const tokenRef = `${themeVarName}.${matchingToken.token}`;
|
|
48
|
+
return fixer.replaceText(prop.value, tokenRef);
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
traverseStyleNode(prop.value, themeTokens, context, themeVarName, newContext);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
break;
|
|
60
|
+
case 'ArrayExpression':
|
|
61
|
+
node.elements.forEach((element) => {
|
|
62
|
+
if (element) {
|
|
63
|
+
traverseStyleNode(element, themeTokens, context, themeVarName, propertyContext);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
break;
|
|
67
|
+
case 'ConditionalExpression':
|
|
68
|
+
traverseStyleNode(node.consequent, themeTokens, context, themeVarName, propertyContext);
|
|
69
|
+
traverseStyleNode(node.alternate, themeTokens, context, themeVarName, propertyContext);
|
|
70
|
+
break;
|
|
71
|
+
case 'LogicalExpression':
|
|
72
|
+
traverseStyleNode(node.left, themeTokens, context, themeVarName, propertyContext);
|
|
73
|
+
traverseStyleNode(node.right, themeTokens, context, themeVarName, propertyContext);
|
|
74
|
+
break;
|
|
75
|
+
default:
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export function createThemeTokenVisitor(context) {
|
|
80
|
+
const options = context.options[0] || {};
|
|
81
|
+
const themeImportPath = options.themeImportPath ?? './src/css-sample/themes/light-theme.css.ts';
|
|
82
|
+
const themeVarName = options.themeVarName ?? 'theme';
|
|
83
|
+
const orderingStrategy = options.orderingStrategy ?? 'alphabetical';
|
|
84
|
+
const userDefinedGroupOrder = options.userDefinedGroupOrder;
|
|
85
|
+
const sortRemainingProperties = options.sortRemainingProperties;
|
|
86
|
+
let themeTokens = null;
|
|
87
|
+
const nodeVisitors = createNodeVisitors(context, orderingStrategy, userDefinedGroupOrder, sortRemainingProperties);
|
|
88
|
+
return {
|
|
89
|
+
...nodeVisitors,
|
|
90
|
+
Program() {
|
|
91
|
+
themeTokens = loadThemeTokens(themeImportPath);
|
|
92
|
+
},
|
|
93
|
+
CallExpression(node) {
|
|
94
|
+
if (node.callee.type !== 'Identifier') {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (isVanillaExtractStyleCall(node)) {
|
|
98
|
+
const styleArg = node.arguments[0];
|
|
99
|
+
if (styleArg) {
|
|
100
|
+
traverseStyleNode(styleArg, themeTokens, context, themeVarName);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if ((node.callee.name === 'globalKeyframes' || node.callee.name === 'globalStyle') &&
|
|
104
|
+
node.arguments.length >= 2) {
|
|
105
|
+
const styleArg = node.arguments[1];
|
|
106
|
+
if (styleArg) {
|
|
107
|
+
traverseStyleNode(styleArg, themeTokens, context, themeVarName);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
nodeVisitors.CallExpression?.(node);
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import customOrderRule from './css-rules/custom-order/rule-definition.js';
|
|
|
4
4
|
export const vanillaExtract = {
|
|
5
5
|
meta: {
|
|
6
6
|
name: '@antebudimir/eslint-plugin-vanilla-extract',
|
|
7
|
-
version: '1.
|
|
7
|
+
version: '1.4.0',
|
|
8
8
|
},
|
|
9
9
|
rules: {
|
|
10
10
|
'alphabetical-order': alphabeticalOrderRule,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antebudimir/eslint-plugin-vanilla-extract",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "ESLint plugin for enforcing CSS ordering in vanilla-extract styles",
|
|
5
5
|
"author": "Ante Budimir",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,7 +37,8 @@
|
|
|
37
37
|
"files": [
|
|
38
38
|
"dist",
|
|
39
39
|
"LICENSE",
|
|
40
|
-
"README.md"
|
|
40
|
+
"README.md",
|
|
41
|
+
"!dist/css-sample/"
|
|
41
42
|
],
|
|
42
43
|
"engines": {
|
|
43
44
|
"node": ">=18.18.0"
|
|
@@ -67,8 +68,6 @@
|
|
|
67
68
|
"format": "prettier --write .",
|
|
68
69
|
"lint": "eslint src --ext .ts --fix --max-warnings 0",
|
|
69
70
|
"typecheck": "tsc --noEmit",
|
|
70
|
-
"version:
|
|
71
|
-
"version:minor": "pnpm version minor --no-git-tag-version",
|
|
72
|
-
"version:patch": "pnpm version patch --no-git-tag-version"
|
|
71
|
+
"version:update": "node scripts/update-version.mjs"
|
|
73
72
|
}
|
|
74
73
|
}
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
export declare const item: string;
|
|
2
|
-
export declare const selectButtonVariants: Record<"bordered" | "borderless", string>;
|
|
3
|
-
export declare const trigger: import("@vanilla-extract/recipes").RuntimeFn<{
|
|
4
|
-
isOpen: {
|
|
5
|
-
false: {
|
|
6
|
-
margin: "0";
|
|
7
|
-
fontSize: "large";
|
|
8
|
-
border: "Background";
|
|
9
|
-
borderRight: "ActiveBorder";
|
|
10
|
-
borderLeft: "ActiveBorder";
|
|
11
|
-
borderRadius: "initial";
|
|
12
|
-
borderBottomLeftRadius: "initial";
|
|
13
|
-
borderBottomRightRadius: "initial";
|
|
14
|
-
boxShadow: "none";
|
|
15
|
-
boxSizing: "inherit";
|
|
16
|
-
position: "relative";
|
|
17
|
-
right: "inherit";
|
|
18
|
-
display: "flex";
|
|
19
|
-
gap: "revert";
|
|
20
|
-
transform: "none";
|
|
21
|
-
outline: "none";
|
|
22
|
-
backgroundColor: "initial";
|
|
23
|
-
cursor: "pointer";
|
|
24
|
-
color: "red";
|
|
25
|
-
':hover': {
|
|
26
|
-
margin: "0";
|
|
27
|
-
fontSize: "large";
|
|
28
|
-
border: "Background";
|
|
29
|
-
borderRight: "ActiveBorder";
|
|
30
|
-
borderLeft: "ActiveBorder";
|
|
31
|
-
borderRadius: "initial";
|
|
32
|
-
borderBottomLeftRadius: "initial";
|
|
33
|
-
borderBottomRightRadius: "initial";
|
|
34
|
-
boxShadow: "none";
|
|
35
|
-
boxSizing: "inherit";
|
|
36
|
-
position: "relative";
|
|
37
|
-
right: "inherit";
|
|
38
|
-
display: "flex";
|
|
39
|
-
gap: "revert";
|
|
40
|
-
transform: "none";
|
|
41
|
-
outline: "none";
|
|
42
|
-
backgroundColor: "initial";
|
|
43
|
-
cursor: "pointer";
|
|
44
|
-
color: "red";
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
true: {
|
|
48
|
-
margin: "0";
|
|
49
|
-
fontSize: "large";
|
|
50
|
-
border: "Background";
|
|
51
|
-
borderRight: "ActiveBorder";
|
|
52
|
-
borderLeft: "ActiveBorder";
|
|
53
|
-
borderRadius: "initial";
|
|
54
|
-
borderBottomLeftRadius: "initial";
|
|
55
|
-
borderBottomRightRadius: "initial";
|
|
56
|
-
boxShadow: "none";
|
|
57
|
-
boxSizing: "inherit";
|
|
58
|
-
position: "relative";
|
|
59
|
-
right: "inherit";
|
|
60
|
-
display: "flex";
|
|
61
|
-
gap: "revert";
|
|
62
|
-
transform: "none";
|
|
63
|
-
outline: "none";
|
|
64
|
-
backgroundColor: "initial";
|
|
65
|
-
cursor: "pointer";
|
|
66
|
-
color: "red";
|
|
67
|
-
':hover': {
|
|
68
|
-
margin: "0";
|
|
69
|
-
fontSize: "large";
|
|
70
|
-
border: "Background";
|
|
71
|
-
borderRight: "ActiveBorder";
|
|
72
|
-
borderLeft: "ActiveBorder";
|
|
73
|
-
borderRadius: "initial";
|
|
74
|
-
borderBottomLeftRadius: "initial";
|
|
75
|
-
borderBottomRightRadius: "initial";
|
|
76
|
-
boxShadow: "none";
|
|
77
|
-
boxSizing: "inherit";
|
|
78
|
-
position: "relative";
|
|
79
|
-
right: "inherit";
|
|
80
|
-
display: "flex";
|
|
81
|
-
gap: "revert";
|
|
82
|
-
transform: "none";
|
|
83
|
-
outline: "none";
|
|
84
|
-
backgroundColor: "initial";
|
|
85
|
-
cursor: "pointer";
|
|
86
|
-
color: "red";
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
}>;
|
|
91
|
-
export declare const accordionContent: import("@vanilla-extract/recipes").RuntimeFn<{
|
|
92
|
-
isOpen: {
|
|
93
|
-
false: {
|
|
94
|
-
margin: "0";
|
|
95
|
-
fontSize: "large";
|
|
96
|
-
border: "Background";
|
|
97
|
-
borderRight: "ActiveBorder";
|
|
98
|
-
borderLeft: "ActiveBorder";
|
|
99
|
-
borderRadius: "initial";
|
|
100
|
-
borderBottomLeftRadius: "initial";
|
|
101
|
-
borderBottomRightRadius: "initial";
|
|
102
|
-
boxShadow: "none";
|
|
103
|
-
boxSizing: "inherit";
|
|
104
|
-
position: "relative";
|
|
105
|
-
right: "inherit";
|
|
106
|
-
display: "flex";
|
|
107
|
-
gap: "revert";
|
|
108
|
-
transform: "none";
|
|
109
|
-
outline: "none";
|
|
110
|
-
backgroundColor: "initial";
|
|
111
|
-
cursor: "pointer";
|
|
112
|
-
color: "red";
|
|
113
|
-
};
|
|
114
|
-
true: {
|
|
115
|
-
margin: "0";
|
|
116
|
-
fontSize: "large";
|
|
117
|
-
border: "Background";
|
|
118
|
-
borderRight: "ActiveBorder";
|
|
119
|
-
borderLeft: "ActiveBorder";
|
|
120
|
-
borderRadius: "initial";
|
|
121
|
-
borderBottomLeftRadius: "initial";
|
|
122
|
-
borderBottomRightRadius: "initial";
|
|
123
|
-
boxShadow: "none";
|
|
124
|
-
boxSizing: "inherit";
|
|
125
|
-
position: "relative";
|
|
126
|
-
right: "inherit";
|
|
127
|
-
display: "flex";
|
|
128
|
-
gap: "revert";
|
|
129
|
-
transform: "none";
|
|
130
|
-
outline: "none";
|
|
131
|
-
backgroundColor: "initial";
|
|
132
|
-
cursor: "pointer";
|
|
133
|
-
color: "red";
|
|
134
|
-
':focus-visible': {
|
|
135
|
-
margin: "0";
|
|
136
|
-
fontSize: "large";
|
|
137
|
-
border: "Background";
|
|
138
|
-
borderRight: "ActiveBorder";
|
|
139
|
-
borderLeft: "ActiveBorder";
|
|
140
|
-
borderRadius: "initial";
|
|
141
|
-
borderBottomLeftRadius: "initial";
|
|
142
|
-
borderBottomRightRadius: "initial";
|
|
143
|
-
boxShadow: "none";
|
|
144
|
-
boxSizing: "inherit";
|
|
145
|
-
position: "relative";
|
|
146
|
-
right: "inherit";
|
|
147
|
-
display: "flex";
|
|
148
|
-
gap: "revert";
|
|
149
|
-
transform: "none";
|
|
150
|
-
outline: "none";
|
|
151
|
-
backgroundColor: "initial";
|
|
152
|
-
cursor: "pointer";
|
|
153
|
-
color: "red";
|
|
154
|
-
};
|
|
155
|
-
};
|
|
156
|
-
};
|
|
157
|
-
}>;
|
|
158
|
-
export declare const clearAllFiltersButton: string;
|
|
159
|
-
export declare const theFont: string;
|
|
160
|
-
export declare const starter: string;
|
|
161
|
-
export declare const spinster: void;
|