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