@unocss/eslint-plugin 66.3.3 → 66.4.0
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 +156 -6
- package/dist/index.mjs +156 -6
- package/dist/worker.mjs +9 -4
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -276,10 +276,39 @@ const order = createRule({
|
|
|
276
276
|
messages: {
|
|
277
277
|
"invalid-order": "UnoCSS utilities are not ordered"
|
|
278
278
|
},
|
|
279
|
-
schema: [
|
|
279
|
+
schema: [
|
|
280
|
+
{
|
|
281
|
+
type: "object",
|
|
282
|
+
properties: {
|
|
283
|
+
unoFunctions: {
|
|
284
|
+
type: "array",
|
|
285
|
+
items: { type: "string" }
|
|
286
|
+
},
|
|
287
|
+
unoVariables: {
|
|
288
|
+
type: "array",
|
|
289
|
+
items: { type: "string" }
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
]
|
|
280
294
|
},
|
|
281
|
-
defaultOptions: [
|
|
295
|
+
defaultOptions: [
|
|
296
|
+
{
|
|
297
|
+
unoFunctions: ["clsx", "classnames"],
|
|
298
|
+
unoVariables: ["^cls", "classNames?$"]
|
|
299
|
+
// for example `clsButton = ''` or `buttonClassNames = {}`
|
|
300
|
+
}
|
|
301
|
+
],
|
|
282
302
|
create(context) {
|
|
303
|
+
let { unoFunctions = ["clsx", "classnames"], unoVariables = ["^cls", "classNames?$"] } = context.options[0] || {};
|
|
304
|
+
unoFunctions = unoFunctions.map((name) => name.toLowerCase());
|
|
305
|
+
function isUnoFunction(name) {
|
|
306
|
+
return unoFunctions.includes(name.toLowerCase());
|
|
307
|
+
}
|
|
308
|
+
const unoVariablesRegexes = unoVariables.map((regex) => new RegExp(regex, "i"));
|
|
309
|
+
function isUnoVariable(name) {
|
|
310
|
+
return unoVariablesRegexes.some((reg) => reg.test(name));
|
|
311
|
+
}
|
|
283
312
|
function checkLiteral(node, addSpace) {
|
|
284
313
|
if (typeof node.value !== "string" || !node.value.trim())
|
|
285
314
|
return;
|
|
@@ -308,13 +337,84 @@ const order = createRule({
|
|
|
308
337
|
});
|
|
309
338
|
}
|
|
310
339
|
}
|
|
340
|
+
function checkTemplateElement(quasi) {
|
|
341
|
+
const input = quasi.value.raw;
|
|
342
|
+
if (!input)
|
|
343
|
+
return;
|
|
344
|
+
const getRange = () => {
|
|
345
|
+
const text = context.sourceCode.getText(quasi);
|
|
346
|
+
const raw = quasi.value.raw;
|
|
347
|
+
if (!text.includes(raw))
|
|
348
|
+
return;
|
|
349
|
+
const rawStart = text.indexOf(raw);
|
|
350
|
+
const start = quasi.range[0] + rawStart;
|
|
351
|
+
const end = quasi.range[0] + rawStart + raw.length;
|
|
352
|
+
if (start < quasi.range[0] || end > quasi.range[1])
|
|
353
|
+
return;
|
|
354
|
+
return [start, end];
|
|
355
|
+
};
|
|
356
|
+
const realRange = getRange();
|
|
357
|
+
if (!realRange)
|
|
358
|
+
return;
|
|
359
|
+
let sorted = syncAction(
|
|
360
|
+
context.settings.unocss?.configPath,
|
|
361
|
+
"sort",
|
|
362
|
+
input
|
|
363
|
+
).trim();
|
|
364
|
+
if (/^\s/.test(input))
|
|
365
|
+
sorted = ` ${sorted}`;
|
|
366
|
+
if (/\s$/.test(input))
|
|
367
|
+
sorted += " ";
|
|
368
|
+
if (sorted !== input) {
|
|
369
|
+
context.report({
|
|
370
|
+
node: quasi,
|
|
371
|
+
loc: quasi.loc,
|
|
372
|
+
messageId: "invalid-order",
|
|
373
|
+
fix(fixer) {
|
|
374
|
+
const realRange2 = getRange();
|
|
375
|
+
if (!realRange2)
|
|
376
|
+
return null;
|
|
377
|
+
return fixer.replaceTextRange(realRange2, sorted);
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
function isPossibleLiteral(node) {
|
|
383
|
+
return node.type === "Literal" || node.type === "TemplateLiteral" || node.type === "TaggedTemplateExpression";
|
|
384
|
+
}
|
|
385
|
+
function checkPossibleLiteral(...nodes) {
|
|
386
|
+
nodes.forEach((node) => {
|
|
387
|
+
if (!isPossibleLiteral(node))
|
|
388
|
+
return;
|
|
389
|
+
if (node.type === "Literal" && typeof node.value === "string") {
|
|
390
|
+
return checkLiteral(node);
|
|
391
|
+
}
|
|
392
|
+
const isSimpleTemplateLiteral = (node2) => {
|
|
393
|
+
return node2.expressions.length === 0 && node2.quasis.length === 1;
|
|
394
|
+
};
|
|
395
|
+
if (node.type === "TemplateLiteral" && isSimpleTemplateLiteral(node)) {
|
|
396
|
+
return checkTemplateElement(node.quasis[0]);
|
|
397
|
+
}
|
|
398
|
+
const isStringRaw = (tag) => {
|
|
399
|
+
return tag.type === "MemberExpression" && tag.object.type === "Identifier" && tag.object.name === "String" && tag.property.type === "Identifier" && tag.property.name === "raw";
|
|
400
|
+
};
|
|
401
|
+
if (node.type === "TaggedTemplateExpression" && isStringRaw(node.tag) && isSimpleTemplateLiteral(node.quasi)) {
|
|
402
|
+
return checkTemplateElement(node.quasi.quasis[0]);
|
|
403
|
+
}
|
|
404
|
+
if (node.type === "TemplateLiteral" && node.expressions.length > 0 && node.quasis.length > 0) {
|
|
405
|
+
return void node.quasis.forEach((quasi) => {
|
|
406
|
+
checkTemplateElement(quasi);
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
}
|
|
311
411
|
const scriptVisitor = {
|
|
312
412
|
JSXAttribute(node) {
|
|
313
413
|
if (typeof node.name.name === "string" && CLASS_FIELDS.includes(node.name.name.toLowerCase()) && node.value) {
|
|
314
|
-
if (node.value
|
|
315
|
-
|
|
316
|
-
else if (node.value.type === "JSXExpressionContainer" && node.value.expression
|
|
317
|
-
|
|
414
|
+
if (isPossibleLiteral(node.value))
|
|
415
|
+
return checkPossibleLiteral(node.value);
|
|
416
|
+
else if (node.value.type === "JSXExpressionContainer" && isPossibleLiteral(node.value.expression))
|
|
417
|
+
return checkPossibleLiteral(node.value.expression);
|
|
318
418
|
}
|
|
319
419
|
},
|
|
320
420
|
SvelteAttribute(node) {
|
|
@@ -344,6 +444,56 @@ const order = createRule({
|
|
|
344
444
|
}
|
|
345
445
|
});
|
|
346
446
|
}
|
|
447
|
+
},
|
|
448
|
+
// for Future node types
|
|
449
|
+
// 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
|
|
450
|
+
CallExpression(node) {
|
|
451
|
+
if (!(node.callee.type === "Identifier" && isUnoFunction(node.callee.name)))
|
|
452
|
+
return;
|
|
453
|
+
node.arguments.forEach((arg) => {
|
|
454
|
+
if (isPossibleLiteral(arg)) {
|
|
455
|
+
return checkPossibleLiteral(arg);
|
|
456
|
+
}
|
|
457
|
+
if (arg.type === "ConditionalExpression") {
|
|
458
|
+
return checkPossibleLiteral(arg.consequent, arg.alternate);
|
|
459
|
+
}
|
|
460
|
+
if (arg.type === "LogicalExpression") {
|
|
461
|
+
return checkPossibleLiteral(arg.left, arg.right);
|
|
462
|
+
}
|
|
463
|
+
if (arg.type === "ObjectExpression") {
|
|
464
|
+
const keys = arg.properties.filter((p) => p.type === "Property").map((p) => p.key);
|
|
465
|
+
return checkPossibleLiteral(...keys);
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
},
|
|
469
|
+
// https://typescript-eslint.io/play/#ts=5.8.2&showAST=es&fileType=.tsx&code=MYewdgzgLgBApgDygJwIYGEA2qIQHKoC2cMAvDAOQBeAtAIwAMDFAUCwPTswBuqyAlqgBGmEgBM4wbGij9wLUJFhSIAIQCuUKODKVCyeq0XQYKjVvAAmXQAN99GABIA3ohQZsuAsQC%2BNheAmZpraYADMtvZ0Tq5IaFg4%2BERwfjA4poFQbJwwIEIAVpKwElJ8qLLyxrBCUGAJXskQus4sMDASAGao6phQAFx6mDSWAA4IFAA0rTAA7vxQABYAonGoAzYdoggw83CEEDTAcGBQcMgwQgDmNDMLuzCnSDQiqMAA1jFu8Z5JvjZTbQQAxabTaAE8BhRCENRuNpj4WAiOFx0lV2pJpOU5GAAkoLrV6r84BBrOQQeiuj1%2BoNhmNJtMgTByeDIdDaXC2gifGkmlUgA&eslintrc=N4KABGBEBOCuA2BTAzpAXGYBfEWg&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false
|
|
470
|
+
VariableDeclarator(node) {
|
|
471
|
+
if (node.id.type !== "Identifier" || !node.init || !isUnoVariable(node.id.name))
|
|
472
|
+
return;
|
|
473
|
+
if (isPossibleLiteral(node.init)) {
|
|
474
|
+
return checkPossibleLiteral(node.init);
|
|
475
|
+
}
|
|
476
|
+
if (node.init.type === "TSAsExpression" && isPossibleLiteral(node.init.expression)) {
|
|
477
|
+
return checkPossibleLiteral(node.init.expression);
|
|
478
|
+
}
|
|
479
|
+
function handleObjectExpression(node2) {
|
|
480
|
+
node2.properties.forEach((p) => {
|
|
481
|
+
if (p.type !== "Property")
|
|
482
|
+
return;
|
|
483
|
+
if (isPossibleLiteral(p.value)) {
|
|
484
|
+
return checkPossibleLiteral(p.value);
|
|
485
|
+
}
|
|
486
|
+
if (p.value.type === "ObjectExpression") {
|
|
487
|
+
return handleObjectExpression(p.value);
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
if (node.init.type === "ObjectExpression") {
|
|
492
|
+
return handleObjectExpression(node.init);
|
|
493
|
+
}
|
|
494
|
+
if (node.init.type === "TSAsExpression" && node.init.expression.type === "ObjectExpression") {
|
|
495
|
+
return handleObjectExpression(node.init.expression);
|
|
496
|
+
}
|
|
347
497
|
}
|
|
348
498
|
};
|
|
349
499
|
const templateBodyVisitor = {
|
package/dist/index.mjs
CHANGED
|
@@ -270,10 +270,39 @@ const order = createRule({
|
|
|
270
270
|
messages: {
|
|
271
271
|
"invalid-order": "UnoCSS utilities are not ordered"
|
|
272
272
|
},
|
|
273
|
-
schema: [
|
|
273
|
+
schema: [
|
|
274
|
+
{
|
|
275
|
+
type: "object",
|
|
276
|
+
properties: {
|
|
277
|
+
unoFunctions: {
|
|
278
|
+
type: "array",
|
|
279
|
+
items: { type: "string" }
|
|
280
|
+
},
|
|
281
|
+
unoVariables: {
|
|
282
|
+
type: "array",
|
|
283
|
+
items: { type: "string" }
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
]
|
|
274
288
|
},
|
|
275
|
-
defaultOptions: [
|
|
289
|
+
defaultOptions: [
|
|
290
|
+
{
|
|
291
|
+
unoFunctions: ["clsx", "classnames"],
|
|
292
|
+
unoVariables: ["^cls", "classNames?$"]
|
|
293
|
+
// for example `clsButton = ''` or `buttonClassNames = {}`
|
|
294
|
+
}
|
|
295
|
+
],
|
|
276
296
|
create(context) {
|
|
297
|
+
let { unoFunctions = ["clsx", "classnames"], unoVariables = ["^cls", "classNames?$"] } = context.options[0] || {};
|
|
298
|
+
unoFunctions = unoFunctions.map((name) => name.toLowerCase());
|
|
299
|
+
function isUnoFunction(name) {
|
|
300
|
+
return unoFunctions.includes(name.toLowerCase());
|
|
301
|
+
}
|
|
302
|
+
const unoVariablesRegexes = unoVariables.map((regex) => new RegExp(regex, "i"));
|
|
303
|
+
function isUnoVariable(name) {
|
|
304
|
+
return unoVariablesRegexes.some((reg) => reg.test(name));
|
|
305
|
+
}
|
|
277
306
|
function checkLiteral(node, addSpace) {
|
|
278
307
|
if (typeof node.value !== "string" || !node.value.trim())
|
|
279
308
|
return;
|
|
@@ -302,13 +331,84 @@ const order = createRule({
|
|
|
302
331
|
});
|
|
303
332
|
}
|
|
304
333
|
}
|
|
334
|
+
function checkTemplateElement(quasi) {
|
|
335
|
+
const input = quasi.value.raw;
|
|
336
|
+
if (!input)
|
|
337
|
+
return;
|
|
338
|
+
const getRange = () => {
|
|
339
|
+
const text = context.sourceCode.getText(quasi);
|
|
340
|
+
const raw = quasi.value.raw;
|
|
341
|
+
if (!text.includes(raw))
|
|
342
|
+
return;
|
|
343
|
+
const rawStart = text.indexOf(raw);
|
|
344
|
+
const start = quasi.range[0] + rawStart;
|
|
345
|
+
const end = quasi.range[0] + rawStart + raw.length;
|
|
346
|
+
if (start < quasi.range[0] || end > quasi.range[1])
|
|
347
|
+
return;
|
|
348
|
+
return [start, end];
|
|
349
|
+
};
|
|
350
|
+
const realRange = getRange();
|
|
351
|
+
if (!realRange)
|
|
352
|
+
return;
|
|
353
|
+
let sorted = syncAction(
|
|
354
|
+
context.settings.unocss?.configPath,
|
|
355
|
+
"sort",
|
|
356
|
+
input
|
|
357
|
+
).trim();
|
|
358
|
+
if (/^\s/.test(input))
|
|
359
|
+
sorted = ` ${sorted}`;
|
|
360
|
+
if (/\s$/.test(input))
|
|
361
|
+
sorted += " ";
|
|
362
|
+
if (sorted !== input) {
|
|
363
|
+
context.report({
|
|
364
|
+
node: quasi,
|
|
365
|
+
loc: quasi.loc,
|
|
366
|
+
messageId: "invalid-order",
|
|
367
|
+
fix(fixer) {
|
|
368
|
+
const realRange2 = getRange();
|
|
369
|
+
if (!realRange2)
|
|
370
|
+
return null;
|
|
371
|
+
return fixer.replaceTextRange(realRange2, sorted);
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
function isPossibleLiteral(node) {
|
|
377
|
+
return node.type === "Literal" || node.type === "TemplateLiteral" || node.type === "TaggedTemplateExpression";
|
|
378
|
+
}
|
|
379
|
+
function checkPossibleLiteral(...nodes) {
|
|
380
|
+
nodes.forEach((node) => {
|
|
381
|
+
if (!isPossibleLiteral(node))
|
|
382
|
+
return;
|
|
383
|
+
if (node.type === "Literal" && typeof node.value === "string") {
|
|
384
|
+
return checkLiteral(node);
|
|
385
|
+
}
|
|
386
|
+
const isSimpleTemplateLiteral = (node2) => {
|
|
387
|
+
return node2.expressions.length === 0 && node2.quasis.length === 1;
|
|
388
|
+
};
|
|
389
|
+
if (node.type === "TemplateLiteral" && isSimpleTemplateLiteral(node)) {
|
|
390
|
+
return checkTemplateElement(node.quasis[0]);
|
|
391
|
+
}
|
|
392
|
+
const isStringRaw = (tag) => {
|
|
393
|
+
return tag.type === "MemberExpression" && tag.object.type === "Identifier" && tag.object.name === "String" && tag.property.type === "Identifier" && tag.property.name === "raw";
|
|
394
|
+
};
|
|
395
|
+
if (node.type === "TaggedTemplateExpression" && isStringRaw(node.tag) && isSimpleTemplateLiteral(node.quasi)) {
|
|
396
|
+
return checkTemplateElement(node.quasi.quasis[0]);
|
|
397
|
+
}
|
|
398
|
+
if (node.type === "TemplateLiteral" && node.expressions.length > 0 && node.quasis.length > 0) {
|
|
399
|
+
return void node.quasis.forEach((quasi) => {
|
|
400
|
+
checkTemplateElement(quasi);
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
}
|
|
305
405
|
const scriptVisitor = {
|
|
306
406
|
JSXAttribute(node) {
|
|
307
407
|
if (typeof node.name.name === "string" && CLASS_FIELDS.includes(node.name.name.toLowerCase()) && node.value) {
|
|
308
|
-
if (node.value
|
|
309
|
-
|
|
310
|
-
else if (node.value.type === "JSXExpressionContainer" && node.value.expression
|
|
311
|
-
|
|
408
|
+
if (isPossibleLiteral(node.value))
|
|
409
|
+
return checkPossibleLiteral(node.value);
|
|
410
|
+
else if (node.value.type === "JSXExpressionContainer" && isPossibleLiteral(node.value.expression))
|
|
411
|
+
return checkPossibleLiteral(node.value.expression);
|
|
312
412
|
}
|
|
313
413
|
},
|
|
314
414
|
SvelteAttribute(node) {
|
|
@@ -338,6 +438,56 @@ const order = createRule({
|
|
|
338
438
|
}
|
|
339
439
|
});
|
|
340
440
|
}
|
|
441
|
+
},
|
|
442
|
+
// for Future node types
|
|
443
|
+
// 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
|
|
444
|
+
CallExpression(node) {
|
|
445
|
+
if (!(node.callee.type === "Identifier" && isUnoFunction(node.callee.name)))
|
|
446
|
+
return;
|
|
447
|
+
node.arguments.forEach((arg) => {
|
|
448
|
+
if (isPossibleLiteral(arg)) {
|
|
449
|
+
return checkPossibleLiteral(arg);
|
|
450
|
+
}
|
|
451
|
+
if (arg.type === "ConditionalExpression") {
|
|
452
|
+
return checkPossibleLiteral(arg.consequent, arg.alternate);
|
|
453
|
+
}
|
|
454
|
+
if (arg.type === "LogicalExpression") {
|
|
455
|
+
return checkPossibleLiteral(arg.left, arg.right);
|
|
456
|
+
}
|
|
457
|
+
if (arg.type === "ObjectExpression") {
|
|
458
|
+
const keys = arg.properties.filter((p) => p.type === "Property").map((p) => p.key);
|
|
459
|
+
return checkPossibleLiteral(...keys);
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
},
|
|
463
|
+
// https://typescript-eslint.io/play/#ts=5.8.2&showAST=es&fileType=.tsx&code=MYewdgzgLgBApgDygJwIYGEA2qIQHKoC2cMAvDAOQBeAtAIwAMDFAUCwPTswBuqyAlqgBGmEgBM4wbGij9wLUJFhSIAIQCuUKODKVCyeq0XQYKjVvAAmXQAN99GABIA3ohQZsuAsQC%2BNheAmZpraYADMtvZ0Tq5IaFg4%2BERwfjA4poFQbJwwIEIAVpKwElJ8qLLyxrBCUGAJXskQus4sMDASAGao6phQAFx6mDSWAA4IFAA0rTAA7vxQABYAonGoAzYdoggw83CEEDTAcGBQcMgwQgDmNDMLuzCnSDQiqMAA1jFu8Z5JvjZTbQQAxabTaAE8BhRCENRuNpj4WAiOFx0lV2pJpOU5GAAkoLrV6r84BBrOQQeiuj1%2BoNhmNJtMgTByeDIdDaXC2gifGkmlUgA&eslintrc=N4KABGBEBOCuA2BTAzpAXGYBfEWg&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false
|
|
464
|
+
VariableDeclarator(node) {
|
|
465
|
+
if (node.id.type !== "Identifier" || !node.init || !isUnoVariable(node.id.name))
|
|
466
|
+
return;
|
|
467
|
+
if (isPossibleLiteral(node.init)) {
|
|
468
|
+
return checkPossibleLiteral(node.init);
|
|
469
|
+
}
|
|
470
|
+
if (node.init.type === "TSAsExpression" && isPossibleLiteral(node.init.expression)) {
|
|
471
|
+
return checkPossibleLiteral(node.init.expression);
|
|
472
|
+
}
|
|
473
|
+
function handleObjectExpression(node2) {
|
|
474
|
+
node2.properties.forEach((p) => {
|
|
475
|
+
if (p.type !== "Property")
|
|
476
|
+
return;
|
|
477
|
+
if (isPossibleLiteral(p.value)) {
|
|
478
|
+
return checkPossibleLiteral(p.value);
|
|
479
|
+
}
|
|
480
|
+
if (p.value.type === "ObjectExpression") {
|
|
481
|
+
return handleObjectExpression(p.value);
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
if (node.init.type === "ObjectExpression") {
|
|
486
|
+
return handleObjectExpression(node.init);
|
|
487
|
+
}
|
|
488
|
+
if (node.init.type === "TSAsExpression" && node.init.expression.type === "ObjectExpression") {
|
|
489
|
+
return handleObjectExpression(node.init.expression);
|
|
490
|
+
}
|
|
341
491
|
}
|
|
342
492
|
};
|
|
343
493
|
const templateBodyVisitor = {
|
package/dist/worker.mjs
CHANGED
|
@@ -9,16 +9,21 @@ async function sortRules(rules, uno) {
|
|
|
9
9
|
uno.config.details = true;
|
|
10
10
|
const expandedResult = parseVariantGroup(rules);
|
|
11
11
|
rules = expandedResult.expanded;
|
|
12
|
-
const result =
|
|
12
|
+
const result = [];
|
|
13
|
+
const arr = rules.split(/\s+/g);
|
|
14
|
+
for (const i of arr) {
|
|
15
|
+
if (!i)
|
|
16
|
+
continue;
|
|
13
17
|
const token = await uno.parseToken(i);
|
|
14
18
|
if (token == null) {
|
|
15
19
|
unknown.push(i);
|
|
16
|
-
|
|
20
|
+
result.push(void 0);
|
|
21
|
+
continue;
|
|
17
22
|
}
|
|
18
23
|
const variantRank = (token[0][5]?.variantHandlers?.length || 0) * 1e5;
|
|
19
24
|
const order = token[0][0] + variantRank;
|
|
20
|
-
|
|
21
|
-
}
|
|
25
|
+
result.push([order, i]);
|
|
26
|
+
}
|
|
22
27
|
let sorted = result.filter(notNull).sort((a, b) => {
|
|
23
28
|
let result2 = a[0] - b[0];
|
|
24
29
|
if (result2 === 0)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/eslint-plugin",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "66.
|
|
4
|
+
"version": "66.4.0",
|
|
5
5
|
"description": "ESLint plugin for UnoCSS",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -35,18 +35,18 @@
|
|
|
35
35
|
"node": ">=14"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@typescript-eslint/utils": "^8.
|
|
38
|
+
"@typescript-eslint/utils": "^8.38.0",
|
|
39
39
|
"magic-string": "^0.30.17",
|
|
40
|
-
"synckit": "^0.11.
|
|
41
|
-
"@unocss/config": "66.
|
|
42
|
-
"@unocss/
|
|
43
|
-
"@unocss/
|
|
40
|
+
"synckit": "^0.11.11",
|
|
41
|
+
"@unocss/config": "66.4.0",
|
|
42
|
+
"@unocss/rule-utils": "66.4.0",
|
|
43
|
+
"@unocss/core": "66.4.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@typescript/native-preview": "latest",
|
|
47
|
-
"svelte-eslint-parser": "^1.
|
|
47
|
+
"svelte-eslint-parser": "^1.3.1",
|
|
48
48
|
"vue-eslint-parser": "^10.2.0",
|
|
49
|
-
"@unocss/eslint-plugin": "66.
|
|
49
|
+
"@unocss/eslint-plugin": "66.4.0"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
52
|
"build": "unbuild",
|