@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/dirs-DMLliOn8.cjs +13 -0
- package/dist/dirs-DTjbV7PE.mjs +7 -0
- package/dist/dirs.cjs +2 -7
- package/dist/dirs.d.cts +3 -2
- package/dist/dirs.d.mts +3 -2
- package/dist/dirs.mjs +2 -4
- package/dist/index.cjs +461 -554
- package/dist/index.d.cts +64 -37
- package/dist/index.d.mts +64 -37
- package/dist/index.mjs +430 -548
- package/dist/worker.d.mts +957 -0
- package/dist/worker.mjs +87 -105
- package/package.json +18 -12
- package/dist/dirs.d.ts +0 -3
- package/dist/index.d.ts +0 -45
package/dist/index.mjs
CHANGED
|
@@ -1,569 +1,451 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import MagicString from
|
|
6
|
-
import { AST_TOKEN_TYPES } from
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
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
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
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
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
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
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
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
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
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
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
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
|
-
|
|
450
|
+
//#endregion
|
|
451
|
+
export { configs, src_default as default };
|