@unocss/eslint-plugin 66.5.10-beta.1 → 66.5.11

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