@unocss/eslint-plugin 66.5.10 → 66.5.12

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.mjs CHANGED
@@ -1,569 +1,451 @@
1
- import { join } from 'node:path';
2
- import { ESLintUtils } from '@typescript-eslint/utils';
3
- import { createSyncFn } from 'synckit';
4
- import { distDir } from './dirs.mjs';
5
- import MagicString from 'magic-string';
6
- import { AST_TOKEN_TYPES } from '@typescript-eslint/types';
7
- import 'node:url';
1
+ import { t as distDir } from "./dirs-DTjbV7PE.mjs";
2
+ import { join } from "node:path";
3
+ import { ESLintUtils } from "@typescript-eslint/utils";
4
+ import { createSyncFn } from "synckit";
5
+ import MagicString from "magic-string";
6
+ import { AST_TOKEN_TYPES } from "@typescript-eslint/types";
8
7
 
8
+ //#region src/constants.ts
9
9
  const CLASS_FIELDS = ["class", "classname"];
10
10
  const AST_NODES_WITH_QUOTES = ["Literal", "VLiteral"];
11
11
 
12
+ //#endregion
13
+ //#region src/rules/_.ts
12
14
  const syncAction = createSyncFn(join(distDir, "worker.mjs"));
13
- const createRule = ESLintUtils.RuleCreator(
14
- () => "https://unocss.dev/integrations/eslint#rules"
15
- );
15
+ const createRule = ESLintUtils.RuleCreator(() => "https://unocss.dev/integrations/eslint#rules");
16
16
 
17
- const IGNORE_ATTRIBUTES = ["style", "class", "classname", "value"];
18
- const orderAttributify = createRule({
19
- name: "order-attributify",
20
- meta: {
21
- type: "layout",
22
- fixable: "code",
23
- docs: {
24
- description: "Order of UnoCSS attributes"
25
- },
26
- messages: {
27
- "invalid-order": "UnoCSS attributes are not ordered"
28
- },
29
- schema: []
30
- },
31
- defaultOptions: [],
32
- create(context) {
33
- const scriptVisitor = {};
34
- const templateBodyVisitor = {
35
- VStartTag(node) {
36
- const valueless = node.attributes.filter((i) => typeof i.key?.name === "string" && !IGNORE_ATTRIBUTES.includes(i.key?.name?.toLowerCase()) && i.value == null);
37
- if (!valueless.length)
38
- return;
39
- const input = valueless.map((i) => i.key.name).join(" ").trim();
40
- const sorted = syncAction(
41
- context.settings.unocss?.configPath,
42
- "sort",
43
- input,
44
- context.filename
45
- );
46
- if (sorted !== input) {
47
- context.report({
48
- node,
49
- messageId: "invalid-order",
50
- fix(fixer) {
51
- const codeFull = context.getSourceCode();
52
- const offset = node.range[0];
53
- const code = codeFull.getText().slice(node.range[0], node.range[1]);
54
- const s = new MagicString(code);
55
- const sortedNodes = valueless.map((i) => [i.range[0] - offset, i.range[1] - offset]).sort((a, b) => b[0] - a[0]);
56
- for (const [start, end] of sortedNodes.slice(1))
57
- s.remove(start, end);
58
- s.overwrite(sortedNodes[0][0], sortedNodes[0][1], ` ${sorted.trim()} `);
59
- return fixer.replaceText(node, s.toString());
60
- }
61
- });
62
- }
63
- }
64
- };
65
- const parserServices = context?.sourceCode.parserServices || context.parserServices;
66
- if (parserServices == null || parserServices.defineTemplateBodyVisitor == null) {
67
- return scriptVisitor;
68
- } else {
69
- return parserServices?.defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor);
70
- }
71
- }
17
+ //#endregion
18
+ //#region src/rules/order-attributify.ts
19
+ const IGNORE_ATTRIBUTES = [
20
+ "style",
21
+ "class",
22
+ "classname",
23
+ "value"
24
+ ];
25
+ var order_attributify_default = createRule({
26
+ name: "order-attributify",
27
+ meta: {
28
+ type: "layout",
29
+ fixable: "code",
30
+ docs: { description: "Order of UnoCSS attributes" },
31
+ messages: { "invalid-order": "UnoCSS attributes are not ordered" },
32
+ schema: []
33
+ },
34
+ defaultOptions: [],
35
+ create(context) {
36
+ const scriptVisitor = {};
37
+ const templateBodyVisitor = { VStartTag(node) {
38
+ var _context$settings$uno;
39
+ const valueless = node.attributes.filter((i) => {
40
+ var _i$key, _i$key2;
41
+ return typeof ((_i$key = i.key) === null || _i$key === void 0 ? void 0 : _i$key.name) === "string" && !IGNORE_ATTRIBUTES.includes((_i$key2 = i.key) === null || _i$key2 === void 0 || (_i$key2 = _i$key2.name) === null || _i$key2 === void 0 ? void 0 : _i$key2.toLowerCase()) && i.value == null;
42
+ });
43
+ if (!valueless.length) return;
44
+ const input = valueless.map((i) => i.key.name).join(" ").trim();
45
+ const sorted = syncAction((_context$settings$uno = context.settings.unocss) === null || _context$settings$uno === void 0 ? void 0 : _context$settings$uno.configPath, "sort", input, context.filename);
46
+ if (sorted !== input) context.report({
47
+ node,
48
+ messageId: "invalid-order",
49
+ fix(fixer) {
50
+ const codeFull = context.getSourceCode();
51
+ const offset = node.range[0];
52
+ const s = new MagicString(codeFull.getText().slice(node.range[0], node.range[1]));
53
+ const sortedNodes = valueless.map((i) => [i.range[0] - offset, i.range[1] - offset]).sort((a, b) => b[0] - a[0]);
54
+ for (const [start, end] of sortedNodes.slice(1)) s.remove(start, end);
55
+ s.overwrite(sortedNodes[0][0], sortedNodes[0][1], ` ${sorted.trim()} `);
56
+ return fixer.replaceText(node, s.toString());
57
+ }
58
+ });
59
+ } };
60
+ const parserServices = (context === null || context === void 0 ? void 0 : context.sourceCode.parserServices) || context.parserServices;
61
+ if (parserServices == null || parserServices.defineTemplateBodyVisitor == null) return scriptVisitor;
62
+ else return parserServices === null || parserServices === void 0 ? void 0 : parserServices.defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor);
63
+ }
72
64
  });
73
65
 
74
- const blocklist = createRule({
75
- name: "blocklist",
76
- meta: {
77
- type: "problem",
78
- fixable: "code",
79
- docs: {
80
- description: "Utilities in UnoCSS blocklist"
81
- },
82
- messages: {
83
- "in-blocklist": '"{{name}}" is in blocklist{{reason}}'
84
- },
85
- schema: []
86
- },
87
- defaultOptions: [],
88
- create(context) {
89
- const checkLiteral = (node) => {
90
- if (typeof node.value !== "string" || !node.value.trim())
91
- return;
92
- const input = node.value;
93
- const blocked = syncAction(
94
- context.settings.unocss?.configPath,
95
- "blocklist",
96
- input,
97
- context.filename
98
- );
99
- blocked.forEach(([name, meta]) => {
100
- context.report({
101
- node,
102
- messageId: "in-blocklist",
103
- data: {
104
- name,
105
- reason: meta?.message ? `: ${meta.message}` : ""
106
- }
107
- });
108
- });
109
- };
110
- const scriptVisitor = {
111
- JSXAttribute(node) {
112
- if (typeof node.name.name === "string" && CLASS_FIELDS.includes(node.name.name.toLowerCase()) && node.value) {
113
- if (node.value.type === "Literal")
114
- checkLiteral(node.value);
115
- }
116
- },
117
- SvelteAttribute(node) {
118
- if (node.key.name === "class") {
119
- if (node.value?.[0].type === "SvelteLiteral")
120
- checkLiteral(node.value[0]);
121
- }
122
- }
123
- };
124
- const templateBodyVisitor = {
125
- VAttribute(node) {
126
- if (node.key.name === "class") {
127
- if (node.value.type === "VLiteral")
128
- checkLiteral(node.value);
129
- }
130
- },
131
- // Attributify
132
- VStartTag(node) {
133
- const valueless = node.attributes.filter((i) => typeof i.key?.name === "string" && !IGNORE_ATTRIBUTES.includes(i.key?.name?.toLowerCase()) && i.value == null);
134
- if (!valueless.length)
135
- return;
136
- for (const node2 of valueless) {
137
- if (!node2?.key?.name)
138
- continue;
139
- const blocked = syncAction(
140
- context.settings.unocss?.configPath,
141
- "blocklist",
142
- node2.key.name,
143
- context.filename
144
- );
145
- blocked.forEach(([name, meta]) => {
146
- context.report({
147
- node: node2,
148
- messageId: "in-blocklist",
149
- data: {
150
- name,
151
- reason: meta?.message ? `: ${meta.message}` : ""
152
- }
153
- });
154
- });
155
- }
156
- }
157
- };
158
- const parserServices = context?.sourceCode.parserServices || context.parserServices;
159
- if (parserServices == null || parserServices.defineTemplateBodyVisitor == null) {
160
- return scriptVisitor;
161
- } else {
162
- return parserServices?.defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor);
163
- }
164
- }
66
+ //#endregion
67
+ //#region src/rules/blocklist.ts
68
+ var blocklist_default = createRule({
69
+ name: "blocklist",
70
+ meta: {
71
+ type: "problem",
72
+ fixable: "code",
73
+ docs: { description: "Utilities in UnoCSS blocklist" },
74
+ messages: { "in-blocklist": "\"{{name}}\" is in blocklist{{reason}}" },
75
+ schema: []
76
+ },
77
+ defaultOptions: [],
78
+ create(context) {
79
+ const checkLiteral = (node) => {
80
+ var _context$settings$uno;
81
+ if (typeof node.value !== "string" || !node.value.trim()) return;
82
+ const input = node.value;
83
+ syncAction((_context$settings$uno = context.settings.unocss) === null || _context$settings$uno === void 0 ? void 0 : _context$settings$uno.configPath, "blocklist", input, context.filename).forEach(([name, meta]) => {
84
+ context.report({
85
+ node,
86
+ messageId: "in-blocklist",
87
+ data: {
88
+ name,
89
+ reason: (meta === null || meta === void 0 ? void 0 : meta.message) ? `: ${meta.message}` : ""
90
+ }
91
+ });
92
+ });
93
+ };
94
+ const scriptVisitor = {
95
+ JSXAttribute(node) {
96
+ if (typeof node.name.name === "string" && CLASS_FIELDS.includes(node.name.name.toLowerCase()) && node.value) {
97
+ if (node.value.type === "Literal") checkLiteral(node.value);
98
+ }
99
+ },
100
+ SvelteAttribute(node) {
101
+ if (node.key.name === "class") {
102
+ var _node$value;
103
+ if (((_node$value = node.value) === null || _node$value === void 0 ? void 0 : _node$value[0].type) === "SvelteLiteral") checkLiteral(node.value[0]);
104
+ }
105
+ }
106
+ };
107
+ const templateBodyVisitor = {
108
+ VAttribute(node) {
109
+ if (node.key.name === "class") {
110
+ if (node.value.type === "VLiteral") checkLiteral(node.value);
111
+ }
112
+ },
113
+ VStartTag(node) {
114
+ const valueless = node.attributes.filter((i) => {
115
+ var _i$key, _i$key2;
116
+ return typeof ((_i$key = i.key) === null || _i$key === void 0 ? void 0 : _i$key.name) === "string" && !IGNORE_ATTRIBUTES.includes((_i$key2 = i.key) === null || _i$key2 === void 0 || (_i$key2 = _i$key2.name) === null || _i$key2 === void 0 ? void 0 : _i$key2.toLowerCase()) && i.value == null;
117
+ });
118
+ if (!valueless.length) return;
119
+ for (const node$1 of valueless) {
120
+ var _node$key, _context$settings$uno2;
121
+ if (!(node$1 === null || node$1 === void 0 || (_node$key = node$1.key) === null || _node$key === void 0 ? void 0 : _node$key.name)) continue;
122
+ syncAction((_context$settings$uno2 = context.settings.unocss) === null || _context$settings$uno2 === void 0 ? void 0 : _context$settings$uno2.configPath, "blocklist", node$1.key.name, context.filename).forEach(([name, meta]) => {
123
+ context.report({
124
+ node: node$1,
125
+ messageId: "in-blocklist",
126
+ data: {
127
+ name,
128
+ reason: (meta === null || meta === void 0 ? void 0 : meta.message) ? `: ${meta.message}` : ""
129
+ }
130
+ });
131
+ });
132
+ }
133
+ }
134
+ };
135
+ const parserServices = (context === null || context === void 0 ? void 0 : context.sourceCode.parserServices) || context.parserServices;
136
+ if (parserServices == null || parserServices.defineTemplateBodyVisitor == null) return scriptVisitor;
137
+ else return parserServices === null || parserServices === void 0 ? void 0 : parserServices.defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor);
138
+ }
165
139
  });
166
140
 
167
- const enforceClassCompile = createRule({
168
- name: "enforce-class-compile",
169
- meta: {
170
- type: "problem",
171
- fixable: "code",
172
- docs: {
173
- description: "Enforce class compilation"
174
- },
175
- messages: {
176
- missing: "prefix: `{{prefix}}` is missing"
177
- },
178
- schema: [{
179
- type: "object",
180
- properties: {
181
- prefix: {
182
- type: "string"
183
- },
184
- enableFix: {
185
- type: "boolean"
186
- }
187
- },
188
- additionalProperties: false
189
- }]
190
- },
191
- defaultOptions: [{ prefix: ":uno:", enableFix: true }],
192
- create(context, [mergedOptions]) {
193
- const CLASS_COMPILE_PREFIX = `${mergedOptions.prefix} `;
194
- const ENABLE_FIX = mergedOptions.enableFix;
195
- function report({ node, fix }) {
196
- context.report({
197
- node,
198
- loc: node.loc,
199
- messageId: "missing",
200
- data: { prefix: CLASS_COMPILE_PREFIX.trim() },
201
- fix: (...args) => ENABLE_FIX ? fix(...args) : null
202
- });
203
- }
204
- const scriptVisitor = {
205
- JSXAttribute(_node) {
206
- },
207
- SvelteAttribute(_node) {
208
- }
209
- };
210
- const reportClassList = (node, classList) => {
211
- if (classList.startsWith(CLASS_COMPILE_PREFIX))
212
- return;
213
- report({
214
- node,
215
- fix(fixer) {
216
- return fixer.replaceTextRange([node.range[0] + 1, node.range[1] - 1], `${CLASS_COMPILE_PREFIX}${classList}`);
217
- }
218
- });
219
- };
220
- const templateBodyVisitor = {
221
- [`VAttribute[key.name=class]`](attr) {
222
- const valueNode = attr.value;
223
- if (!valueNode || !valueNode.value)
224
- return;
225
- reportClassList(valueNode, valueNode.value);
226
- },
227
- [`VAttribute[key.argument.name=class] VExpressionContainer Literal:not(ConditionalExpression .test Literal):not(Property .value Literal)`](literal) {
228
- if (!literal.value || typeof literal.value !== "string")
229
- return;
230
- reportClassList(literal, literal.value);
231
- },
232
- [`VAttribute[key.argument.name=class] VExpressionContainer TemplateElement`](templateElement) {
233
- if (!templateElement.value.raw)
234
- return;
235
- reportClassList(templateElement, templateElement.value.raw);
236
- },
237
- [`VAttribute[key.argument.name=class] VExpressionContainer Property`](property) {
238
- if (property.key.type !== "Identifier")
239
- return;
240
- const classListString = property.key.name;
241
- if (classListString.startsWith(CLASS_COMPILE_PREFIX))
242
- return;
243
- report({
244
- node: property.key,
245
- fix(fixer) {
246
- let replacePropertyKeyText = `'${CLASS_COMPILE_PREFIX}${classListString}'`;
247
- if (property.shorthand)
248
- replacePropertyKeyText = `${replacePropertyKeyText}: ${classListString}`;
249
- return fixer.replaceTextRange(property.key.range, replacePropertyKeyText);
250
- }
251
- });
252
- }
253
- };
254
- const parserServices = context?.sourceCode.parserServices || context.parserServices;
255
- if (parserServices == null || parserServices.defineTemplateBodyVisitor == null) {
256
- return scriptVisitor;
257
- } else {
258
- return parserServices?.defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor);
259
- }
260
- }
141
+ //#endregion
142
+ //#region src/rules/enforce-class-compile.ts
143
+ var enforce_class_compile_default = createRule({
144
+ name: "enforce-class-compile",
145
+ meta: {
146
+ type: "problem",
147
+ fixable: "code",
148
+ docs: { description: "Enforce class compilation" },
149
+ messages: { missing: "prefix: `{{prefix}}` is missing" },
150
+ schema: [{
151
+ type: "object",
152
+ properties: {
153
+ prefix: { type: "string" },
154
+ enableFix: { type: "boolean" }
155
+ },
156
+ additionalProperties: false
157
+ }]
158
+ },
159
+ defaultOptions: [{
160
+ prefix: ":uno:",
161
+ enableFix: true
162
+ }],
163
+ create(context, [mergedOptions]) {
164
+ const CLASS_COMPILE_PREFIX = `${mergedOptions.prefix} `;
165
+ const ENABLE_FIX = mergedOptions.enableFix;
166
+ function report({ node, fix }) {
167
+ context.report({
168
+ node,
169
+ loc: node.loc,
170
+ messageId: "missing",
171
+ data: { prefix: CLASS_COMPILE_PREFIX.trim() },
172
+ fix: (...args) => ENABLE_FIX ? fix(...args) : null
173
+ });
174
+ }
175
+ const scriptVisitor = {
176
+ JSXAttribute(_node) {},
177
+ SvelteAttribute(_node) {}
178
+ };
179
+ const reportClassList = (node, classList) => {
180
+ if (classList.startsWith(CLASS_COMPILE_PREFIX)) return;
181
+ report({
182
+ node,
183
+ fix(fixer) {
184
+ return fixer.replaceTextRange([node.range[0] + 1, node.range[1] - 1], `${CLASS_COMPILE_PREFIX}${classList}`);
185
+ }
186
+ });
187
+ };
188
+ const templateBodyVisitor = {
189
+ [`VAttribute[key.name=class]`](attr) {
190
+ const valueNode = attr.value;
191
+ if (!valueNode || !valueNode.value) return;
192
+ reportClassList(valueNode, valueNode.value);
193
+ },
194
+ [`VAttribute[key.argument.name=class] VExpressionContainer Literal:not(ConditionalExpression .test Literal):not(Property .value Literal)`](literal) {
195
+ if (!literal.value || typeof literal.value !== "string") return;
196
+ reportClassList(literal, literal.value);
197
+ },
198
+ [`VAttribute[key.argument.name=class] VExpressionContainer TemplateElement`](templateElement) {
199
+ if (!templateElement.value.raw) return;
200
+ reportClassList(templateElement, templateElement.value.raw);
201
+ },
202
+ [`VAttribute[key.argument.name=class] VExpressionContainer Property`](property) {
203
+ if (property.key.type !== "Identifier") return;
204
+ const classListString = property.key.name;
205
+ if (classListString.startsWith(CLASS_COMPILE_PREFIX)) return;
206
+ report({
207
+ node: property.key,
208
+ fix(fixer) {
209
+ let replacePropertyKeyText = `'${CLASS_COMPILE_PREFIX}${classListString}'`;
210
+ if (property.shorthand) replacePropertyKeyText = `${replacePropertyKeyText}: ${classListString}`;
211
+ return fixer.replaceTextRange(property.key.range, replacePropertyKeyText);
212
+ }
213
+ });
214
+ }
215
+ };
216
+ const parserServices = (context === null || context === void 0 ? void 0 : context.sourceCode.parserServices) || context.parserServices;
217
+ if (parserServices == null || parserServices.defineTemplateBodyVisitor == null) return scriptVisitor;
218
+ else return parserServices === null || parserServices === void 0 ? void 0 : parserServices.defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor);
219
+ }
261
220
  });
262
221
 
263
- const order = createRule({
264
- name: "order",
265
- meta: {
266
- type: "layout",
267
- fixable: "code",
268
- docs: {
269
- description: "Order of UnoCSS utilities in class attribute"
270
- },
271
- messages: {
272
- "invalid-order": "UnoCSS utilities are not ordered"
273
- },
274
- schema: [
275
- {
276
- type: "object",
277
- properties: {
278
- unoFunctions: {
279
- type: "array",
280
- items: { type: "string" }
281
- },
282
- unoVariables: {
283
- type: "array",
284
- items: { type: "string" }
285
- }
286
- },
287
- additionalProperties: false
288
- }
289
- ]
290
- },
291
- defaultOptions: [
292
- {
293
- unoFunctions: ["clsx", "classnames"],
294
- unoVariables: ["^cls", "classNames?$"]
295
- // for example `clsButton = ''` or `buttonClassNames = {}`
296
- }
297
- ],
298
- create(context) {
299
- let { unoFunctions = ["clsx", "classnames"], unoVariables = ["^cls", "classNames?$"] } = context.options[0] || {};
300
- unoFunctions = unoFunctions.map((name) => name.toLowerCase());
301
- function isUnoFunction(name) {
302
- return unoFunctions.includes(name.toLowerCase());
303
- }
304
- const unoVariablesRegexes = unoVariables.map((regex) => new RegExp(regex, "i"));
305
- function isUnoVariable(name) {
306
- return unoVariablesRegexes.some((reg) => reg.test(name));
307
- }
308
- function checkLiteral(node, addSpace) {
309
- if (typeof node.value !== "string" || !node.value.trim())
310
- return;
311
- const input = node.value;
312
- let sorted = syncAction(
313
- context.settings.unocss?.configPath,
314
- "sort",
315
- input,
316
- context.filename
317
- ).trim();
318
- if (addSpace === "before")
319
- sorted = ` ${sorted}`;
320
- else if (addSpace === "after")
321
- sorted += " ";
322
- if (sorted !== input) {
323
- const nodeOrToken = node.type === "SvelteLiteral" ? { type: AST_TOKEN_TYPES.String, value: node.value, loc: node.loc, range: node.range } : node;
324
- context.report({
325
- node: nodeOrToken,
326
- loc: node.loc,
327
- messageId: "invalid-order",
328
- fix(fixer) {
329
- if (AST_NODES_WITH_QUOTES.includes(node.type))
330
- return fixer.replaceTextRange([node.range[0] + 1, node.range[1] - 1], sorted);
331
- else
332
- return fixer.replaceText(nodeOrToken, sorted);
333
- }
334
- });
335
- }
336
- }
337
- function checkTemplateElement(quasi) {
338
- const input = quasi.value.raw;
339
- if (!input)
340
- return;
341
- const getRange = () => {
342
- const text = context.sourceCode.getText(quasi);
343
- const raw = quasi.value.raw;
344
- if (!text.includes(raw))
345
- return;
346
- const rawStart = text.indexOf(raw);
347
- const start = quasi.range[0] + rawStart;
348
- const end = quasi.range[0] + rawStart + raw.length;
349
- if (start < quasi.range[0] || end > quasi.range[1])
350
- return;
351
- return [start, end];
352
- };
353
- const realRange = getRange();
354
- if (!realRange)
355
- return;
356
- let sorted = syncAction(
357
- context.settings.unocss?.configPath,
358
- "sort",
359
- input,
360
- context.filename
361
- ).trim();
362
- if (/^\s/.test(input))
363
- sorted = ` ${sorted}`;
364
- if (/\s$/.test(input))
365
- sorted += " ";
366
- if (sorted !== input) {
367
- context.report({
368
- node: quasi,
369
- loc: quasi.loc,
370
- messageId: "invalid-order",
371
- fix(fixer) {
372
- const realRange2 = getRange();
373
- if (!realRange2)
374
- return null;
375
- return fixer.replaceTextRange(realRange2, sorted);
376
- }
377
- });
378
- }
379
- }
380
- function isPossibleLiteral(node) {
381
- return node.type === "Literal" || node.type === "TemplateLiteral" || node.type === "TaggedTemplateExpression";
382
- }
383
- function checkPossibleLiteral(...nodes) {
384
- nodes.forEach((node) => {
385
- if (!isPossibleLiteral(node))
386
- return;
387
- if (node.type === "Literal" && typeof node.value === "string") {
388
- return checkLiteral(node);
389
- }
390
- const isSimpleTemplateLiteral = (node2) => {
391
- return node2.expressions.length === 0 && node2.quasis.length === 1;
392
- };
393
- if (node.type === "TemplateLiteral" && isSimpleTemplateLiteral(node)) {
394
- return checkTemplateElement(node.quasis[0]);
395
- }
396
- const isStringRaw = (tag) => {
397
- return tag.type === "MemberExpression" && tag.object.type === "Identifier" && tag.object.name === "String" && tag.property.type === "Identifier" && tag.property.name === "raw";
398
- };
399
- if (node.type === "TaggedTemplateExpression" && isStringRaw(node.tag) && isSimpleTemplateLiteral(node.quasi)) {
400
- return checkTemplateElement(node.quasi.quasis[0]);
401
- }
402
- if (node.type === "TemplateLiteral" && node.expressions.length > 0 && node.quasis.length > 0) {
403
- return void node.quasis.forEach((quasi) => {
404
- checkTemplateElement(quasi);
405
- });
406
- }
407
- });
408
- }
409
- const scriptVisitor = {
410
- JSXAttribute(node) {
411
- if (typeof node.name.name === "string" && CLASS_FIELDS.includes(node.name.name.toLowerCase()) && node.value) {
412
- if (isPossibleLiteral(node.value))
413
- return checkPossibleLiteral(node.value);
414
- else if (node.value.type === "JSXExpressionContainer" && isPossibleLiteral(node.value.expression))
415
- return checkPossibleLiteral(node.value.expression);
416
- }
417
- },
418
- SvelteAttribute(node) {
419
- if (node.key.name === "class") {
420
- let checkExpressionRecursively = function(expression) {
421
- if (expression.type !== "ConditionalExpression")
422
- return;
423
- if (expression.consequent.type === "Literal") {
424
- checkLiteral(expression.consequent);
425
- }
426
- if (expression.alternate) {
427
- if (expression.alternate.type === "ConditionalExpression") {
428
- checkExpressionRecursively(expression.alternate);
429
- } else if (expression.alternate.type === "Literal") {
430
- checkLiteral(expression.alternate);
431
- }
432
- }
433
- };
434
- if (!node.value.length)
435
- return;
436
- node.value.forEach((obj, i) => {
437
- if (obj.type === "SvelteMustacheTag") {
438
- checkExpressionRecursively(obj.expression);
439
- } else if (obj.type === "SvelteLiteral") {
440
- const addSpace = node.value?.[i - 1]?.type === "SvelteMustacheTag" ? "before" : node.value?.[i + 1]?.type === "SvelteMustacheTag" ? "after" : void 0;
441
- checkLiteral(obj, addSpace);
442
- }
443
- });
444
- }
445
- },
446
- // for Future node types
447
- // https://typescript-eslint.io/play/#ts=5.8.3&showAST=es&fileType=.tsx&code=PTAEDMCcHsFtQBYBckAcDOAuEB3PA6AO1VgCt18BjOYVAQ0oGs6BzAU2EoBt0APAfgZIAlgDc2AFToAjALzUAJm1AAoEKG59OPXvgX4k6FUu51IywnVht09Sss29QAbxWhQSAJ6plAYS506OgAanRcAK7KsqD%2BgegAgpCQdJ6gAD4xAUEAIsKUItCWkKkZ6EiQwoQs6aCE4bDSbJA10sIslUg1dVxcLdDQXGx0hDXhhErglWwKANxuHt5%2BWei5%2BcKFZqnRAEps1JAKADxlFVUANKDDngB8c%2B5ePplxiclbT0GhEWwA2gC6dxAxmtChodAAKfCQyqocKGTDvEJhSJ-ACU8JOlRYcwAvsY9gFzIDCMCRo4IVDiLCsKC%2BPhYh8kT9fmjQBiqnMVNRCGUPDYkABGUDRcqRTmFHlIPkAJiFEDC6DYYu5nUlZQAzLKRYquTy2LxynR6egAHJWKKgADksEgAFoACyoXgWlSDTqmIKm6zo8qY0bjNiTQjTFRqMDoYSwVCDDSBbXLT3msnzC2oG38x2ga02qWOi1neaqgWgfiW6RcaBMC2geEWwiFNh5gvS0AAMhbpfLlfz7mcoAARAg2D1oH34VqLn2cNBIFwFKO5TxlNj8yiQ%2BpYNPlEgEMNQPXQ6AAAaFwVt3llGVni3gQZOw%2BgQD6coB6M1AABloO1KGEAKK8VDmIJ1kIA93FAG1QEGcAkDHPlT3bQspRA9xwIqFhkBrG89SrV9hElZIuAPQBRU0AODkjxPVt22vW8LXvQBJb0AGBVABBNQAwFzXMAD0lSMAklVkfSqA9OXjM1ZSTe5YIoo9MN4Q9u3PIsz0PKTQAAEmcPUDSNBNsRkpsyjg0AAGU%2BJYfBkhwRTb1AaQWBtb5RDMMEbRtdA4DYAAdAB9eyKhkQYUV%2BHSxL0iSjNOEyzIsvUrJsuyHKclzrE87zhF8th-JUtT9WSTSzW0lcgA&eslintrc=N4KABGBEBOCuA2BTAzpAXGYBfEWg&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false
448
- CallExpression(node) {
449
- if (!(node.callee.type === "Identifier" && isUnoFunction(node.callee.name)))
450
- return;
451
- node.arguments.forEach((arg) => {
452
- if (isPossibleLiteral(arg)) {
453
- return checkPossibleLiteral(arg);
454
- }
455
- if (arg.type === "ConditionalExpression") {
456
- return checkPossibleLiteral(arg.consequent, arg.alternate);
457
- }
458
- if (arg.type === "LogicalExpression") {
459
- return checkPossibleLiteral(arg.left, arg.right);
460
- }
461
- function handleObjectExpression(node2) {
462
- node2.properties.forEach((p) => {
463
- if (p.type !== "Property")
464
- return;
465
- if (isPossibleLiteral(p.value)) {
466
- return checkPossibleLiteral(p.value);
467
- }
468
- if (p.value.type === "ObjectExpression") {
469
- return handleObjectExpression(p.value);
470
- }
471
- });
472
- const keys = node2.properties.filter((p) => p.type === "Property").map((p) => p.key);
473
- return checkPossibleLiteral(...keys);
474
- }
475
- if (arg.type === "ObjectExpression") {
476
- return handleObjectExpression(arg);
477
- }
478
- if (arg.type === "ArrayExpression") {
479
- return arg.elements.forEach((element) => {
480
- if (element && isPossibleLiteral(element)) {
481
- return checkPossibleLiteral(element);
482
- }
483
- });
484
- }
485
- });
486
- },
487
- // https://typescript-eslint.io/play/#ts=5.8.2&showAST=es&fileType=.tsx&code=MYewdgzgLgBApgDygJwIYGEA2qIQHKoC2cMAvDAOQBeAtAIwAMDFAUCwPTswBuqyAlqgBGmEgBM4wbGij9wLUJFhSIAIQCuUKODKVCyeq0XQYKjVvAAmXQAN99GABIA3ohQZsuAsQC%2BNheAmZpraYADMtvZ0Tq5IaFg4%2BERwfjA4poFQbJwwIEIAVpKwElJ8qLLyxrBCUGAJXskQus4sMDASAGao6phQAFx6mDSWAA4IFAA0rTAA7vxQABYAonGoAzYdoggw83CEEDTAcGBQcMgwQgDmNDMLuzCnSDQiqMAA1jFu8Z5JvjZTbQQAxabTaAE8BhRCENRuNpj4WAiOFx0lV2pJpOU5GAAkoLrV6r84BBrOQQeiuj1%2BoNhmNJtMgTByeDIdDaXC2gifGkmlUgA&eslintrc=N4KABGBEBOCuA2BTAzpAXGYBfEWg&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false
488
- VariableDeclarator(node) {
489
- if (node.id.type !== "Identifier" || !node.init || !isUnoVariable(node.id.name))
490
- return;
491
- if (isPossibleLiteral(node.init)) {
492
- return checkPossibleLiteral(node.init);
493
- }
494
- if (node.init.type === "TSAsExpression" && isPossibleLiteral(node.init.expression)) {
495
- return checkPossibleLiteral(node.init.expression);
496
- }
497
- function handleObjectExpression(node2) {
498
- node2.properties.forEach((p) => {
499
- if (p.type !== "Property")
500
- return;
501
- if (isPossibleLiteral(p.value)) {
502
- return checkPossibleLiteral(p.value);
503
- }
504
- if (p.value.type === "ObjectExpression") {
505
- return handleObjectExpression(p.value);
506
- }
507
- });
508
- }
509
- if (node.init.type === "ObjectExpression") {
510
- return handleObjectExpression(node.init);
511
- }
512
- if (node.init.type === "TSAsExpression" && node.init.expression.type === "ObjectExpression") {
513
- return handleObjectExpression(node.init.expression);
514
- }
515
- }
516
- };
517
- const templateBodyVisitor = {
518
- VAttribute(node) {
519
- if (node.key.name === "class") {
520
- if (node.value.type === "VLiteral")
521
- checkLiteral(node.value);
522
- }
523
- }
524
- };
525
- const parserServices = context?.sourceCode.parserServices || context.parserServices;
526
- if (parserServices == null || parserServices.defineTemplateBodyVisitor == null) {
527
- return scriptVisitor;
528
- } else {
529
- return parserServices?.defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor);
530
- }
531
- }
222
+ //#endregion
223
+ //#region src/rules/order.ts
224
+ var order_default = createRule({
225
+ name: "order",
226
+ meta: {
227
+ type: "layout",
228
+ fixable: "code",
229
+ docs: { description: "Order of UnoCSS utilities in class attribute" },
230
+ messages: { "invalid-order": "UnoCSS utilities are not ordered" },
231
+ schema: [{
232
+ type: "object",
233
+ properties: {
234
+ unoFunctions: {
235
+ type: "array",
236
+ items: { type: "string" }
237
+ },
238
+ unoVariables: {
239
+ type: "array",
240
+ items: { type: "string" }
241
+ }
242
+ },
243
+ additionalProperties: false
244
+ }]
245
+ },
246
+ defaultOptions: [{
247
+ unoFunctions: ["clsx", "classnames"],
248
+ unoVariables: ["^cls", "classNames?$"]
249
+ }],
250
+ create(context) {
251
+ let { unoFunctions = ["clsx", "classnames"], unoVariables = ["^cls", "classNames?$"] } = context.options[0] || {};
252
+ unoFunctions = unoFunctions.map((name) => name.toLowerCase());
253
+ function isUnoFunction(name) {
254
+ return unoFunctions.includes(name.toLowerCase());
255
+ }
256
+ const unoVariablesRegexes = unoVariables.map((regex) => new RegExp(regex, "i"));
257
+ function isUnoVariable(name) {
258
+ return unoVariablesRegexes.some((reg) => reg.test(name));
259
+ }
260
+ function checkLiteral(node, addSpace) {
261
+ var _context$settings$uno;
262
+ if (typeof node.value !== "string" || !node.value.trim()) return;
263
+ const input = node.value;
264
+ let sorted = syncAction((_context$settings$uno = context.settings.unocss) === null || _context$settings$uno === void 0 ? void 0 : _context$settings$uno.configPath, "sort", input, context.filename).trim();
265
+ if (addSpace === "before") sorted = ` ${sorted}`;
266
+ else if (addSpace === "after") sorted += " ";
267
+ if (sorted !== input) {
268
+ const nodeOrToken = node.type === "SvelteLiteral" ? {
269
+ type: AST_TOKEN_TYPES.String,
270
+ value: node.value,
271
+ loc: node.loc,
272
+ range: node.range
273
+ } : node;
274
+ context.report({
275
+ node: nodeOrToken,
276
+ loc: node.loc,
277
+ messageId: "invalid-order",
278
+ fix(fixer) {
279
+ if (AST_NODES_WITH_QUOTES.includes(node.type)) return fixer.replaceTextRange([node.range[0] + 1, node.range[1] - 1], sorted);
280
+ else return fixer.replaceText(nodeOrToken, sorted);
281
+ }
282
+ });
283
+ }
284
+ }
285
+ function checkTemplateElement(quasi) {
286
+ var _context$settings$uno2;
287
+ const input = quasi.value.raw;
288
+ if (!input) return;
289
+ const getRange = () => {
290
+ const text = context.sourceCode.getText(quasi);
291
+ const raw = quasi.value.raw;
292
+ if (!text.includes(raw)) return;
293
+ const rawStart = text.indexOf(raw);
294
+ const start = quasi.range[0] + rawStart;
295
+ const end = quasi.range[0] + rawStart + raw.length;
296
+ if (start < quasi.range[0] || end > quasi.range[1]) return;
297
+ return [start, end];
298
+ };
299
+ if (!getRange()) return;
300
+ let sorted = syncAction((_context$settings$uno2 = context.settings.unocss) === null || _context$settings$uno2 === void 0 ? void 0 : _context$settings$uno2.configPath, "sort", input, context.filename).trim();
301
+ if (/^\s/.test(input)) sorted = ` ${sorted}`;
302
+ if (/\s$/.test(input)) sorted += " ";
303
+ if (sorted !== input) context.report({
304
+ node: quasi,
305
+ loc: quasi.loc,
306
+ messageId: "invalid-order",
307
+ fix(fixer) {
308
+ const realRange = getRange();
309
+ if (!realRange) return null;
310
+ return fixer.replaceTextRange(realRange, sorted);
311
+ }
312
+ });
313
+ }
314
+ function isPossibleLiteral(node) {
315
+ return node.type === "Literal" || node.type === "TemplateLiteral" || node.type === "TaggedTemplateExpression";
316
+ }
317
+ function checkPossibleLiteral(...nodes) {
318
+ nodes.forEach((node) => {
319
+ if (!isPossibleLiteral(node)) return;
320
+ if (node.type === "Literal" && typeof node.value === "string") return checkLiteral(node);
321
+ const isSimpleTemplateLiteral = (node$1) => {
322
+ return node$1.expressions.length === 0 && node$1.quasis.length === 1;
323
+ };
324
+ if (node.type === "TemplateLiteral" && isSimpleTemplateLiteral(node)) return checkTemplateElement(node.quasis[0]);
325
+ const isStringRaw = (tag) => {
326
+ return tag.type === "MemberExpression" && tag.object.type === "Identifier" && tag.object.name === "String" && tag.property.type === "Identifier" && tag.property.name === "raw";
327
+ };
328
+ if (node.type === "TaggedTemplateExpression" && isStringRaw(node.tag) && isSimpleTemplateLiteral(node.quasi)) return checkTemplateElement(node.quasi.quasis[0]);
329
+ if (node.type === "TemplateLiteral" && node.expressions.length > 0 && node.quasis.length > 0) {
330
+ node.quasis.forEach((quasi) => {
331
+ checkTemplateElement(quasi);
332
+ });
333
+ return;
334
+ }
335
+ });
336
+ }
337
+ const scriptVisitor = {
338
+ JSXAttribute(node) {
339
+ if (typeof node.name.name === "string" && CLASS_FIELDS.includes(node.name.name.toLowerCase()) && node.value) {
340
+ if (isPossibleLiteral(node.value)) return checkPossibleLiteral(node.value);
341
+ else if (node.value.type === "JSXExpressionContainer" && isPossibleLiteral(node.value.expression)) return checkPossibleLiteral(node.value.expression);
342
+ }
343
+ },
344
+ SvelteAttribute(node) {
345
+ if (node.key.name === "class") {
346
+ if (!node.value.length) return;
347
+ function checkExpressionRecursively(expression) {
348
+ if (expression.type !== "ConditionalExpression") return;
349
+ if (expression.consequent.type === "Literal") checkLiteral(expression.consequent);
350
+ if (expression.alternate) {
351
+ if (expression.alternate.type === "ConditionalExpression") checkExpressionRecursively(expression.alternate);
352
+ else if (expression.alternate.type === "Literal") checkLiteral(expression.alternate);
353
+ }
354
+ }
355
+ node.value.forEach((obj, i) => {
356
+ if (obj.type === "SvelteMustacheTag") checkExpressionRecursively(obj.expression);
357
+ else if (obj.type === "SvelteLiteral") {
358
+ var _node$value, _node$value2;
359
+ checkLiteral(obj, ((_node$value = node.value) === null || _node$value === void 0 || (_node$value = _node$value[i - 1]) === null || _node$value === void 0 ? void 0 : _node$value.type) === "SvelteMustacheTag" ? "before" : ((_node$value2 = node.value) === null || _node$value2 === void 0 || (_node$value2 = _node$value2[i + 1]) === null || _node$value2 === void 0 ? void 0 : _node$value2.type) === "SvelteMustacheTag" ? "after" : void 0);
360
+ }
361
+ });
362
+ }
363
+ },
364
+ CallExpression(node) {
365
+ if (!(node.callee.type === "Identifier" && isUnoFunction(node.callee.name))) return;
366
+ node.arguments.forEach((arg) => {
367
+ if (isPossibleLiteral(arg)) return checkPossibleLiteral(arg);
368
+ if (arg.type === "ConditionalExpression") return checkPossibleLiteral(arg.consequent, arg.alternate);
369
+ if (arg.type === "LogicalExpression") return checkPossibleLiteral(arg.left, arg.right);
370
+ function handleObjectExpression(node$1) {
371
+ node$1.properties.forEach((p) => {
372
+ if (p.type !== "Property") return;
373
+ if (isPossibleLiteral(p.value)) return checkPossibleLiteral(p.value);
374
+ if (p.value.type === "ObjectExpression") return handleObjectExpression(p.value);
375
+ });
376
+ return checkPossibleLiteral(...node$1.properties.filter((p) => p.type === "Property").map((p) => p.key));
377
+ }
378
+ if (arg.type === "ObjectExpression") return handleObjectExpression(arg);
379
+ if (arg.type === "ArrayExpression") return arg.elements.forEach((element) => {
380
+ if (element && isPossibleLiteral(element)) return checkPossibleLiteral(element);
381
+ });
382
+ });
383
+ },
384
+ VariableDeclarator(node) {
385
+ if (node.id.type !== "Identifier" || !node.init || !isUnoVariable(node.id.name)) return;
386
+ if (isPossibleLiteral(node.init)) return checkPossibleLiteral(node.init);
387
+ if (node.init.type === "TSAsExpression" && isPossibleLiteral(node.init.expression)) return checkPossibleLiteral(node.init.expression);
388
+ function handleObjectExpression(node$1) {
389
+ node$1.properties.forEach((p) => {
390
+ if (p.type !== "Property") return;
391
+ if (isPossibleLiteral(p.value)) return checkPossibleLiteral(p.value);
392
+ if (p.value.type === "ObjectExpression") return handleObjectExpression(p.value);
393
+ });
394
+ }
395
+ if (node.init.type === "ObjectExpression") return handleObjectExpression(node.init);
396
+ if (node.init.type === "TSAsExpression" && node.init.expression.type === "ObjectExpression") return handleObjectExpression(node.init.expression);
397
+ }
398
+ };
399
+ const templateBodyVisitor = { VAttribute(node) {
400
+ if (node.key.name === "class") {
401
+ if (node.value.type === "VLiteral") checkLiteral(node.value);
402
+ }
403
+ } };
404
+ const parserServices = (context === null || context === void 0 ? void 0 : context.sourceCode.parserServices) || context.parserServices;
405
+ if (parserServices == null || parserServices.defineTemplateBodyVisitor == null) return scriptVisitor;
406
+ else return parserServices === null || parserServices === void 0 ? void 0 : parserServices.defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor);
407
+ }
532
408
  });
533
409
 
534
- const plugin = {
535
- rules: {
536
- order,
537
- "order-attributify": orderAttributify,
538
- blocklist,
539
- "enforce-class-compile": enforceClassCompile
540
- }
541
- };
410
+ //#endregion
411
+ //#region src/plugin.ts
412
+ const plugin = { rules: {
413
+ order: order_default,
414
+ "order-attributify": order_attributify_default,
415
+ blocklist: blocklist_default,
416
+ "enforce-class-compile": enforce_class_compile_default
417
+ } };
542
418
 
543
- const configsFlat = {
544
- plugins: {
545
- unocss: plugin
546
- },
547
- rules: {
548
- "unocss/order": "warn",
549
- "unocss/order-attributify": "warn"
550
- }
419
+ //#endregion
420
+ //#region src/configs/flat.ts
421
+ var flat_default = {
422
+ plugins: { unocss: plugin },
423
+ rules: {
424
+ "unocss/order": "warn",
425
+ "unocss/order-attributify": "warn"
426
+ }
551
427
  };
552
428
 
553
- const configsRecommended = {
554
- plugins: ["@unocss"],
555
- rules: {
556
- "@unocss/order": "warn",
557
- "@unocss/order-attributify": "warn"
558
- }
429
+ //#endregion
430
+ //#region src/configs/recommended.ts
431
+ var recommended_default = {
432
+ plugins: ["@unocss"],
433
+ rules: {
434
+ "@unocss/order": "warn",
435
+ "@unocss/order-attributify": "warn"
436
+ }
559
437
  };
560
438
 
561
- const index = {
562
- ...plugin,
563
- configs: {
564
- recommended: configsRecommended,
565
- flat: configsFlat
566
- }
439
+ //#endregion
440
+ //#region src/index.ts
441
+ const configs = {
442
+ recommended: recommended_default,
443
+ flat: flat_default
444
+ };
445
+ var src_default = {
446
+ ...plugin,
447
+ configs
567
448
  };
568
449
 
569
- export { index as default };
450
+ //#endregion
451
+ export { configs, src_default as default };