@unocss/eslint-plugin 66.6.6 → 66.6.7
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 +206 -226
- package/dist/index.d.cts +42 -60
- package/dist/index.d.mts +42 -60
- package/dist/index.mjs +196 -217
- package/dist/worker.mjs +5 -8
- package/package.json +7 -8
package/dist/index.mjs
CHANGED
|
@@ -1,23 +1,16 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
|
-
import {
|
|
2
|
+
import { RuleCreator } from "@typescript-eslint/utils/eslint-utils";
|
|
3
3
|
import { createSyncFn } from "synckit";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import MagicString from "magic-string";
|
|
6
6
|
import { AST_TOKEN_TYPES } from "@typescript-eslint/types";
|
|
7
|
-
|
|
8
7
|
//#region src/constants.ts
|
|
9
8
|
const CLASS_FIELDS = ["class", "classname"];
|
|
10
9
|
const AST_NODES_WITH_QUOTES = ["Literal", "VLiteral"];
|
|
11
|
-
|
|
12
|
-
//#endregion
|
|
13
|
-
//#region src/dirs.ts
|
|
14
|
-
const distDir = fileURLToPath(new URL("../dist", import.meta.url));
|
|
15
|
-
|
|
16
10
|
//#endregion
|
|
17
11
|
//#region src/rules/_.ts
|
|
18
|
-
const syncAction = createSyncFn(join(
|
|
19
|
-
const createRule =
|
|
20
|
-
|
|
12
|
+
const syncAction = createSyncFn(join(fileURLToPath(new URL("../dist", import.meta.url)), "worker.mjs"));
|
|
13
|
+
const createRule = RuleCreator(() => "https://unocss.dev/integrations/eslint#rules");
|
|
21
14
|
//#endregion
|
|
22
15
|
//#region src/rules/order-attributify.ts
|
|
23
16
|
const IGNORE_ATTRIBUTES = [
|
|
@@ -33,9 +26,9 @@ var order_attributify_default = createRule({
|
|
|
33
26
|
fixable: "code",
|
|
34
27
|
docs: { description: "Order of UnoCSS attributes" },
|
|
35
28
|
messages: { "invalid-order": "UnoCSS attributes are not ordered" },
|
|
36
|
-
schema: []
|
|
29
|
+
schema: [],
|
|
30
|
+
defaultOptions: []
|
|
37
31
|
},
|
|
38
|
-
defaultOptions: [],
|
|
39
32
|
create(context) {
|
|
40
33
|
const scriptVisitor = {};
|
|
41
34
|
const templateBodyVisitor = { VStartTag(node) {
|
|
@@ -65,7 +58,6 @@ var order_attributify_default = createRule({
|
|
|
65
58
|
else return parserServices === null || parserServices === void 0 ? void 0 : parserServices.defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor);
|
|
66
59
|
}
|
|
67
60
|
});
|
|
68
|
-
|
|
69
61
|
//#endregion
|
|
70
62
|
//#region src/rules/blocklist.ts
|
|
71
63
|
var blocklist_default = createRule({
|
|
@@ -75,9 +67,9 @@ var blocklist_default = createRule({
|
|
|
75
67
|
fixable: "code",
|
|
76
68
|
docs: { description: "Utilities in UnoCSS blocklist" },
|
|
77
69
|
messages: { "in-blocklist": "\"{{name}}\" is in blocklist{{reason}}" },
|
|
78
|
-
schema: []
|
|
70
|
+
schema: [],
|
|
71
|
+
defaultOptions: []
|
|
79
72
|
},
|
|
80
|
-
defaultOptions: [],
|
|
81
73
|
create(context) {
|
|
82
74
|
const checkLiteral = (node) => {
|
|
83
75
|
var _context$settings$uno;
|
|
@@ -119,12 +111,12 @@ var blocklist_default = createRule({
|
|
|
119
111
|
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;
|
|
120
112
|
});
|
|
121
113
|
if (!valueless.length) return;
|
|
122
|
-
for (const node
|
|
114
|
+
for (const node of valueless) {
|
|
123
115
|
var _node$key, _context$settings$uno2;
|
|
124
|
-
if (!(node
|
|
125
|
-
syncAction((_context$settings$uno2 = context.settings.unocss) === null || _context$settings$uno2 === void 0 ? void 0 : _context$settings$uno2.configPath, "blocklist", node
|
|
116
|
+
if (!(node === null || node === void 0 || (_node$key = node.key) === null || _node$key === void 0 ? void 0 : _node$key.name)) continue;
|
|
117
|
+
syncAction((_context$settings$uno2 = context.settings.unocss) === null || _context$settings$uno2 === void 0 ? void 0 : _context$settings$uno2.configPath, "blocklist", node.key.name, context.filename).forEach(([name, meta]) => {
|
|
126
118
|
context.report({
|
|
127
|
-
node
|
|
119
|
+
node,
|
|
128
120
|
messageId: "in-blocklist",
|
|
129
121
|
data: {
|
|
130
122
|
name,
|
|
@@ -140,7 +132,6 @@ var blocklist_default = createRule({
|
|
|
140
132
|
else return parserServices === null || parserServices === void 0 ? void 0 : parserServices.defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor);
|
|
141
133
|
}
|
|
142
134
|
});
|
|
143
|
-
|
|
144
135
|
//#endregion
|
|
145
136
|
//#region src/rules/enforce-class-compile.ts
|
|
146
137
|
var enforce_class_compile_default = createRule({
|
|
@@ -157,12 +148,12 @@ var enforce_class_compile_default = createRule({
|
|
|
157
148
|
enableFix: { type: "boolean" }
|
|
158
149
|
},
|
|
159
150
|
additionalProperties: false
|
|
151
|
+
}],
|
|
152
|
+
defaultOptions: [{
|
|
153
|
+
prefix: ":uno:",
|
|
154
|
+
enableFix: true
|
|
160
155
|
}]
|
|
161
156
|
},
|
|
162
|
-
defaultOptions: [{
|
|
163
|
-
prefix: ":uno:",
|
|
164
|
-
enableFix: true
|
|
165
|
-
}],
|
|
166
157
|
create(context, [mergedOptions]) {
|
|
167
158
|
const CLASS_COMPILE_PREFIX = `${mergedOptions.prefix} `;
|
|
168
159
|
const ENABLE_FIX = mergedOptions.enableFix;
|
|
@@ -221,234 +212,222 @@ var enforce_class_compile_default = createRule({
|
|
|
221
212
|
else return parserServices === null || parserServices === void 0 ? void 0 : parserServices.defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor);
|
|
222
213
|
}
|
|
223
214
|
});
|
|
224
|
-
|
|
225
215
|
//#endregion
|
|
226
|
-
//#region src/
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
216
|
+
//#region src/plugin.ts
|
|
217
|
+
const plugin = { rules: {
|
|
218
|
+
order: createRule({
|
|
219
|
+
name: "order",
|
|
220
|
+
meta: {
|
|
221
|
+
type: "layout",
|
|
222
|
+
fixable: "code",
|
|
223
|
+
docs: { description: "Order of UnoCSS utilities in class attribute" },
|
|
224
|
+
messages: { "invalid-order": "UnoCSS utilities are not ordered" },
|
|
225
|
+
schema: [{
|
|
226
|
+
type: "object",
|
|
227
|
+
properties: {
|
|
228
|
+
unoFunctions: {
|
|
229
|
+
type: "array",
|
|
230
|
+
items: { type: "string" }
|
|
231
|
+
},
|
|
232
|
+
unoVariables: {
|
|
233
|
+
type: "array",
|
|
234
|
+
items: { type: "string" }
|
|
235
|
+
}
|
|
240
236
|
},
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
237
|
+
additionalProperties: false
|
|
238
|
+
}],
|
|
239
|
+
defaultOptions: [{
|
|
240
|
+
unoFunctions: ["clsx", "classnames"],
|
|
241
|
+
unoVariables: ["^cls", "classNames?$"]
|
|
242
|
+
}]
|
|
243
|
+
},
|
|
244
|
+
create(context) {
|
|
245
|
+
let { unoFunctions = ["clsx", "classnames"], unoVariables = ["^cls", "classNames?$"] } = context.options[0] || {};
|
|
246
|
+
unoFunctions = unoFunctions.map((name) => name.toLowerCase());
|
|
247
|
+
function isUnoFunction(name) {
|
|
248
|
+
return unoFunctions.includes(name.toLowerCase());
|
|
249
|
+
}
|
|
250
|
+
const unoVariablesRegexes = unoVariables.map((regex) => new RegExp(regex, "i"));
|
|
251
|
+
function isUnoVariable(name) {
|
|
252
|
+
return unoVariablesRegexes.some((reg) => reg.test(name));
|
|
253
|
+
}
|
|
254
|
+
function checkLiteral(node, addSpace) {
|
|
255
|
+
var _context$settings$uno;
|
|
256
|
+
if (typeof node.value !== "string" || !node.value.trim()) return;
|
|
257
|
+
const input = node.value;
|
|
258
|
+
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();
|
|
259
|
+
if (addSpace === "before") sorted = ` ${sorted}`;
|
|
260
|
+
else if (addSpace === "after") sorted += " ";
|
|
261
|
+
if (sorted !== input) {
|
|
262
|
+
const nodeOrToken = node.type === "SvelteLiteral" ? {
|
|
263
|
+
type: AST_TOKEN_TYPES.String,
|
|
264
|
+
value: node.value,
|
|
265
|
+
loc: node.loc,
|
|
266
|
+
range: node.range
|
|
267
|
+
} : node;
|
|
268
|
+
context.report({
|
|
269
|
+
node: nodeOrToken,
|
|
270
|
+
loc: node.loc,
|
|
271
|
+
messageId: "invalid-order",
|
|
272
|
+
fix(fixer) {
|
|
273
|
+
if (AST_NODES_WITH_QUOTES.includes(node.type)) return fixer.replaceTextRange([node.range[0] + 1, node.range[1] - 1], sorted);
|
|
274
|
+
else return fixer.replaceText(nodeOrToken, sorted);
|
|
275
|
+
}
|
|
276
|
+
});
|
|
244
277
|
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
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();
|
|
268
|
-
if (addSpace === "before") sorted = ` ${sorted}`;
|
|
269
|
-
else if (addSpace === "after") sorted += " ";
|
|
270
|
-
if (sorted !== input) {
|
|
271
|
-
const nodeOrToken = node.type === "SvelteLiteral" ? {
|
|
272
|
-
type: AST_TOKEN_TYPES.String,
|
|
273
|
-
value: node.value,
|
|
274
|
-
loc: node.loc,
|
|
275
|
-
range: node.range
|
|
276
|
-
} : node;
|
|
277
|
-
context.report({
|
|
278
|
-
node: nodeOrToken,
|
|
279
|
-
loc: node.loc,
|
|
278
|
+
}
|
|
279
|
+
function checkTemplateElement(quasi) {
|
|
280
|
+
var _context$settings$uno2;
|
|
281
|
+
const input = quasi.value.raw;
|
|
282
|
+
if (!input) return;
|
|
283
|
+
const getRange = () => {
|
|
284
|
+
const text = context.sourceCode.getText(quasi);
|
|
285
|
+
const raw = quasi.value.raw;
|
|
286
|
+
if (!text.includes(raw)) return;
|
|
287
|
+
const rawStart = text.indexOf(raw);
|
|
288
|
+
const start = quasi.range[0] + rawStart;
|
|
289
|
+
const end = quasi.range[0] + rawStart + raw.length;
|
|
290
|
+
if (start < quasi.range[0] || end > quasi.range[1]) return;
|
|
291
|
+
return [start, end];
|
|
292
|
+
};
|
|
293
|
+
if (!getRange()) return;
|
|
294
|
+
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();
|
|
295
|
+
if (/^\s/.test(input)) sorted = ` ${sorted}`;
|
|
296
|
+
if (/\s$/.test(input)) sorted += " ";
|
|
297
|
+
if (sorted !== input) context.report({
|
|
298
|
+
node: quasi,
|
|
299
|
+
loc: quasi.loc,
|
|
280
300
|
messageId: "invalid-order",
|
|
281
301
|
fix(fixer) {
|
|
282
|
-
|
|
283
|
-
|
|
302
|
+
const realRange = getRange();
|
|
303
|
+
if (!realRange) return null;
|
|
304
|
+
return fixer.replaceTextRange(realRange, sorted);
|
|
284
305
|
}
|
|
285
306
|
});
|
|
286
307
|
}
|
|
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
|
-
if (
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
if (node.type === "TemplateLiteral" && isSimpleTemplateLiteral(node)) return checkTemplateElement(node.quasis[0]);
|
|
328
|
-
const isStringRaw = (tag) => {
|
|
329
|
-
return tag.type === "MemberExpression" && tag.object.type === "Identifier" && tag.object.name === "String" && tag.property.type === "Identifier" && tag.property.name === "raw";
|
|
330
|
-
};
|
|
331
|
-
if (node.type === "TaggedTemplateExpression" && isStringRaw(node.tag) && isSimpleTemplateLiteral(node.quasi)) return checkTemplateElement(node.quasi.quasis[0]);
|
|
332
|
-
if (node.type === "TemplateLiteral" && node.expressions.length > 0 && node.quasis.length > 0) {
|
|
333
|
-
node.quasis.forEach((quasi) => {
|
|
334
|
-
checkTemplateElement(quasi);
|
|
335
|
-
});
|
|
336
|
-
return;
|
|
337
|
-
}
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
const scriptVisitor = {
|
|
341
|
-
JSXAttribute(node) {
|
|
342
|
-
if (typeof node.name.name === "string" && CLASS_FIELDS.includes(node.name.name.toLowerCase()) && node.value) {
|
|
343
|
-
if (isPossibleLiteral(node.value)) return checkPossibleLiteral(node.value);
|
|
344
|
-
else if (node.value.type === "JSXExpressionContainer" && isPossibleLiteral(node.value.expression)) return checkPossibleLiteral(node.value.expression);
|
|
345
|
-
}
|
|
346
|
-
},
|
|
347
|
-
SvelteAttribute(node) {
|
|
348
|
-
if (node.key.name === "class") {
|
|
349
|
-
if (!node.value.length) return;
|
|
350
|
-
function checkExpressionRecursively(expression) {
|
|
351
|
-
if (expression.type !== "ConditionalExpression") return;
|
|
352
|
-
if (expression.consequent.type === "Literal") checkLiteral(expression.consequent);
|
|
353
|
-
if (expression.alternate) {
|
|
354
|
-
if (expression.alternate.type === "ConditionalExpression") checkExpressionRecursively(expression.alternate);
|
|
355
|
-
else if (expression.alternate.type === "Literal") checkLiteral(expression.alternate);
|
|
308
|
+
function isPossibleLiteral(node) {
|
|
309
|
+
return node.type === "Literal" || node.type === "TemplateLiteral" || node.type === "TaggedTemplateExpression";
|
|
310
|
+
}
|
|
311
|
+
function checkPossibleLiteral(...nodes) {
|
|
312
|
+
nodes.forEach((node) => {
|
|
313
|
+
if (!isPossibleLiteral(node)) return;
|
|
314
|
+
if (node.type === "Literal" && typeof node.value === "string") return checkLiteral(node);
|
|
315
|
+
const isSimpleTemplateLiteral = (node) => {
|
|
316
|
+
return node.expressions.length === 0 && node.quasis.length === 1;
|
|
317
|
+
};
|
|
318
|
+
if (node.type === "TemplateLiteral" && isSimpleTemplateLiteral(node)) return checkTemplateElement(node.quasis[0]);
|
|
319
|
+
const isStringRaw = (tag) => {
|
|
320
|
+
return tag.type === "MemberExpression" && tag.object.type === "Identifier" && tag.object.name === "String" && tag.property.type === "Identifier" && tag.property.name === "raw";
|
|
321
|
+
};
|
|
322
|
+
if (node.type === "TaggedTemplateExpression" && isStringRaw(node.tag) && isSimpleTemplateLiteral(node.quasi)) return checkTemplateElement(node.quasi.quasis[0]);
|
|
323
|
+
if (node.type === "TemplateLiteral" && node.expressions.length > 0 && node.quasis.length > 0) {
|
|
324
|
+
node.quasis.forEach((quasi) => {
|
|
325
|
+
checkTemplateElement(quasi);
|
|
326
|
+
});
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
const scriptVisitor = {
|
|
332
|
+
JSXAttribute(node) {
|
|
333
|
+
if (typeof node.name.name === "string" && CLASS_FIELDS.includes(node.name.name.toLowerCase()) && node.value) {
|
|
334
|
+
if (isPossibleLiteral(node.value)) return checkPossibleLiteral(node.value);
|
|
335
|
+
else if (node.value.type === "JSXExpressionContainer" && isPossibleLiteral(node.value.expression)) return checkPossibleLiteral(node.value.expression);
|
|
336
|
+
}
|
|
337
|
+
},
|
|
338
|
+
SvelteAttribute(node) {
|
|
339
|
+
if (node.key.name === "class") {
|
|
340
|
+
if (!node.value.length) return;
|
|
341
|
+
function checkExpressionRecursively(expression) {
|
|
342
|
+
if (expression.type !== "ConditionalExpression") return;
|
|
343
|
+
if (expression.consequent.type === "Literal") checkLiteral(expression.consequent);
|
|
344
|
+
if (expression.alternate) {
|
|
345
|
+
if (expression.alternate.type === "ConditionalExpression") checkExpressionRecursively(expression.alternate);
|
|
346
|
+
else if (expression.alternate.type === "Literal") checkLiteral(expression.alternate);
|
|
347
|
+
}
|
|
356
348
|
}
|
|
349
|
+
node.value.forEach((obj, i) => {
|
|
350
|
+
if (obj.type === "SvelteMustacheTag") checkExpressionRecursively(obj.expression);
|
|
351
|
+
else if (obj.type === "SvelteLiteral") {
|
|
352
|
+
var _node$value, _node$value2;
|
|
353
|
+
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);
|
|
354
|
+
}
|
|
355
|
+
});
|
|
357
356
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
357
|
+
},
|
|
358
|
+
CallExpression(node) {
|
|
359
|
+
if (!(node.callee.type === "Identifier" && isUnoFunction(node.callee.name))) return;
|
|
360
|
+
node.arguments.forEach((arg) => {
|
|
361
|
+
if (isPossibleLiteral(arg)) return checkPossibleLiteral(arg);
|
|
362
|
+
if (arg.type === "ConditionalExpression") return checkPossibleLiteral(arg.consequent, arg.alternate);
|
|
363
|
+
if (arg.type === "LogicalExpression") return checkPossibleLiteral(arg.left, arg.right);
|
|
364
|
+
function handleObjectExpression(node) {
|
|
365
|
+
node.properties.forEach((p) => {
|
|
366
|
+
if (p.type !== "Property") return;
|
|
367
|
+
if (isPossibleLiteral(p.value)) return checkPossibleLiteral(p.value);
|
|
368
|
+
if (p.value.type === "ObjectExpression") return handleObjectExpression(p.value);
|
|
369
|
+
});
|
|
370
|
+
return checkPossibleLiteral(...node.properties.filter((p) => p.type === "Property").map((p) => p.key));
|
|
363
371
|
}
|
|
372
|
+
if (arg.type === "ObjectExpression") return handleObjectExpression(arg);
|
|
373
|
+
if (arg.type === "ArrayExpression") return arg.elements.forEach((element) => {
|
|
374
|
+
if (element && isPossibleLiteral(element)) return checkPossibleLiteral(element);
|
|
375
|
+
});
|
|
364
376
|
});
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
if (arg.type === "LogicalExpression") return checkPossibleLiteral(arg.left, arg.right);
|
|
373
|
-
function handleObjectExpression(node$1) {
|
|
374
|
-
node$1.properties.forEach((p) => {
|
|
377
|
+
},
|
|
378
|
+
VariableDeclarator(node) {
|
|
379
|
+
if (node.id.type !== "Identifier" || !node.init || !isUnoVariable(node.id.name)) return;
|
|
380
|
+
if (isPossibleLiteral(node.init)) return checkPossibleLiteral(node.init);
|
|
381
|
+
if (node.init.type === "TSAsExpression" && isPossibleLiteral(node.init.expression)) return checkPossibleLiteral(node.init.expression);
|
|
382
|
+
function handleObjectExpression(node) {
|
|
383
|
+
node.properties.forEach((p) => {
|
|
375
384
|
if (p.type !== "Property") return;
|
|
376
385
|
if (isPossibleLiteral(p.value)) return checkPossibleLiteral(p.value);
|
|
377
386
|
if (p.value.type === "ObjectExpression") return handleObjectExpression(p.value);
|
|
378
387
|
});
|
|
379
|
-
return checkPossibleLiteral(...node$1.properties.filter((p) => p.type === "Property").map((p) => p.key));
|
|
380
388
|
}
|
|
381
|
-
if (
|
|
382
|
-
if (
|
|
383
|
-
if (element && isPossibleLiteral(element)) return checkPossibleLiteral(element);
|
|
384
|
-
});
|
|
385
|
-
});
|
|
386
|
-
},
|
|
387
|
-
VariableDeclarator(node) {
|
|
388
|
-
if (node.id.type !== "Identifier" || !node.init || !isUnoVariable(node.id.name)) return;
|
|
389
|
-
if (isPossibleLiteral(node.init)) return checkPossibleLiteral(node.init);
|
|
390
|
-
if (node.init.type === "TSAsExpression" && isPossibleLiteral(node.init.expression)) return checkPossibleLiteral(node.init.expression);
|
|
391
|
-
function handleObjectExpression(node$1) {
|
|
392
|
-
node$1.properties.forEach((p) => {
|
|
393
|
-
if (p.type !== "Property") return;
|
|
394
|
-
if (isPossibleLiteral(p.value)) return checkPossibleLiteral(p.value);
|
|
395
|
-
if (p.value.type === "ObjectExpression") return handleObjectExpression(p.value);
|
|
396
|
-
});
|
|
389
|
+
if (node.init.type === "ObjectExpression") return handleObjectExpression(node.init);
|
|
390
|
+
if (node.init.type === "TSAsExpression" && node.init.expression.type === "ObjectExpression") return handleObjectExpression(node.init.expression);
|
|
397
391
|
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
else return parserServices === null || parserServices === void 0 ? void 0 : parserServices.defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor);
|
|
410
|
-
}
|
|
411
|
-
});
|
|
412
|
-
|
|
413
|
-
//#endregion
|
|
414
|
-
//#region src/plugin.ts
|
|
415
|
-
const plugin = { rules: {
|
|
416
|
-
order: order_default,
|
|
392
|
+
};
|
|
393
|
+
const templateBodyVisitor = { VAttribute(node) {
|
|
394
|
+
if (node.key.name === "class") {
|
|
395
|
+
if (node.value.type === "VLiteral") checkLiteral(node.value);
|
|
396
|
+
}
|
|
397
|
+
} };
|
|
398
|
+
const parserServices = (context === null || context === void 0 ? void 0 : context.sourceCode.parserServices) || context.parserServices;
|
|
399
|
+
if (parserServices == null || parserServices.defineTemplateBodyVisitor == null) return scriptVisitor;
|
|
400
|
+
else return parserServices === null || parserServices === void 0 ? void 0 : parserServices.defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor);
|
|
401
|
+
}
|
|
402
|
+
}),
|
|
417
403
|
"order-attributify": order_attributify_default,
|
|
418
404
|
blocklist: blocklist_default,
|
|
419
405
|
"enforce-class-compile": enforce_class_compile_default
|
|
420
406
|
} };
|
|
421
|
-
|
|
422
407
|
//#endregion
|
|
423
408
|
//#region src/configs/flat.ts
|
|
424
|
-
|
|
409
|
+
const flatConfig = {
|
|
425
410
|
plugins: { unocss: plugin },
|
|
426
411
|
rules: {
|
|
427
412
|
"unocss/order": "warn",
|
|
428
413
|
"unocss/order-attributify": "warn"
|
|
429
414
|
}
|
|
430
415
|
};
|
|
431
|
-
|
|
432
|
-
//#endregion
|
|
433
|
-
//#region src/configs/recommended.ts
|
|
434
|
-
var recommended_default = {
|
|
435
|
-
plugins: ["@unocss"],
|
|
436
|
-
rules: {
|
|
437
|
-
"@unocss/order": "warn",
|
|
438
|
-
"@unocss/order-attributify": "warn"
|
|
439
|
-
}
|
|
440
|
-
};
|
|
441
|
-
|
|
442
416
|
//#endregion
|
|
443
417
|
//#region src/index.ts
|
|
444
418
|
const configs = {
|
|
445
|
-
recommended:
|
|
446
|
-
|
|
419
|
+
recommended: {
|
|
420
|
+
plugins: ["@unocss"],
|
|
421
|
+
rules: {
|
|
422
|
+
"@unocss/order": "warn",
|
|
423
|
+
"@unocss/order-attributify": "warn"
|
|
424
|
+
}
|
|
425
|
+
},
|
|
426
|
+
flat: flatConfig
|
|
447
427
|
};
|
|
448
|
-
|
|
428
|
+
const eslintPlugin = {
|
|
449
429
|
...plugin,
|
|
450
430
|
configs
|
|
451
431
|
};
|
|
452
|
-
|
|
453
432
|
//#endregion
|
|
454
|
-
export { configs,
|
|
433
|
+
export { configs, eslintPlugin as default };
|
package/dist/worker.mjs
CHANGED
|
@@ -3,7 +3,6 @@ import process from "node:process";
|
|
|
3
3
|
import { collapseVariantGroup, createGenerator, notNull, parseVariantGroup } from "@unocss/core";
|
|
4
4
|
import { loadConfig } from "@unocss/config";
|
|
5
5
|
import { runAsWorker } from "synckit";
|
|
6
|
-
|
|
7
6
|
//#region ../../virtual-shared/integration/src/sort-rules.ts
|
|
8
7
|
async function sortRules(rules, uno) {
|
|
9
8
|
const unknown = [];
|
|
@@ -26,14 +25,13 @@ async function sortRules(rules, uno) {
|
|
|
26
25
|
result.push([order, i]);
|
|
27
26
|
}
|
|
28
27
|
let sorted = result.filter(notNull).sort((a, b) => {
|
|
29
|
-
let result
|
|
30
|
-
if (result
|
|
31
|
-
return result
|
|
28
|
+
let result = a[0] - b[0];
|
|
29
|
+
if (result === 0) result = a[1].localeCompare(b[1]);
|
|
30
|
+
return result;
|
|
32
31
|
}).map((i) => i[1]).join(" ");
|
|
33
32
|
if (expandedResult === null || expandedResult === void 0 ? void 0 : expandedResult.prefixes.length) sorted = collapseVariantGroup(sorted, expandedResult.prefixes);
|
|
34
33
|
return [...unknown, sorted].join(" ").trim();
|
|
35
34
|
}
|
|
36
|
-
|
|
37
35
|
//#endregion
|
|
38
36
|
//#region src/worker.ts
|
|
39
37
|
var _process$env;
|
|
@@ -92,7 +90,7 @@ async function actionBlocklist(configPath, classes, id) {
|
|
|
92
90
|
let current = raw;
|
|
93
91
|
for (const p of uno.config.preprocess) current = p(raw);
|
|
94
92
|
const rules = (await uno.matchVariants(raw, current)).map((r) => r && uno.getBlocked(r[1]));
|
|
95
|
-
for (const rule
|
|
93
|
+
for (const rule of rules) if (rule) blocked.set(raw, getMeta(raw, rule[1]));
|
|
96
94
|
};
|
|
97
95
|
await Promise.all(values.map(matchBlocked));
|
|
98
96
|
return [...blocked];
|
|
@@ -107,6 +105,5 @@ function run(configPath, action, ...args) {
|
|
|
107
105
|
return runAsync(configPath, action, ...args);
|
|
108
106
|
}
|
|
109
107
|
runAsWorker(run);
|
|
110
|
-
|
|
111
108
|
//#endregion
|
|
112
|
-
export { getGenerator, run, runAsync, setGenerator };
|
|
109
|
+
export { getGenerator, run, runAsync, setGenerator };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/eslint-plugin",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "66.6.
|
|
4
|
+
"version": "66.6.7",
|
|
5
5
|
"description": "ESLint plugin for UnoCSS",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"sideEffects": false,
|
|
23
23
|
"exports": {
|
|
24
24
|
".": {
|
|
25
|
-
"
|
|
26
|
-
"
|
|
25
|
+
"import": "./dist/index.mjs",
|
|
26
|
+
"require": "./dist/index.cjs"
|
|
27
27
|
},
|
|
28
28
|
"./worker": "./dist/worker.mjs",
|
|
29
29
|
"./package.json": "./package.json"
|
|
@@ -49,15 +49,14 @@
|
|
|
49
49
|
"@typescript-eslint/utils": "^8.56.1",
|
|
50
50
|
"magic-string": "^0.30.21",
|
|
51
51
|
"synckit": "^0.11.12",
|
|
52
|
-
"@unocss/config": "66.6.
|
|
53
|
-
"@unocss/core": "66.6.
|
|
54
|
-
"@unocss/rule-utils": "66.6.
|
|
52
|
+
"@unocss/config": "66.6.7",
|
|
53
|
+
"@unocss/core": "66.6.7",
|
|
54
|
+
"@unocss/rule-utils": "66.6.7"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@typescript/native-preview": "latest",
|
|
58
58
|
"svelte-eslint-parser": "^1.5.1",
|
|
59
|
-
"vue-eslint-parser": "^10.4.0"
|
|
60
|
-
"@unocss/eslint-plugin": "66.6.6"
|
|
59
|
+
"vue-eslint-parser": "^10.4.0"
|
|
61
60
|
},
|
|
62
61
|
"scripts": {
|
|
63
62
|
"build": "tsdown --config-loader unrun",
|