@unocss/eslint-plugin 0.50.6 → 0.50.8

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
@@ -12,6 +12,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
12
12
  const MagicString__default = /*#__PURE__*/_interopDefaultLegacy(MagicString);
13
13
 
14
14
  const CLASS_FIELDS = ["class", "classname"];
15
+ const AST_NODES_WITH_QUOTES = ["Literal", "VLiteral"];
15
16
 
16
17
  const sortClasses$1 = synckit.createSyncFn(node_path.join(dirs.distDir, "worker-sort.cjs"));
17
18
  const order = utils.ESLintUtils.RuleCreator((name) => name)({
@@ -31,16 +32,19 @@ const order = utils.ESLintUtils.RuleCreator((name) => name)({
31
32
  defaultOptions: [],
32
33
  create(context) {
33
34
  function checkLiteral(node) {
34
- if (typeof node.value !== "string")
35
+ if (typeof node.value !== "string" || !node.value.trim())
35
36
  return;
36
37
  const input = node.value;
37
- const sorted = sortClasses$1(input);
38
+ const sorted = sortClasses$1(input).trim();
38
39
  if (sorted !== input) {
39
40
  context.report({
40
41
  node,
41
42
  messageId: "invalid-order",
42
43
  fix(fixer) {
43
- return fixer.replaceText(node, `"${sorted.trim()}"`);
44
+ if (AST_NODES_WITH_QUOTES.includes(node.type))
45
+ return fixer.replaceTextRange([node.range[0] + 1, node.range[1] - 1], sorted);
46
+ else
47
+ return fixer.replaceText(node, sorted);
44
48
  }
45
49
  });
46
50
  }
@@ -51,6 +55,12 @@ const order = utils.ESLintUtils.RuleCreator((name) => name)({
51
55
  if (node.value.type === "Literal")
52
56
  checkLiteral(node.value);
53
57
  }
58
+ },
59
+ SvelteAttribute(node) {
60
+ if (node.key.name === "class") {
61
+ if (node.value?.[0].type === "SvelteLiteral")
62
+ checkLiteral(node.value[0]);
63
+ }
54
64
  }
55
65
  };
56
66
  const templateBodyVisitor = {
package/dist/index.mjs CHANGED
@@ -6,6 +6,7 @@ import MagicString from 'magic-string';
6
6
  import 'node:url';
7
7
 
8
8
  const CLASS_FIELDS = ["class", "classname"];
9
+ const AST_NODES_WITH_QUOTES = ["Literal", "VLiteral"];
9
10
 
10
11
  const sortClasses$1 = createSyncFn(join(distDir, "worker-sort.cjs"));
11
12
  const order = ESLintUtils.RuleCreator((name) => name)({
@@ -25,16 +26,19 @@ const order = ESLintUtils.RuleCreator((name) => name)({
25
26
  defaultOptions: [],
26
27
  create(context) {
27
28
  function checkLiteral(node) {
28
- if (typeof node.value !== "string")
29
+ if (typeof node.value !== "string" || !node.value.trim())
29
30
  return;
30
31
  const input = node.value;
31
- const sorted = sortClasses$1(input);
32
+ const sorted = sortClasses$1(input).trim();
32
33
  if (sorted !== input) {
33
34
  context.report({
34
35
  node,
35
36
  messageId: "invalid-order",
36
37
  fix(fixer) {
37
- return fixer.replaceText(node, `"${sorted.trim()}"`);
38
+ if (AST_NODES_WITH_QUOTES.includes(node.type))
39
+ return fixer.replaceTextRange([node.range[0] + 1, node.range[1] - 1], sorted);
40
+ else
41
+ return fixer.replaceText(node, sorted);
38
42
  }
39
43
  });
40
44
  }
@@ -45,6 +49,12 @@ const order = ESLintUtils.RuleCreator((name) => name)({
45
49
  if (node.value.type === "Literal")
46
50
  checkLiteral(node.value);
47
51
  }
52
+ },
53
+ SvelteAttribute(node) {
54
+ if (node.key.name === "class") {
55
+ if (node.value?.[0].type === "SvelteLiteral")
56
+ checkLiteral(node.value[0]);
57
+ }
48
58
  }
49
59
  };
50
60
  const templateBodyVisitor = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/eslint-plugin",
3
- "version": "0.50.6",
3
+ "version": "0.50.8",
4
4
  "description": "ESLint plugin for UnoCSS",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -36,14 +36,14 @@
36
36
  "node": ">=14"
37
37
  },
38
38
  "dependencies": {
39
- "@typescript-eslint/utils": "^5.55.0",
39
+ "@typescript-eslint/utils": "^5.57.1",
40
40
  "magic-string": "^0.30.0",
41
41
  "synckit": "^0.8.5",
42
- "@unocss/config": "0.50.6",
43
- "@unocss/core": "0.50.6"
42
+ "@unocss/config": "0.50.8",
43
+ "@unocss/core": "0.50.8"
44
44
  },
45
45
  "devDependencies": {
46
- "@unocss/eslint-plugin": "0.50.6"
46
+ "@unocss/eslint-plugin": "0.50.8"
47
47
  },
48
48
  "scripts": {
49
49
  "build": "unbuild",