@typestyles/eslint-plugin 0.4.4 → 0.5.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/dist/index.cjs +824 -764
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +135 -133
- package/dist/index.d.ts +135 -133
- package/dist/index.js +796 -755
- package/dist/index.js.map +1 -1
- package/package.json +13 -14
package/dist/index.cjs
CHANGED
|
@@ -1,824 +1,884 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
5
|
+
//#region \0rolldown/runtime.js
|
|
6
|
+
var __create = Object.create;
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
9
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
10
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
14
|
+
key = keys[i];
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: ((k) => from[k]).bind(null, key),
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
//#endregion
|
|
27
|
+
let _typescript_eslint_utils = require("@typescript-eslint/utils");
|
|
28
|
+
let node_path = require("node:path");
|
|
29
|
+
node_path = __toESM(node_path, 1);
|
|
30
|
+
let _typestyles_cli = require("@typestyles/cli");
|
|
31
|
+
//#region src/utils/create-rule.ts
|
|
32
|
+
const createRule = _typescript_eslint_utils.ESLintUtils.RuleCreator((name) => `https://typestyles.dev/docs/eslint#${name}`);
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/rules/no-default-scope-in-package.ts
|
|
35
|
+
function memberPropertyName$1(node) {
|
|
36
|
+
if (node.property.type === "Identifier" && !node.computed) return node.property.name;
|
|
37
|
+
if (node.property.type === "Literal" && typeof node.property.value === "string") return node.property.value;
|
|
38
|
+
return null;
|
|
25
39
|
}
|
|
26
40
|
function objectHasScopeId(arg) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return true;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return false;
|
|
41
|
+
if (!arg || arg.type !== "ObjectExpression") return false;
|
|
42
|
+
for (const prop of arg.properties) if (prop.type === "Property" && !prop.computed && prop.key.type === "Identifier" && prop.key.name === "scopeId") return true;
|
|
43
|
+
return false;
|
|
34
44
|
}
|
|
35
45
|
function isUnscopedFactoryCall(node) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
46
|
+
const { callee, arguments: args } = node;
|
|
47
|
+
if (callee.type !== "Identifier") return false;
|
|
48
|
+
if (callee.name !== "createTypeStyles" && callee.name !== "createStyles") return false;
|
|
49
|
+
if (args.length === 0) return true;
|
|
50
|
+
const first = args[0];
|
|
51
|
+
if (first.type === "SpreadElement") return false;
|
|
52
|
+
if (first.type === "ObjectExpression") return !objectHasScopeId(first);
|
|
53
|
+
return false;
|
|
44
54
|
}
|
|
45
55
|
function isLegacyDefaultStylesCall(node) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
56
|
+
const { callee } = node;
|
|
57
|
+
if (callee.type !== "MemberExpression") return false;
|
|
58
|
+
const method = memberPropertyName$1(callee);
|
|
59
|
+
if (method !== "class" && method !== "component" && method !== "hashClass") return false;
|
|
60
|
+
return callee.object.type === "Identifier" && callee.object.name === "styles";
|
|
51
61
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
}
|
|
62
|
+
const noDefaultScopeInPackage = createRule({
|
|
63
|
+
name: "no-default-scope-in-package",
|
|
64
|
+
meta: {
|
|
65
|
+
type: "suggestion",
|
|
66
|
+
docs: { description: "Require a scoped styles factory (`createTypeStyles`/`createStyles` with `scopeId`) in publishable packages — flags unscoped factory calls and legacy `styles.*` usage" },
|
|
67
|
+
messages: {
|
|
68
|
+
unscopedFactory: "`{{factory}}()` without `scopeId` in a published package risks class-name collisions. Pass `scopeId` (e.g. `createTypeStyles({ scopeId: pkg.name })`).",
|
|
69
|
+
unscopedInPackage: "Using the legacy unscoped `styles.{{method}}()` API in a published package risks class-name collisions. Use `createTypeStyles({ scopeId: pkg.name })` and call `style` / `hash` / `recipe` from that instance."
|
|
70
|
+
},
|
|
71
|
+
schema: []
|
|
72
|
+
},
|
|
73
|
+
defaultOptions: [],
|
|
74
|
+
create(context) {
|
|
75
|
+
return { CallExpression(node) {
|
|
76
|
+
if (isUnscopedFactoryCall(node)) {
|
|
77
|
+
const factory = node.callee.name;
|
|
78
|
+
context.report({
|
|
79
|
+
node: node.callee,
|
|
80
|
+
messageId: "unscopedFactory",
|
|
81
|
+
data: { factory }
|
|
82
|
+
});
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (!isLegacyDefaultStylesCall(node)) return;
|
|
86
|
+
const method = memberPropertyName$1(node.callee) ?? "class";
|
|
87
|
+
context.report({
|
|
88
|
+
node: node.callee,
|
|
89
|
+
messageId: "unscopedInPackage",
|
|
90
|
+
data: { method }
|
|
91
|
+
});
|
|
92
|
+
} };
|
|
93
|
+
}
|
|
88
94
|
});
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
function
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
return null;
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/utils/style-calls.ts
|
|
97
|
+
function memberPropertyName(node) {
|
|
98
|
+
if (node.property.type === "Identifier" && !node.computed) return node.property.name;
|
|
99
|
+
if (node.property.type === "Literal" && typeof node.property.value === "string") return node.property.value;
|
|
100
|
+
return null;
|
|
97
101
|
}
|
|
98
102
|
function calleeRootName(node) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
103
|
+
if (node.type === "Identifier") return node.name;
|
|
104
|
+
if (node.type === "MemberExpression") {
|
|
105
|
+
if (node.object.type === "Identifier") return node.object.name;
|
|
106
|
+
if (node.object.type === "MemberExpression") {
|
|
107
|
+
const inner = memberPropertyName(node.object);
|
|
108
|
+
const outer = calleeRootName(node.object);
|
|
109
|
+
if (outer && inner) return `${outer}.${inner}`;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return null;
|
|
109
113
|
}
|
|
110
114
|
function isMemberCall(callee, objectName, method) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return false;
|
|
115
|
+
if (callee.type !== "MemberExpression") return false;
|
|
116
|
+
if (memberPropertyName(callee) !== method) return false;
|
|
117
|
+
if (callee.object.type === "Identifier") return callee.object.name === objectName;
|
|
118
|
+
return false;
|
|
116
119
|
}
|
|
117
120
|
function firstStringArg(args) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
121
|
+
const first = args[0];
|
|
122
|
+
if (!first || first.type === "SpreadElement") return null;
|
|
123
|
+
if (first.type === "Literal" && typeof first.value === "string") return first;
|
|
124
|
+
return null;
|
|
122
125
|
}
|
|
123
126
|
function nameFromObjectArg(args) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
return null;
|
|
127
|
+
const first = args[0];
|
|
128
|
+
if (!first || first.type !== "ObjectExpression") return null;
|
|
129
|
+
for (const prop of first.properties) {
|
|
130
|
+
if (prop.type !== "Property" || prop.computed) continue;
|
|
131
|
+
if ((prop.key.type === "Identifier" ? prop.key.name : prop.key.type === "Literal" && typeof prop.key.value === "string" ? prop.key.value : null) !== "name") continue;
|
|
132
|
+
if (prop.value.type === "Literal" && typeof prop.value.value === "string") return prop.value;
|
|
133
|
+
}
|
|
134
|
+
return null;
|
|
133
135
|
}
|
|
134
136
|
function recipeNameArg(args) {
|
|
135
|
-
|
|
137
|
+
return nameFromObjectArg(args) ?? firstStringArg(args);
|
|
136
138
|
}
|
|
137
139
|
function getNamespaceCall(node) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
140
|
+
const { callee, arguments: args } = node;
|
|
141
|
+
if (callee.type === "Identifier" && callee.name === "style") {
|
|
142
|
+
const nameNode = firstStringArg(args);
|
|
143
|
+
if (!nameNode) return null;
|
|
144
|
+
return {
|
|
145
|
+
kind: "style",
|
|
146
|
+
key: `.${nameNode.value}-`,
|
|
147
|
+
nameNode
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
if (callee.type === "Identifier" && callee.name === "recipe") {
|
|
151
|
+
const nameNode = recipeNameArg(args);
|
|
152
|
+
if (!nameNode) return null;
|
|
153
|
+
return {
|
|
154
|
+
kind: "recipe",
|
|
155
|
+
key: `.${nameNode.value}-`,
|
|
156
|
+
nameNode
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
if (callee.type === "Identifier" && callee.name === "hash") {
|
|
160
|
+
const first = args[0];
|
|
161
|
+
if (!first || first.type === "SpreadElement") return null;
|
|
162
|
+
if (args[1]?.type === "ObjectExpression") {
|
|
163
|
+
for (const prop of args[1].properties) if (prop.type === "Property" && prop.key.type === "Identifier" && prop.key.name === "label" && prop.value.type === "Literal" && typeof prop.value.value === "string") return {
|
|
164
|
+
kind: "hash",
|
|
165
|
+
key: `.${prop.value.value}-`,
|
|
166
|
+
nameNode: prop.value
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
if (isMemberCall(callee, "styles", "class")) {
|
|
172
|
+
const nameNode = firstStringArg(args);
|
|
173
|
+
if (!nameNode) return null;
|
|
174
|
+
return {
|
|
175
|
+
kind: "styles.class",
|
|
176
|
+
key: `.${nameNode.value}-`,
|
|
177
|
+
nameNode
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
if (isMemberCall(callee, "styles", "component")) {
|
|
181
|
+
const nameNode = recipeNameArg(args);
|
|
182
|
+
if (!nameNode) return null;
|
|
183
|
+
return {
|
|
184
|
+
kind: "styles.component",
|
|
185
|
+
key: `.${nameNode.value}-`,
|
|
186
|
+
nameNode
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
if (isMemberCall(callee, "styles", "hashClass")) {
|
|
190
|
+
const first = args[0];
|
|
191
|
+
if (!first || first.type === "SpreadElement") return null;
|
|
192
|
+
if (first.type === "Literal" && typeof first.value === "string") return {
|
|
193
|
+
kind: "styles.hashClass",
|
|
194
|
+
key: `.${first.value}-`,
|
|
195
|
+
nameNode: first
|
|
196
|
+
};
|
|
197
|
+
const label = args[1];
|
|
198
|
+
if (label?.type === "Literal" && typeof label.value === "string") return {
|
|
199
|
+
kind: "styles.hashClass",
|
|
200
|
+
key: `.${label.value}-`,
|
|
201
|
+
nameNode: label
|
|
202
|
+
};
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
if (isMemberCall(callee, "tokens", "create")) {
|
|
206
|
+
const nameNode = firstStringArg(args);
|
|
207
|
+
if (!nameNode) return null;
|
|
208
|
+
return {
|
|
209
|
+
kind: "tokens.create",
|
|
210
|
+
key: `tokens:${nameNode.value}`,
|
|
211
|
+
nameNode
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
if (isMemberCall(callee, "tokens", "createTheme")) {
|
|
215
|
+
const nameNode = firstStringArg(args);
|
|
216
|
+
if (!nameNode) return null;
|
|
217
|
+
return {
|
|
218
|
+
kind: "tokens.createTheme",
|
|
219
|
+
key: `theme:${nameNode.value}`,
|
|
220
|
+
nameNode
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
if (callee.type === "Identifier" && callee.name === "createTheme") {
|
|
224
|
+
const nameNode = firstStringArg(args);
|
|
225
|
+
if (!nameNode) return null;
|
|
226
|
+
return {
|
|
227
|
+
kind: "createTheme",
|
|
228
|
+
key: `theme:${nameNode.value}`,
|
|
229
|
+
nameNode
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
if (isMemberCall(callee, "keyframes", "create")) {
|
|
233
|
+
const nameNode = firstStringArg(args);
|
|
234
|
+
if (!nameNode) return null;
|
|
235
|
+
return {
|
|
236
|
+
kind: "keyframes.create",
|
|
237
|
+
key: `keyframes:${nameNode.value}`,
|
|
238
|
+
nameNode
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
if (isMemberCall(callee, "global", "rule") || isMemberCall(callee, "global", "style")) {
|
|
242
|
+
const nameNode = firstStringArg(args);
|
|
243
|
+
if (!nameNode) return null;
|
|
244
|
+
return {
|
|
245
|
+
kind: isMemberCall(callee, "global", "rule") ? "global.rule" : "global.style",
|
|
246
|
+
key: nameNode.value,
|
|
247
|
+
nameNode
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
if (isMemberCall(callee, "global", "fontFace")) {
|
|
251
|
+
const nameNode = firstStringArg(args);
|
|
252
|
+
if (!nameNode) return null;
|
|
253
|
+
return {
|
|
254
|
+
kind: "global.fontFace",
|
|
255
|
+
key: `font-face:${nameNode.value}`,
|
|
256
|
+
nameNode
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
if (callee.type === "MemberExpression") {
|
|
260
|
+
const method = memberPropertyName(callee);
|
|
261
|
+
const root = calleeRootName(callee);
|
|
262
|
+
if (method === "class" && root) {
|
|
263
|
+
const nameNode = firstStringArg(args);
|
|
264
|
+
if (!nameNode) return null;
|
|
265
|
+
return {
|
|
266
|
+
kind: "styles.class",
|
|
267
|
+
key: `.${nameNode.value}-`,
|
|
268
|
+
nameNode
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
if (method === "component" && root) {
|
|
272
|
+
const nameNode = firstStringArg(args);
|
|
273
|
+
if (!nameNode) return null;
|
|
274
|
+
return {
|
|
275
|
+
kind: "styles.component",
|
|
276
|
+
key: `.${nameNode.value}-`,
|
|
277
|
+
nameNode
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
if (method === "create" && root?.endsWith("tokens")) {
|
|
281
|
+
const nameNode = firstStringArg(args);
|
|
282
|
+
if (!nameNode) return null;
|
|
283
|
+
return {
|
|
284
|
+
kind: "tokens.create",
|
|
285
|
+
key: `tokens:${nameNode.value}`,
|
|
286
|
+
nameNode
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return null;
|
|
237
291
|
}
|
|
238
292
|
function getStyleObjectArguments(node) {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
return objects;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
return objects;
|
|
293
|
+
const { callee, arguments: args } = node;
|
|
294
|
+
const objects = [];
|
|
295
|
+
const pushObject = (arg) => {
|
|
296
|
+
if (!arg || arg.type === "SpreadElement") return;
|
|
297
|
+
if (arg.type === "ObjectExpression") objects.push(arg);
|
|
298
|
+
if (arg.type === "ArrowFunctionExpression" && arg.body.type === "ObjectExpression") objects.push(arg.body);
|
|
299
|
+
};
|
|
300
|
+
if (callee.type === "Identifier" && (callee.name === "style" || callee.name === "recipe")) {
|
|
301
|
+
pushObject(args[1]);
|
|
302
|
+
return objects;
|
|
303
|
+
}
|
|
304
|
+
if (callee.type === "Identifier" && callee.name === "hash") {
|
|
305
|
+
pushObject(args[0]);
|
|
306
|
+
return objects;
|
|
307
|
+
}
|
|
308
|
+
if (callee.type === "MemberExpression") {
|
|
309
|
+
const method = memberPropertyName(callee);
|
|
310
|
+
if (method === "class" || method === "component" || method === "rule" || method === "style") {
|
|
311
|
+
pushObject(args[1]);
|
|
312
|
+
return objects;
|
|
313
|
+
}
|
|
314
|
+
if (method === "hashClass" || method === "rules") {
|
|
315
|
+
const first = args[0];
|
|
316
|
+
if (first && first.type !== "SpreadElement" && first.type === "ObjectExpression") objects.push(first);
|
|
317
|
+
return objects;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return objects;
|
|
271
321
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
322
|
+
//#endregion
|
|
323
|
+
//#region src/rules/no-duplicate-namespace.ts
|
|
324
|
+
const namespaceRegistry = new Map();
|
|
325
|
+
const noDuplicateNamespace = createRule({
|
|
326
|
+
name: "no-duplicate-namespace",
|
|
327
|
+
meta: {
|
|
328
|
+
type: "problem",
|
|
329
|
+
docs: { description: "Disallow reusing the same TypeStyles namespace (`styles.class`, `styles.component`, `tokens.create`, …) across the project" },
|
|
330
|
+
messages: {
|
|
331
|
+
duplicateInFile: "Namespace `{{name}}` ({{kind}}) is already registered in this file at line {{line}}.",
|
|
332
|
+
duplicateAcrossFiles: "Namespace `{{name}}` ({{kind}}) is already registered in `{{otherFile}}` at line {{line}}."
|
|
333
|
+
},
|
|
334
|
+
schema: []
|
|
335
|
+
},
|
|
336
|
+
defaultOptions: [],
|
|
337
|
+
create(context) {
|
|
338
|
+
const fileSeen = new Map();
|
|
339
|
+
const filename = context.filename;
|
|
340
|
+
return { CallExpression(node) {
|
|
341
|
+
const call = getNamespaceCall(node);
|
|
342
|
+
if (!call) return;
|
|
343
|
+
const displayName = call.kind === "styles.class" || call.kind === "styles.component" ? call.nameNode.value : call.nameNode.value;
|
|
344
|
+
const line = call.nameNode.loc?.start.line ?? node.loc?.start.line ?? 0;
|
|
345
|
+
const column = call.nameNode.loc?.start.column ?? node.loc?.start.column ?? 0;
|
|
346
|
+
const priorInFile = fileSeen.get(call.key);
|
|
347
|
+
if (priorInFile) {
|
|
348
|
+
context.report({
|
|
349
|
+
node: call.nameNode,
|
|
350
|
+
messageId: "duplicateInFile",
|
|
351
|
+
data: {
|
|
352
|
+
name: displayName,
|
|
353
|
+
kind: call.kind,
|
|
354
|
+
line: String(priorInFile.line)
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
fileSeen.set(call.key, {
|
|
360
|
+
line,
|
|
361
|
+
column
|
|
362
|
+
});
|
|
363
|
+
const priorGlobal = namespaceRegistry.get(call.key);
|
|
364
|
+
if (priorGlobal && priorGlobal.filename !== filename) {
|
|
365
|
+
context.report({
|
|
366
|
+
node: call.nameNode,
|
|
367
|
+
messageId: "duplicateAcrossFiles",
|
|
368
|
+
data: {
|
|
369
|
+
name: displayName,
|
|
370
|
+
kind: call.kind,
|
|
371
|
+
otherFile: priorGlobal.filename,
|
|
372
|
+
line: String(priorGlobal.line)
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
if (!priorGlobal) namespaceRegistry.set(call.key, {
|
|
378
|
+
filename,
|
|
379
|
+
line,
|
|
380
|
+
column
|
|
381
|
+
});
|
|
382
|
+
} };
|
|
383
|
+
}
|
|
333
384
|
});
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
385
|
+
//#endregion
|
|
386
|
+
//#region src/utils/css-properties.ts
|
|
387
|
+
const UNITLESS_PROPERTIES = new Set([
|
|
388
|
+
"animationIterationCount",
|
|
389
|
+
"aspectRatio",
|
|
390
|
+
"borderImageOutset",
|
|
391
|
+
"borderImageSlice",
|
|
392
|
+
"borderImageWidth",
|
|
393
|
+
"boxFlex",
|
|
394
|
+
"boxFlexGroup",
|
|
395
|
+
"boxOrdinalGroup",
|
|
396
|
+
"columnCount",
|
|
397
|
+
"columns",
|
|
398
|
+
"flex",
|
|
399
|
+
"flexGrow",
|
|
400
|
+
"flexPositive",
|
|
401
|
+
"flexShrink",
|
|
402
|
+
"flexNegative",
|
|
403
|
+
"flexOrder",
|
|
404
|
+
"fontSizeAdjust",
|
|
405
|
+
"fontWeight",
|
|
406
|
+
"gridArea",
|
|
407
|
+
"gridColumn",
|
|
408
|
+
"gridColumnEnd",
|
|
409
|
+
"gridColumnSpan",
|
|
410
|
+
"gridColumnStart",
|
|
411
|
+
"gridRow",
|
|
412
|
+
"gridRowEnd",
|
|
413
|
+
"gridRowSpan",
|
|
414
|
+
"gridRowStart",
|
|
415
|
+
"initialLetter",
|
|
416
|
+
"lineClamp",
|
|
417
|
+
"lineHeight",
|
|
418
|
+
"maskBorderOutset",
|
|
419
|
+
"maskBorderSlice",
|
|
420
|
+
"maskBorderWidth",
|
|
421
|
+
"opacity",
|
|
422
|
+
"order",
|
|
423
|
+
"orphans",
|
|
424
|
+
"scale",
|
|
425
|
+
"tabSize",
|
|
426
|
+
"widows",
|
|
427
|
+
"zIndex",
|
|
428
|
+
"zoom",
|
|
429
|
+
"fillOpacity",
|
|
430
|
+
"floodOpacity",
|
|
431
|
+
"stopOpacity",
|
|
432
|
+
"strokeDasharray",
|
|
433
|
+
"strokeDashoffset",
|
|
434
|
+
"strokeMiterlimit",
|
|
435
|
+
"strokeOpacity",
|
|
436
|
+
"strokeWidth"
|
|
386
437
|
]);
|
|
387
|
-
|
|
438
|
+
const VENDOR_PREFIX_RE = /^(Webkit|Moz|ms|O)([A-Z])(.*)$/;
|
|
388
439
|
function isUnitlessProperty(prop) {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
}
|
|
394
|
-
return false;
|
|
440
|
+
if (UNITLESS_PROPERTIES.has(prop)) return true;
|
|
441
|
+
const match = VENDOR_PREFIX_RE.exec(prop);
|
|
442
|
+
if (match) return UNITLESS_PROPERTIES.has(match[2].toLowerCase() + match[3]);
|
|
443
|
+
return false;
|
|
395
444
|
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
445
|
+
const SHORTHAND_TO_LONGHANDS = {
|
|
446
|
+
padding: [
|
|
447
|
+
"paddingTop",
|
|
448
|
+
"paddingRight",
|
|
449
|
+
"paddingBottom",
|
|
450
|
+
"paddingLeft",
|
|
451
|
+
"paddingInline",
|
|
452
|
+
"paddingBlock",
|
|
453
|
+
"paddingInlineStart",
|
|
454
|
+
"paddingInlineEnd",
|
|
455
|
+
"paddingBlockStart",
|
|
456
|
+
"paddingBlockEnd"
|
|
457
|
+
],
|
|
458
|
+
margin: [
|
|
459
|
+
"marginTop",
|
|
460
|
+
"marginRight",
|
|
461
|
+
"marginBottom",
|
|
462
|
+
"marginLeft",
|
|
463
|
+
"marginInline",
|
|
464
|
+
"marginBlock",
|
|
465
|
+
"marginInlineStart",
|
|
466
|
+
"marginInlineEnd",
|
|
467
|
+
"marginBlockStart",
|
|
468
|
+
"marginBlockEnd"
|
|
469
|
+
],
|
|
470
|
+
border: [
|
|
471
|
+
"borderWidth",
|
|
472
|
+
"borderStyle",
|
|
473
|
+
"borderColor",
|
|
474
|
+
"borderTop",
|
|
475
|
+
"borderRight",
|
|
476
|
+
"borderBottom",
|
|
477
|
+
"borderLeft",
|
|
478
|
+
"borderInline",
|
|
479
|
+
"borderBlock"
|
|
480
|
+
],
|
|
481
|
+
borderWidth: [
|
|
482
|
+
"borderTopWidth",
|
|
483
|
+
"borderRightWidth",
|
|
484
|
+
"borderBottomWidth",
|
|
485
|
+
"borderLeftWidth",
|
|
486
|
+
"borderInlineWidth",
|
|
487
|
+
"borderBlockWidth"
|
|
488
|
+
],
|
|
489
|
+
borderStyle: [
|
|
490
|
+
"borderTopStyle",
|
|
491
|
+
"borderRightStyle",
|
|
492
|
+
"borderBottomStyle",
|
|
493
|
+
"borderLeftStyle"
|
|
494
|
+
],
|
|
495
|
+
borderColor: [
|
|
496
|
+
"borderTopColor",
|
|
497
|
+
"borderRightColor",
|
|
498
|
+
"borderBottomColor",
|
|
499
|
+
"borderLeftColor"
|
|
500
|
+
],
|
|
501
|
+
borderTop: [
|
|
502
|
+
"borderTopWidth",
|
|
503
|
+
"borderTopStyle",
|
|
504
|
+
"borderTopColor"
|
|
505
|
+
],
|
|
506
|
+
borderRight: [
|
|
507
|
+
"borderRightWidth",
|
|
508
|
+
"borderRightStyle",
|
|
509
|
+
"borderRightColor"
|
|
510
|
+
],
|
|
511
|
+
borderBottom: [
|
|
512
|
+
"borderBottomWidth",
|
|
513
|
+
"borderBottomStyle",
|
|
514
|
+
"borderBottomColor"
|
|
515
|
+
],
|
|
516
|
+
borderLeft: [
|
|
517
|
+
"borderLeftWidth",
|
|
518
|
+
"borderLeftStyle",
|
|
519
|
+
"borderLeftColor"
|
|
520
|
+
],
|
|
521
|
+
background: [
|
|
522
|
+
"backgroundColor",
|
|
523
|
+
"backgroundImage",
|
|
524
|
+
"backgroundPosition",
|
|
525
|
+
"backgroundSize",
|
|
526
|
+
"backgroundRepeat",
|
|
527
|
+
"backgroundAttachment",
|
|
528
|
+
"backgroundOrigin",
|
|
529
|
+
"backgroundClip"
|
|
530
|
+
],
|
|
531
|
+
font: [
|
|
532
|
+
"fontStyle",
|
|
533
|
+
"fontVariant",
|
|
534
|
+
"fontWeight",
|
|
535
|
+
"fontSize",
|
|
536
|
+
"lineHeight",
|
|
537
|
+
"fontFamily"
|
|
538
|
+
],
|
|
539
|
+
flex: [
|
|
540
|
+
"flexGrow",
|
|
541
|
+
"flexShrink",
|
|
542
|
+
"flexBasis"
|
|
543
|
+
],
|
|
544
|
+
gap: ["rowGap", "columnGap"],
|
|
545
|
+
overflow: ["overflowX", "overflowY"],
|
|
546
|
+
transition: [
|
|
547
|
+
"transitionProperty",
|
|
548
|
+
"transitionDuration",
|
|
549
|
+
"transitionTimingFunction",
|
|
550
|
+
"transitionDelay"
|
|
551
|
+
],
|
|
552
|
+
animation: [
|
|
553
|
+
"animationName",
|
|
554
|
+
"animationDuration",
|
|
555
|
+
"animationTimingFunction",
|
|
556
|
+
"animationDelay",
|
|
557
|
+
"animationIterationCount",
|
|
558
|
+
"animationDirection",
|
|
559
|
+
"animationFillMode",
|
|
560
|
+
"animationPlayState"
|
|
561
|
+
],
|
|
562
|
+
outline: [
|
|
563
|
+
"outlineWidth",
|
|
564
|
+
"outlineStyle",
|
|
565
|
+
"outlineColor"
|
|
566
|
+
],
|
|
567
|
+
listStyle: [
|
|
568
|
+
"listStyleType",
|
|
569
|
+
"listStylePosition",
|
|
570
|
+
"listStyleImage"
|
|
571
|
+
],
|
|
572
|
+
grid: [
|
|
573
|
+
"gridTemplateRows",
|
|
574
|
+
"gridTemplateColumns",
|
|
575
|
+
"gridTemplateAreas",
|
|
576
|
+
"gridAutoRows",
|
|
577
|
+
"gridAutoColumns",
|
|
578
|
+
"gridAutoFlow"
|
|
579
|
+
],
|
|
580
|
+
gridTemplate: [
|
|
581
|
+
"gridTemplateRows",
|
|
582
|
+
"gridTemplateColumns",
|
|
583
|
+
"gridTemplateAreas"
|
|
584
|
+
],
|
|
585
|
+
inset: [
|
|
586
|
+
"top",
|
|
587
|
+
"right",
|
|
588
|
+
"bottom",
|
|
589
|
+
"left"
|
|
590
|
+
],
|
|
591
|
+
insetBlock: ["insetBlockStart", "insetBlockEnd"],
|
|
592
|
+
insetInline: ["insetInlineStart", "insetInlineEnd"]
|
|
490
593
|
};
|
|
491
|
-
|
|
594
|
+
const BARE_NUMBER_STRING_RE = /^-?\d+(\.\d+)?$/;
|
|
492
595
|
function findShorthandLonghandConflicts(propertyNames) {
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
596
|
+
const keys = new Set(propertyNames);
|
|
597
|
+
const seen = new Set();
|
|
598
|
+
const conflicts = [];
|
|
599
|
+
for (const key of keys) {
|
|
600
|
+
const longhands = SHORTHAND_TO_LONGHANDS[key];
|
|
601
|
+
if (longhands) {
|
|
602
|
+
for (const longhand of longhands) if (keys.has(longhand)) {
|
|
603
|
+
const id = `${key}|${longhand}`;
|
|
604
|
+
if (!seen.has(id)) {
|
|
605
|
+
seen.add(id);
|
|
606
|
+
conflicts.push({
|
|
607
|
+
shorthand: key,
|
|
608
|
+
longhand
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
return conflicts;
|
|
511
615
|
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
616
|
+
//#endregion
|
|
617
|
+
//#region src/utils/style-ast.ts
|
|
618
|
+
const NESTED_SELECTOR_KEY_RE = /^(&|@|\[)/;
|
|
619
|
+
const COMPONENT_STRUCTURAL_KEYS = new Set([
|
|
620
|
+
"base",
|
|
621
|
+
"variants",
|
|
622
|
+
"defaultVariants",
|
|
623
|
+
"compoundVariants",
|
|
624
|
+
"slots"
|
|
521
625
|
]);
|
|
522
626
|
function getStaticPropertyKey(prop) {
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
627
|
+
if (prop.computed) return null;
|
|
628
|
+
if (prop.key.type === "Identifier") return prop.key.name;
|
|
629
|
+
if (prop.key.type === "Literal" && typeof prop.key.value === "string") return prop.key.value;
|
|
630
|
+
return null;
|
|
527
631
|
}
|
|
528
632
|
function isCssPropertyKey(key) {
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
633
|
+
if (NESTED_SELECTOR_KEY_RE.test(key)) return false;
|
|
634
|
+
if (COMPONENT_STRUCTURAL_KEYS.has(key)) return false;
|
|
635
|
+
return /^[a-zA-Z]/.test(key);
|
|
532
636
|
}
|
|
533
637
|
function collectCssPropertyNames(obj) {
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
638
|
+
const names = [];
|
|
639
|
+
for (const prop of obj.properties) {
|
|
640
|
+
if (prop.type !== "Property") continue;
|
|
641
|
+
const key = getStaticPropertyKey(prop);
|
|
642
|
+
if (key && isCssPropertyKey(key)) names.push(key);
|
|
643
|
+
}
|
|
644
|
+
return names;
|
|
541
645
|
}
|
|
542
646
|
function visitStyleObjectLiterals(node, onStyleObject) {
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
if (cvKey === "css" && cvProp.value.type === "ObjectExpression") {
|
|
572
|
-
visitStyleObjectLiterals(cvProp.value, onStyleObject);
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
continue;
|
|
577
|
-
}
|
|
578
|
-
if ((COMPONENT_STRUCTURAL_KEYS.has(key) || prop.value.type === "ObjectExpression") && prop.value.type === "ObjectExpression") {
|
|
579
|
-
visitStyleObjectLiterals(prop.value, onStyleObject);
|
|
580
|
-
}
|
|
581
|
-
}
|
|
647
|
+
onStyleObject(node);
|
|
648
|
+
for (const prop of node.properties) {
|
|
649
|
+
if (prop.type !== "Property") continue;
|
|
650
|
+
const key = getStaticPropertyKey(prop);
|
|
651
|
+
if (!key) continue;
|
|
652
|
+
if (NESTED_SELECTOR_KEY_RE.test(key)) {
|
|
653
|
+
if (prop.value.type === "ObjectExpression") visitStyleObjectLiterals(prop.value, onStyleObject);
|
|
654
|
+
continue;
|
|
655
|
+
}
|
|
656
|
+
if (key === "variants" && prop.value.type === "ObjectExpression") {
|
|
657
|
+
for (const groupProp of prop.value.properties) {
|
|
658
|
+
if (groupProp.type !== "Property" || groupProp.value.type !== "ObjectExpression") continue;
|
|
659
|
+
for (const optionProp of groupProp.value.properties) if (optionProp.type === "Property" && optionProp.value.type === "ObjectExpression") visitStyleObjectLiterals(optionProp.value, onStyleObject);
|
|
660
|
+
}
|
|
661
|
+
continue;
|
|
662
|
+
}
|
|
663
|
+
if (key === "compoundVariants" && prop.value.type === "ArrayExpression") {
|
|
664
|
+
for (const element of prop.value.elements) {
|
|
665
|
+
if (!element || element.type !== "ObjectExpression") continue;
|
|
666
|
+
for (const cvProp of element.properties) {
|
|
667
|
+
if (cvProp.type !== "Property") continue;
|
|
668
|
+
if (getStaticPropertyKey(cvProp) === "css" && cvProp.value.type === "ObjectExpression") visitStyleObjectLiterals(cvProp.value, onStyleObject);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
continue;
|
|
672
|
+
}
|
|
673
|
+
if ((COMPONENT_STRUCTURAL_KEYS.has(key) || prop.value.type === "ObjectExpression") && prop.value.type === "ObjectExpression") visitStyleObjectLiterals(prop.value, onStyleObject);
|
|
674
|
+
}
|
|
582
675
|
}
|
|
583
676
|
function getStringLiteralValue(node) {
|
|
584
|
-
|
|
585
|
-
|
|
677
|
+
if (node.type === "Literal" && typeof node.value === "string") return node.value;
|
|
678
|
+
return null;
|
|
586
679
|
}
|
|
587
680
|
function getNumericLiteralValue(node) {
|
|
588
|
-
|
|
589
|
-
|
|
681
|
+
if (node.type === "Literal" && typeof node.value === "number") return node.value;
|
|
682
|
+
return null;
|
|
590
683
|
}
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
if (parent?.type === "Property" && (parent.key.type === "Identifier" || parent.key.type === "Literal")) {
|
|
656
|
-
const parentKey = parent.key.type === "Identifier" ? parent.key.name : typeof parent.key.value === "string" ? parent.key.value : null;
|
|
657
|
-
if (parentKey === "from" || parentKey === "to" || /^\d+%$/.test(parentKey ?? "")) {
|
|
658
|
-
visitStyleObjectLiterals(node, checkStyleObject);
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
};
|
|
663
|
-
}
|
|
684
|
+
//#endregion
|
|
685
|
+
//#region src/rules/no-invalid-unitless-value.ts
|
|
686
|
+
const noInvalidUnitlessValue = createRule({
|
|
687
|
+
name: "no-invalid-unitless-value",
|
|
688
|
+
meta: {
|
|
689
|
+
type: "problem",
|
|
690
|
+
docs: { description: "Disallow bare numeric strings on properties that require CSS units (TypeStyles only auto-appends `px` to numbers, not strings)" },
|
|
691
|
+
messages: {
|
|
692
|
+
bareNumberString: "`{{property}}` is set to bare number string `{{value}}`, which emits invalid CSS. Use a number (`{{numeric}}`) or a value with units (`{{value}}px`).",
|
|
693
|
+
suspiciousUnitlessNumber: "`{{property}}` is unitless in CSS — numeric `{{value}}` is emitted without a unit. Use a ratio (e.g. `1.5`) or an explicit length (`\"24px\"`)."
|
|
694
|
+
},
|
|
695
|
+
schema: [{
|
|
696
|
+
type: "object",
|
|
697
|
+
properties: { checkSuspiciousUnitlessNumbers: { type: "boolean" } },
|
|
698
|
+
additionalProperties: false
|
|
699
|
+
}]
|
|
700
|
+
},
|
|
701
|
+
defaultOptions: [{ checkSuspiciousUnitlessNumbers: true }],
|
|
702
|
+
create(context, [options]) {
|
|
703
|
+
const SUSPICIOUS_UNITLESS_PROPERTIES = new Set(["lineHeight"]);
|
|
704
|
+
function checkStyleObject(obj) {
|
|
705
|
+
for (const prop of obj.properties) {
|
|
706
|
+
if (prop.type !== "Property") continue;
|
|
707
|
+
const key = getStaticPropertyKey(prop);
|
|
708
|
+
if (!key || !isCssPropertyKey(key)) continue;
|
|
709
|
+
const stringValue = getStringLiteralValue(prop.value);
|
|
710
|
+
if (stringValue && BARE_NUMBER_STRING_RE.test(stringValue) && !isUnitlessProperty(key)) {
|
|
711
|
+
context.report({
|
|
712
|
+
node: prop.value,
|
|
713
|
+
messageId: "bareNumberString",
|
|
714
|
+
data: {
|
|
715
|
+
property: key,
|
|
716
|
+
value: stringValue,
|
|
717
|
+
numeric: stringValue
|
|
718
|
+
}
|
|
719
|
+
});
|
|
720
|
+
continue;
|
|
721
|
+
}
|
|
722
|
+
if (options.checkSuspiciousUnitlessNumbers && SUSPICIOUS_UNITLESS_PROPERTIES.has(key)) {
|
|
723
|
+
const num = getNumericLiteralValue(prop.value);
|
|
724
|
+
if (num != null && num >= 8 && Number.isInteger(num)) context.report({
|
|
725
|
+
node: prop.value,
|
|
726
|
+
messageId: "suspiciousUnitlessNumber",
|
|
727
|
+
data: {
|
|
728
|
+
property: key,
|
|
729
|
+
value: String(num)
|
|
730
|
+
}
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
return {
|
|
736
|
+
CallExpression(node) {
|
|
737
|
+
for (const styleObj of getStyleObjectArguments(node)) visitStyleObjectLiterals(styleObj, checkStyleObject);
|
|
738
|
+
},
|
|
739
|
+
ObjectExpression(node) {
|
|
740
|
+
const parent = node.parent;
|
|
741
|
+
if (parent?.type === "Property" && (parent.key.type === "Identifier" || parent.key.type === "Literal")) {
|
|
742
|
+
const parentKey = parent.key.type === "Identifier" ? parent.key.name : typeof parent.key.value === "string" ? parent.key.value : null;
|
|
743
|
+
if (parentKey === "from" || parentKey === "to" || /^\d+%$/.test(parentKey ?? "")) visitStyleObjectLiterals(node, checkStyleObject);
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
};
|
|
747
|
+
}
|
|
664
748
|
});
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
749
|
+
//#endregion
|
|
750
|
+
//#region src/rules/no-removed-public-classname.ts
|
|
751
|
+
let comparisonDone = false;
|
|
752
|
+
let cachedRemoved = [];
|
|
753
|
+
let reportsEmitted = false;
|
|
668
754
|
function resolveRemovedClassNames(context, options) {
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
755
|
+
if (comparisonDone) return cachedRemoved;
|
|
756
|
+
const rootDir = node_path.default.resolve(options?.rootDir ?? context.cwd ?? process.cwd());
|
|
757
|
+
const snapshotPath = node_path.default.resolve(rootDir, options?.snapshotFile ?? _typestyles_cli.PUBLIC_CLASSNAMES_SNAPSHOT);
|
|
758
|
+
const snapshot = (0, _typestyles_cli.loadPublicClassNamesSnapshot)(snapshotPath);
|
|
759
|
+
if (!snapshot) {
|
|
760
|
+
comparisonDone = true;
|
|
761
|
+
cachedRemoved = [];
|
|
762
|
+
return cachedRemoved;
|
|
763
|
+
}
|
|
764
|
+
const current = (0, _typestyles_cli.collectPublicClassNamesSync)({ rootDir });
|
|
765
|
+
cachedRemoved = (0, _typestyles_cli.diffRemovedPublicClassNames)(snapshot, current);
|
|
766
|
+
comparisonDone = true;
|
|
767
|
+
return cachedRemoved;
|
|
682
768
|
}
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
reportsEmitted = true;
|
|
715
|
-
const removed = resolveRemovedClassNames(context, options);
|
|
716
|
-
for (const entry of removed) {
|
|
717
|
-
context.report({
|
|
718
|
-
node,
|
|
719
|
-
messageId: "removed",
|
|
720
|
-
data: { className: entry.className }
|
|
721
|
-
});
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
|
-
};
|
|
725
|
-
}
|
|
769
|
+
const noRemovedPublicClassname = createRule({
|
|
770
|
+
name: "no-removed-public-classname",
|
|
771
|
+
meta: {
|
|
772
|
+
type: "problem",
|
|
773
|
+
docs: { description: "Disallow removing or renaming semantic class names listed in `.typestyles-public-classnames.json`" },
|
|
774
|
+
messages: { removed: "Public class name `{{className}}` was removed or renamed. This is a breaking change — restore the name or regenerate the snapshot with `typestyles snapshot --write` after a deliberate semver bump." },
|
|
775
|
+
schema: [{
|
|
776
|
+
type: "object",
|
|
777
|
+
properties: {
|
|
778
|
+
snapshotFile: { type: "string" },
|
|
779
|
+
rootDir: { type: "string" }
|
|
780
|
+
},
|
|
781
|
+
additionalProperties: false
|
|
782
|
+
}]
|
|
783
|
+
},
|
|
784
|
+
defaultOptions: [{}],
|
|
785
|
+
create(context, [options]) {
|
|
786
|
+
const rootDir = node_path.default.resolve(options?.rootDir ?? context.cwd ?? process.cwd());
|
|
787
|
+
const snapshotPath = node_path.default.resolve(rootDir, options?.snapshotFile ?? _typestyles_cli.PUBLIC_CLASSNAMES_SNAPSHOT);
|
|
788
|
+
if (!(0, _typestyles_cli.loadPublicClassNamesSnapshot)(snapshotPath)) return {};
|
|
789
|
+
return { "Program:exit"(node) {
|
|
790
|
+
if (reportsEmitted) return;
|
|
791
|
+
reportsEmitted = true;
|
|
792
|
+
const removed = resolveRemovedClassNames(context, options);
|
|
793
|
+
for (const entry of removed) context.report({
|
|
794
|
+
node,
|
|
795
|
+
messageId: "removed",
|
|
796
|
+
data: { className: entry.className }
|
|
797
|
+
});
|
|
798
|
+
} };
|
|
799
|
+
}
|
|
726
800
|
});
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
const parentKey = parent.key.type === "Identifier" ? parent.key.name : typeof parent.key.value === "string" ? parent.key.value : null;
|
|
764
|
-
if (parentKey === "from" || parentKey === "to" || /^\d+%$/.test(parentKey ?? "")) {
|
|
765
|
-
visitStyleObjectLiterals(node, checkStyleObject);
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
}
|
|
769
|
-
};
|
|
770
|
-
}
|
|
801
|
+
//#endregion
|
|
802
|
+
//#region src/rules/no-shorthand-longhand-conflict.ts
|
|
803
|
+
const noShorthandLonghandConflict = createRule({
|
|
804
|
+
name: "no-shorthand-longhand-conflict",
|
|
805
|
+
meta: {
|
|
806
|
+
type: "problem",
|
|
807
|
+
docs: { description: "Disallow mixing CSS shorthand and longhand properties in the same TypeStyles style object" },
|
|
808
|
+
messages: { conflict: "`{{shorthand}}` and `{{longhand}}` must not appear in the same style object — the longhand is ignored or overridden unpredictably." },
|
|
809
|
+
schema: []
|
|
810
|
+
},
|
|
811
|
+
defaultOptions: [],
|
|
812
|
+
create(context) {
|
|
813
|
+
function checkStyleObject(obj) {
|
|
814
|
+
const conflicts = findShorthandLonghandConflicts(collectCssPropertyNames(obj));
|
|
815
|
+
for (const { shorthand, longhand } of conflicts) context.report({
|
|
816
|
+
node: obj,
|
|
817
|
+
messageId: "conflict",
|
|
818
|
+
data: {
|
|
819
|
+
shorthand,
|
|
820
|
+
longhand
|
|
821
|
+
}
|
|
822
|
+
});
|
|
823
|
+
}
|
|
824
|
+
return {
|
|
825
|
+
CallExpression(node) {
|
|
826
|
+
for (const styleObj of getStyleObjectArguments(node)) visitStyleObjectLiterals(styleObj, checkStyleObject);
|
|
827
|
+
},
|
|
828
|
+
ObjectExpression(node) {
|
|
829
|
+
const parent = node.parent;
|
|
830
|
+
if (parent?.type === "Property" && (parent.key.type === "Identifier" || parent.key.type === "Literal")) {
|
|
831
|
+
const parentKey = parent.key.type === "Identifier" ? parent.key.name : typeof parent.key.value === "string" ? parent.key.value : null;
|
|
832
|
+
if (parentKey === "from" || parentKey === "to" || /^\d+%$/.test(parentKey ?? "")) visitStyleObjectLiterals(node, checkStyleObject);
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
};
|
|
836
|
+
}
|
|
771
837
|
});
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
838
|
+
//#endregion
|
|
839
|
+
//#region src/index.ts
|
|
840
|
+
const rules = {
|
|
841
|
+
"no-default-scope-in-package": noDefaultScopeInPackage,
|
|
842
|
+
"no-shorthand-longhand-conflict": noShorthandLonghandConflict,
|
|
843
|
+
"no-invalid-unitless-value": noInvalidUnitlessValue,
|
|
844
|
+
"no-duplicate-namespace": noDuplicateNamespace,
|
|
845
|
+
"no-removed-public-classname": noRemovedPublicClassname
|
|
780
846
|
};
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
847
|
+
const plugin = {
|
|
848
|
+
meta: {
|
|
849
|
+
name: "@typestyles/eslint-plugin",
|
|
850
|
+
version: "0.1.0"
|
|
851
|
+
},
|
|
852
|
+
rules
|
|
787
853
|
};
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
"@typestyles/no-invalid-unitless-value": "error",
|
|
807
|
-
"@typestyles/no-duplicate-namespace": "error",
|
|
808
|
-
"@typestyles/no-default-scope-in-package": "error"
|
|
809
|
-
}
|
|
810
|
-
}
|
|
854
|
+
const configs = {
|
|
855
|
+
recommended: {
|
|
856
|
+
plugins: { "@typestyles": plugin },
|
|
857
|
+
rules: {
|
|
858
|
+
"@typestyles/no-shorthand-longhand-conflict": "error",
|
|
859
|
+
"@typestyles/no-invalid-unitless-value": "error",
|
|
860
|
+
"@typestyles/no-duplicate-namespace": "error"
|
|
861
|
+
}
|
|
862
|
+
},
|
|
863
|
+
package: {
|
|
864
|
+
plugins: { "@typestyles": plugin },
|
|
865
|
+
rules: {
|
|
866
|
+
"@typestyles/no-shorthand-longhand-conflict": "error",
|
|
867
|
+
"@typestyles/no-invalid-unitless-value": "error",
|
|
868
|
+
"@typestyles/no-duplicate-namespace": "error",
|
|
869
|
+
"@typestyles/no-default-scope-in-package": "error"
|
|
870
|
+
}
|
|
871
|
+
}
|
|
811
872
|
};
|
|
812
873
|
Object.assign(plugin, { configs });
|
|
813
|
-
|
|
814
|
-
|
|
874
|
+
//#endregion
|
|
815
875
|
exports.configs = configs;
|
|
816
|
-
exports.default =
|
|
876
|
+
exports.default = plugin;
|
|
817
877
|
exports.noDefaultScopeInPackage = noDefaultScopeInPackage;
|
|
818
878
|
exports.noDuplicateNamespace = noDuplicateNamespace;
|
|
819
879
|
exports.noInvalidUnitlessValue = noInvalidUnitlessValue;
|
|
820
880
|
exports.noRemovedPublicClassname = noRemovedPublicClassname;
|
|
821
881
|
exports.noShorthandLonghandConflict = noShorthandLonghandConflict;
|
|
822
882
|
exports.rules = rules;
|
|
823
|
-
|
|
883
|
+
|
|
824
884
|
//# sourceMappingURL=index.cjs.map
|