@unocss/eslint-plugin 0.57.7 → 0.58.1

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
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
- const utils = require('@typescript-eslint/utils');
4
3
  const MagicString = require('magic-string');
5
4
  const node_path = require('node:path');
6
5
  const synckit = require('synckit');
6
+ const utils = require('@typescript-eslint/utils');
7
7
  const dirs = require('./dirs.cjs');
8
8
  require('node:url');
9
9
 
@@ -20,9 +20,12 @@ const configsRecommended = {
20
20
  };
21
21
 
22
22
  const syncAction = synckit.createSyncFn(node_path.join(dirs.distDir, "worker.cjs"));
23
+ const createRule = utils.ESLintUtils.RuleCreator(
24
+ () => "https://unocss.dev/integrations/eslint#rules"
25
+ );
23
26
 
24
27
  const IGNORE_ATTRIBUTES = ["style", "class", "classname", "value"];
25
- const orderAttributify = utils.ESLintUtils.RuleCreator((name) => name)({
28
+ const orderAttributify = createRule({
26
29
  name: "order-attributify",
27
30
  meta: {
28
31
  type: "layout",
@@ -76,7 +79,7 @@ const orderAttributify = utils.ESLintUtils.RuleCreator((name) => name)({
76
79
  const CLASS_FIELDS = ["class", "classname"];
77
80
  const AST_NODES_WITH_QUOTES = ["Literal", "VLiteral"];
78
81
 
79
- const order = utils.ESLintUtils.RuleCreator((name) => name)({
82
+ const order = createRule({
80
83
  name: "order",
81
84
  meta: {
82
85
  type: "layout",
@@ -140,7 +143,7 @@ const order = utils.ESLintUtils.RuleCreator((name) => name)({
140
143
  }
141
144
  });
142
145
 
143
- const blocklist = utils.ESLintUtils.RuleCreator((name) => name)({
146
+ const blocklist = createRule({
144
147
  name: "blocklist",
145
148
  meta: {
146
149
  type: "problem",
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
1
  import MagicString from 'magic-string';
3
2
  import { join } from 'node:path';
4
3
  import { createSyncFn } from 'synckit';
4
+ import { ESLintUtils } from '@typescript-eslint/utils';
5
5
  import { distDir } from './dirs.mjs';
6
6
  import 'node:url';
7
7
 
@@ -14,9 +14,12 @@ const configsRecommended = {
14
14
  };
15
15
 
16
16
  const syncAction = createSyncFn(join(distDir, "worker.cjs"));
17
+ const createRule = ESLintUtils.RuleCreator(
18
+ () => "https://unocss.dev/integrations/eslint#rules"
19
+ );
17
20
 
18
21
  const IGNORE_ATTRIBUTES = ["style", "class", "classname", "value"];
19
- const orderAttributify = ESLintUtils.RuleCreator((name) => name)({
22
+ const orderAttributify = createRule({
20
23
  name: "order-attributify",
21
24
  meta: {
22
25
  type: "layout",
@@ -70,7 +73,7 @@ const orderAttributify = ESLintUtils.RuleCreator((name) => name)({
70
73
  const CLASS_FIELDS = ["class", "classname"];
71
74
  const AST_NODES_WITH_QUOTES = ["Literal", "VLiteral"];
72
75
 
73
- const order = ESLintUtils.RuleCreator((name) => name)({
76
+ const order = createRule({
74
77
  name: "order",
75
78
  meta: {
76
79
  type: "layout",
@@ -134,7 +137,7 @@ const order = ESLintUtils.RuleCreator((name) => name)({
134
137
  }
135
138
  });
136
139
 
137
- const blocklist = ESLintUtils.RuleCreator((name) => name)({
140
+ const blocklist = createRule({
138
141
  name: "blocklist",
139
142
  meta: {
140
143
  type: "problem",
package/dist/worker.cjs CHANGED
@@ -52,15 +52,35 @@ async function getGenerator() {
52
52
  promise = promise || _getGenerator();
53
53
  return await promise;
54
54
  }
55
+ function setGenerator(generator) {
56
+ promise = Promise.resolve(generator);
57
+ }
55
58
  async function actionSort(classes) {
56
59
  return await sortRules(classes, await getGenerator());
57
60
  }
58
61
  async function actionBlocklist(classes, id) {
59
62
  const uno = await getGenerator();
63
+ const blocked = /* @__PURE__ */ new Set();
60
64
  const extracted = await uno.applyExtractors(classes, id);
61
- return [...extracted.values()].filter((i) => uno.isBlocked(i));
65
+ const values = [...extracted.values()];
66
+ const matchBlocked = async (raw) => {
67
+ if (blocked.has(raw))
68
+ return;
69
+ if (uno.isBlocked(raw)) {
70
+ blocked.add(raw);
71
+ return;
72
+ }
73
+ let current = raw;
74
+ for (const p of uno.config.preprocess)
75
+ current = p(raw);
76
+ const applied = await uno.matchVariants(raw, current);
77
+ if (applied && uno.isBlocked(applied[1]))
78
+ blocked.add(raw);
79
+ };
80
+ await Promise.all(values.map(matchBlocked));
81
+ return [...blocked];
62
82
  }
63
- function run(action, ...args) {
83
+ async function runAsync(action, ...args) {
64
84
  switch (action) {
65
85
  case "sort":
66
86
  return actionSort(...args);
@@ -68,7 +88,12 @@ function run(action, ...args) {
68
88
  return actionBlocklist(...args);
69
89
  }
70
90
  }
91
+ function run(action, ...args) {
92
+ return runAsync(action, ...args);
93
+ }
71
94
  synckit.runAsWorker(run);
72
95
 
73
96
  exports.getGenerator = getGenerator;
74
97
  exports.run = run;
98
+ exports.runAsync = runAsync;
99
+ exports.setGenerator = setGenerator;
package/dist/worker.d.cts CHANGED
@@ -1,7 +1,10 @@
1
1
  import { UnoGenerator } from '@unocss/core';
2
2
 
3
3
  declare function getGenerator(): Promise<UnoGenerator<any>>;
4
+ declare function setGenerator(generator: Awaited<UnoGenerator<any>>): void;
5
+ declare function runAsync(action: 'sort', classes: string): Promise<string>;
6
+ declare function runAsync(action: 'blocklist', classes: string, id?: string): Promise<string[]>;
4
7
  declare function run(action: 'sort', classes: string): string;
5
8
  declare function run(action: 'blocklist', classes: string, id?: string): string[];
6
9
 
7
- export { getGenerator, run };
10
+ export { getGenerator, run, runAsync, setGenerator };
package/dist/worker.d.mts CHANGED
@@ -1,7 +1,10 @@
1
1
  import { UnoGenerator } from '@unocss/core';
2
2
 
3
3
  declare function getGenerator(): Promise<UnoGenerator<any>>;
4
+ declare function setGenerator(generator: Awaited<UnoGenerator<any>>): void;
5
+ declare function runAsync(action: 'sort', classes: string): Promise<string>;
6
+ declare function runAsync(action: 'blocklist', classes: string, id?: string): Promise<string[]>;
4
7
  declare function run(action: 'sort', classes: string): string;
5
8
  declare function run(action: 'blocklist', classes: string, id?: string): string[];
6
9
 
7
- export { getGenerator, run };
10
+ export { getGenerator, run, runAsync, setGenerator };
package/dist/worker.d.ts CHANGED
@@ -1,7 +1,10 @@
1
1
  import { UnoGenerator } from '@unocss/core';
2
2
 
3
3
  declare function getGenerator(): Promise<UnoGenerator<any>>;
4
+ declare function setGenerator(generator: Awaited<UnoGenerator<any>>): void;
5
+ declare function runAsync(action: 'sort', classes: string): Promise<string>;
6
+ declare function runAsync(action: 'blocklist', classes: string, id?: string): Promise<string[]>;
4
7
  declare function run(action: 'sort', classes: string): string;
5
8
  declare function run(action: 'blocklist', classes: string, id?: string): string[];
6
9
 
7
- export { getGenerator, run };
10
+ export { getGenerator, run, runAsync, setGenerator };
package/dist/worker.mjs CHANGED
@@ -46,15 +46,35 @@ async function getGenerator() {
46
46
  promise = promise || _getGenerator();
47
47
  return await promise;
48
48
  }
49
+ function setGenerator(generator) {
50
+ promise = Promise.resolve(generator);
51
+ }
49
52
  async function actionSort(classes) {
50
53
  return await sortRules(classes, await getGenerator());
51
54
  }
52
55
  async function actionBlocklist(classes, id) {
53
56
  const uno = await getGenerator();
57
+ const blocked = /* @__PURE__ */ new Set();
54
58
  const extracted = await uno.applyExtractors(classes, id);
55
- return [...extracted.values()].filter((i) => uno.isBlocked(i));
59
+ const values = [...extracted.values()];
60
+ const matchBlocked = async (raw) => {
61
+ if (blocked.has(raw))
62
+ return;
63
+ if (uno.isBlocked(raw)) {
64
+ blocked.add(raw);
65
+ return;
66
+ }
67
+ let current = raw;
68
+ for (const p of uno.config.preprocess)
69
+ current = p(raw);
70
+ const applied = await uno.matchVariants(raw, current);
71
+ if (applied && uno.isBlocked(applied[1]))
72
+ blocked.add(raw);
73
+ };
74
+ await Promise.all(values.map(matchBlocked));
75
+ return [...blocked];
56
76
  }
57
- function run(action, ...args) {
77
+ async function runAsync(action, ...args) {
58
78
  switch (action) {
59
79
  case "sort":
60
80
  return actionSort(...args);
@@ -62,6 +82,9 @@ function run(action, ...args) {
62
82
  return actionBlocklist(...args);
63
83
  }
64
84
  }
85
+ function run(action, ...args) {
86
+ return runAsync(action, ...args);
87
+ }
65
88
  runAsWorker(run);
66
89
 
67
- export { getGenerator, run };
90
+ export { getGenerator, run, runAsync, setGenerator };
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@unocss/eslint-plugin",
3
- "version": "0.57.7",
3
+ "version": "0.58.1",
4
4
  "description": "ESLint plugin for UnoCSS",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/antfu",
8
- "homepage": "https://github.com/unocss/unocss/tree/main/packages/esling-plugin#readme",
8
+ "homepage": "https://github.com/unocss/unocss/tree/main/packages/eslint-plugin#readme",
9
9
  "repository": {
10
10
  "type": "git",
11
11
  "url": "https://github.com/unocss/unocss",
12
- "directory": "packages/esling-plugin"
12
+ "directory": "packages/eslint-plugin"
13
13
  },
14
14
  "bugs": {
15
15
  "url": "https://github.com/unocss/unocss/issues"
@@ -34,14 +34,14 @@
34
34
  "node": ">=14"
35
35
  },
36
36
  "dependencies": {
37
- "@typescript-eslint/utils": "^6.11.0",
37
+ "@typescript-eslint/utils": "^6.16.0",
38
38
  "magic-string": "^0.30.5",
39
- "synckit": "^0.8.5",
40
- "@unocss/config": "0.57.7",
41
- "@unocss/core": "0.57.7"
39
+ "synckit": "^0.8.8",
40
+ "@unocss/config": "0.58.1",
41
+ "@unocss/core": "0.58.1"
42
42
  },
43
43
  "devDependencies": {
44
- "@unocss/eslint-plugin": "0.57.7"
44
+ "@unocss/eslint-plugin": "0.58.1"
45
45
  },
46
46
  "scripts": {
47
47
  "build": "unbuild",