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