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