@unocss/eslint-plugin 0.65.0-beta.2 → 0.65.0-beta.3
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 +35 -6
- package/dist/index.mjs +35 -6
- package/package.json +5 -4
package/dist/index.cjs
CHANGED
|
@@ -5,6 +5,7 @@ const utils = require('@typescript-eslint/utils');
|
|
|
5
5
|
const synckit = require('synckit');
|
|
6
6
|
const dirs = require('./dirs.cjs');
|
|
7
7
|
const MagicString = require('magic-string');
|
|
8
|
+
const types = require('@typescript-eslint/types');
|
|
8
9
|
require('node:url');
|
|
9
10
|
|
|
10
11
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
@@ -279,24 +280,30 @@ const order = createRule({
|
|
|
279
280
|
},
|
|
280
281
|
defaultOptions: [],
|
|
281
282
|
create(context) {
|
|
282
|
-
function checkLiteral(node) {
|
|
283
|
+
function checkLiteral(node, addSpace) {
|
|
283
284
|
if (typeof node.value !== "string" || !node.value.trim())
|
|
284
285
|
return;
|
|
285
286
|
const input = node.value;
|
|
286
|
-
|
|
287
|
+
let sorted = syncAction(
|
|
287
288
|
context.settings.unocss?.configPath,
|
|
288
289
|
"sort",
|
|
289
290
|
input
|
|
290
291
|
).trim();
|
|
292
|
+
if (addSpace === "before")
|
|
293
|
+
sorted = ` ${sorted}`;
|
|
294
|
+
else if (addSpace === "after")
|
|
295
|
+
sorted += " ";
|
|
291
296
|
if (sorted !== input) {
|
|
297
|
+
const nodeOrToken = node.type === "SvelteLiteral" ? { type: types.AST_TOKEN_TYPES.String, value: node.value, loc: node.loc, range: node.range } : node;
|
|
292
298
|
context.report({
|
|
293
|
-
node,
|
|
299
|
+
node: nodeOrToken,
|
|
300
|
+
loc: node.loc,
|
|
294
301
|
messageId: "invalid-order",
|
|
295
302
|
fix(fixer) {
|
|
296
303
|
if (AST_NODES_WITH_QUOTES.includes(node.type))
|
|
297
304
|
return fixer.replaceTextRange([node.range[0] + 1, node.range[1] - 1], sorted);
|
|
298
305
|
else
|
|
299
|
-
return fixer.replaceText(
|
|
306
|
+
return fixer.replaceText(nodeOrToken, sorted);
|
|
300
307
|
}
|
|
301
308
|
});
|
|
302
309
|
}
|
|
@@ -310,8 +317,30 @@ const order = createRule({
|
|
|
310
317
|
},
|
|
311
318
|
SvelteAttribute(node) {
|
|
312
319
|
if (node.key.name === "class") {
|
|
313
|
-
|
|
314
|
-
|
|
320
|
+
let checkExpressionRecursively = function(expression) {
|
|
321
|
+
if (expression.type !== "ConditionalExpression")
|
|
322
|
+
return;
|
|
323
|
+
if (expression.consequent.type === "Literal") {
|
|
324
|
+
checkLiteral(expression.consequent);
|
|
325
|
+
}
|
|
326
|
+
if (expression.alternate) {
|
|
327
|
+
if (expression.alternate.type === "ConditionalExpression") {
|
|
328
|
+
checkExpressionRecursively(expression.alternate);
|
|
329
|
+
} else if (expression.alternate.type === "Literal") {
|
|
330
|
+
checkLiteral(expression.alternate);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
if (!node.value.length)
|
|
335
|
+
return;
|
|
336
|
+
node.value.forEach((obj, i) => {
|
|
337
|
+
if (obj.type === "SvelteMustacheTag") {
|
|
338
|
+
checkExpressionRecursively(obj.expression);
|
|
339
|
+
} else if (obj.type === "SvelteLiteral") {
|
|
340
|
+
const addSpace = node.value?.[i - 1]?.type === "SvelteMustacheTag" ? "before" : node.value?.[i + 1]?.type === "SvelteMustacheTag" ? "after" : void 0;
|
|
341
|
+
checkLiteral(obj, addSpace);
|
|
342
|
+
}
|
|
343
|
+
});
|
|
315
344
|
}
|
|
316
345
|
}
|
|
317
346
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import { ESLintUtils } from '@typescript-eslint/utils';
|
|
|
3
3
|
import { createSyncFn } from 'synckit';
|
|
4
4
|
import { distDir } from './dirs.mjs';
|
|
5
5
|
import MagicString from 'magic-string';
|
|
6
|
+
import { AST_TOKEN_TYPES } from '@typescript-eslint/types';
|
|
6
7
|
import 'node:url';
|
|
7
8
|
|
|
8
9
|
const CLASS_FIELDS = ["class", "classname"];
|
|
@@ -273,24 +274,30 @@ const order = createRule({
|
|
|
273
274
|
},
|
|
274
275
|
defaultOptions: [],
|
|
275
276
|
create(context) {
|
|
276
|
-
function checkLiteral(node) {
|
|
277
|
+
function checkLiteral(node, addSpace) {
|
|
277
278
|
if (typeof node.value !== "string" || !node.value.trim())
|
|
278
279
|
return;
|
|
279
280
|
const input = node.value;
|
|
280
|
-
|
|
281
|
+
let sorted = syncAction(
|
|
281
282
|
context.settings.unocss?.configPath,
|
|
282
283
|
"sort",
|
|
283
284
|
input
|
|
284
285
|
).trim();
|
|
286
|
+
if (addSpace === "before")
|
|
287
|
+
sorted = ` ${sorted}`;
|
|
288
|
+
else if (addSpace === "after")
|
|
289
|
+
sorted += " ";
|
|
285
290
|
if (sorted !== input) {
|
|
291
|
+
const nodeOrToken = node.type === "SvelteLiteral" ? { type: AST_TOKEN_TYPES.String, value: node.value, loc: node.loc, range: node.range } : node;
|
|
286
292
|
context.report({
|
|
287
|
-
node,
|
|
293
|
+
node: nodeOrToken,
|
|
294
|
+
loc: node.loc,
|
|
288
295
|
messageId: "invalid-order",
|
|
289
296
|
fix(fixer) {
|
|
290
297
|
if (AST_NODES_WITH_QUOTES.includes(node.type))
|
|
291
298
|
return fixer.replaceTextRange([node.range[0] + 1, node.range[1] - 1], sorted);
|
|
292
299
|
else
|
|
293
|
-
return fixer.replaceText(
|
|
300
|
+
return fixer.replaceText(nodeOrToken, sorted);
|
|
294
301
|
}
|
|
295
302
|
});
|
|
296
303
|
}
|
|
@@ -304,8 +311,30 @@ const order = createRule({
|
|
|
304
311
|
},
|
|
305
312
|
SvelteAttribute(node) {
|
|
306
313
|
if (node.key.name === "class") {
|
|
307
|
-
|
|
308
|
-
|
|
314
|
+
let checkExpressionRecursively = function(expression) {
|
|
315
|
+
if (expression.type !== "ConditionalExpression")
|
|
316
|
+
return;
|
|
317
|
+
if (expression.consequent.type === "Literal") {
|
|
318
|
+
checkLiteral(expression.consequent);
|
|
319
|
+
}
|
|
320
|
+
if (expression.alternate) {
|
|
321
|
+
if (expression.alternate.type === "ConditionalExpression") {
|
|
322
|
+
checkExpressionRecursively(expression.alternate);
|
|
323
|
+
} else if (expression.alternate.type === "Literal") {
|
|
324
|
+
checkLiteral(expression.alternate);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
if (!node.value.length)
|
|
329
|
+
return;
|
|
330
|
+
node.value.forEach((obj, i) => {
|
|
331
|
+
if (obj.type === "SvelteMustacheTag") {
|
|
332
|
+
checkExpressionRecursively(obj.expression);
|
|
333
|
+
} else if (obj.type === "SvelteLiteral") {
|
|
334
|
+
const addSpace = node.value?.[i - 1]?.type === "SvelteMustacheTag" ? "before" : node.value?.[i + 1]?.type === "SvelteMustacheTag" ? "after" : void 0;
|
|
335
|
+
checkLiteral(obj, addSpace);
|
|
336
|
+
}
|
|
337
|
+
});
|
|
309
338
|
}
|
|
310
339
|
}
|
|
311
340
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/eslint-plugin",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.65.0-beta.
|
|
4
|
+
"version": "0.65.0-beta.3",
|
|
5
5
|
"description": "ESLint plugin for UnoCSS",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -38,12 +38,13 @@
|
|
|
38
38
|
"@typescript-eslint/utils": "^8.12.2",
|
|
39
39
|
"magic-string": "^0.30.12",
|
|
40
40
|
"synckit": "^0.9.2",
|
|
41
|
-
"@unocss/
|
|
42
|
-
"@unocss/
|
|
41
|
+
"@unocss/core": "0.65.0-beta.3",
|
|
42
|
+
"@unocss/config": "0.65.0-beta.3"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
+
"svelte-eslint-parser": "^0.42.0",
|
|
45
46
|
"vue-eslint-parser": "^9.4.3",
|
|
46
|
-
"@unocss/eslint-plugin": "0.65.0-beta.
|
|
47
|
+
"@unocss/eslint-plugin": "0.65.0-beta.3"
|
|
47
48
|
},
|
|
48
49
|
"scripts": {
|
|
49
50
|
"build": "unbuild",
|