@unocss/eslint-plugin 66.5.10-beta.1 → 66.5.11

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/worker.mjs CHANGED
@@ -1,130 +1,112 @@
1
- import { dirname } from 'node:path';
2
- import process from 'node:process';
3
- import { parseVariantGroup, notNull, collapseVariantGroup, createGenerator } from '@unocss/core';
4
- import { loadConfig } from '@unocss/config';
5
- import { runAsWorker } from 'synckit';
1
+ import { dirname } from "node:path";
2
+ import process from "node:process";
3
+ import { collapseVariantGroup, createGenerator, notNull, parseVariantGroup } from "@unocss/core";
4
+ import { loadConfig } from "@unocss/config";
5
+ import { runAsWorker } from "synckit";
6
6
 
7
+ //#region ../../virtual-shared/integration/src/sort-rules.ts
7
8
  async function sortRules(rules, uno) {
8
- const unknown = [];
9
- if (!uno.config.details)
10
- uno.config.details = true;
11
- const expandedResult = parseVariantGroup(rules);
12
- rules = expandedResult.expanded;
13
- const result = [];
14
- const arr = rules.split(/\s+/g);
15
- for (const i of arr) {
16
- if (!i)
17
- continue;
18
- const token = await uno.parseToken(i);
19
- if (token == null) {
20
- unknown.push(i);
21
- result.push(void 0);
22
- continue;
23
- }
24
- const variantRank = (token[0][5]?.variantHandlers?.length || 0) * 1e5;
25
- const order = token[0][0] + variantRank;
26
- result.push([order, i]);
27
- }
28
- let sorted = result.filter(notNull).sort((a, b) => {
29
- let result2 = a[0] - b[0];
30
- if (result2 === 0)
31
- result2 = a[1].localeCompare(b[1]);
32
- return result2;
33
- }).map((i) => i[1]).join(" ");
34
- if (expandedResult?.prefixes.length)
35
- sorted = collapseVariantGroup(sorted, expandedResult.prefixes);
36
- return [...unknown, sorted].join(" ").trim();
9
+ const unknown = [];
10
+ if (!uno.config.details) uno.config.details = true;
11
+ const expandedResult = parseVariantGroup(rules);
12
+ rules = expandedResult.expanded;
13
+ const result = [];
14
+ const arr = rules.split(/\s+/g);
15
+ for (const i of arr) {
16
+ var _token$0$;
17
+ if (!i) continue;
18
+ const token = await uno.parseToken(i);
19
+ if (token == null) {
20
+ unknown.push(i);
21
+ result.push(void 0);
22
+ continue;
23
+ }
24
+ const variantRank = (((_token$0$ = token[0][5]) === null || _token$0$ === void 0 || (_token$0$ = _token$0$.variantHandlers) === null || _token$0$ === void 0 ? void 0 : _token$0$.length) || 0) * 1e5;
25
+ const order = token[0][0] + variantRank;
26
+ result.push([order, i]);
27
+ }
28
+ let sorted = result.filter(notNull).sort((a, b) => {
29
+ let result$1 = a[0] - b[0];
30
+ if (result$1 === 0) result$1 = a[1].localeCompare(b[1]);
31
+ return result$1;
32
+ }).map((i) => i[1]).join(" ");
33
+ if (expandedResult === null || expandedResult === void 0 ? void 0 : expandedResult.prefixes.length) sorted = collapseVariantGroup(sorted, expandedResult.prefixes);
34
+ return [...unknown, sorted].join(" ").trim();
37
35
  }
38
36
 
37
+ //#endregion
38
+ //#region src/worker.ts
39
+ var _process$env;
39
40
  const promises = /* @__PURE__ */ new Map();
40
- process.env.ESLINT ||= "true";
41
+ (_process$env = process.env).ESLINT || (_process$env.ESLINT = "true");
41
42
  function getSearchCwd(id) {
42
- const virtualMatch = id.match(/\.\w+\/[^/]+$/);
43
- if (virtualMatch) {
44
- const realPath = id.slice(0, id.lastIndexOf("/"));
45
- return dirname(realPath);
46
- }
47
- return dirname(id);
43
+ if (id.match(/\.\w+\/[^/]+$/)) return dirname(id.slice(0, id.lastIndexOf("/")));
44
+ return dirname(id);
48
45
  }
49
46
  async function _getGenerator(configPath, id) {
50
- const searchFrom = configPath ? process.cwd() : id ? getSearchCwd(id) : process.cwd();
51
- const { config, sources } = await loadConfig(
52
- searchFrom,
53
- configPath
54
- );
55
- if (!sources.length)
56
- throw new Error("[@unocss/eslint-plugin] No config file found, create a `uno.config.ts` file in your project root and try again.");
57
- return createGenerator({
58
- ...config,
59
- warn: false
60
- });
47
+ const { config, sources } = await loadConfig(configPath ? process.cwd() : id ? getSearchCwd(id) : process.cwd(), configPath);
48
+ if (!sources.length) throw new Error("[@unocss/eslint-plugin] No config file found, create a `uno.config.ts` file in your project root and try again.");
49
+ return createGenerator({
50
+ ...config,
51
+ warn: false
52
+ });
61
53
  }
62
54
  function getCacheKey(configPath, id) {
63
- if (configPath)
64
- return `config:${configPath}`;
65
- if (id)
66
- return `dir:${getSearchCwd(id)}`;
67
- return `cwd:${process.cwd()}`;
55
+ if (configPath) return `config:${configPath}`;
56
+ if (id) return `dir:${getSearchCwd(id)}`;
57
+ return `cwd:${process.cwd()}`;
68
58
  }
69
59
  async function getGenerator(configPath, id) {
70
- const cacheKey = getCacheKey(configPath, id);
71
- let promise = promises.get(cacheKey);
72
- if (!promise) {
73
- promise = _getGenerator(configPath, id);
74
- promises.set(cacheKey, promise);
75
- }
76
- return await promise;
60
+ const cacheKey = getCacheKey(configPath, id);
61
+ let promise = promises.get(cacheKey);
62
+ if (!promise) {
63
+ promise = _getGenerator(configPath, id);
64
+ promises.set(cacheKey, promise);
65
+ }
66
+ return await promise;
77
67
  }
78
68
  function setGenerator(generator, configPath) {
79
- const cacheKey = configPath ? `config:${configPath}` : `cwd:${process.cwd()}`;
80
- promises.set(cacheKey, Promise.resolve(generator));
69
+ const cacheKey = configPath ? `config:${configPath}` : `cwd:${process.cwd()}`;
70
+ promises.set(cacheKey, Promise.resolve(generator));
81
71
  }
82
72
  async function actionSort(configPath, classes, id) {
83
- return await sortRules(classes, await getGenerator(configPath, id));
73
+ return await sortRules(classes, await getGenerator(configPath, id));
84
74
  }
85
75
  async function actionBlocklist(configPath, classes, id) {
86
- const uno = await getGenerator(configPath, id);
87
- const blocked = /* @__PURE__ */ new Map();
88
- const extracted = await uno.applyExtractors(classes, id);
89
- const values = [...extracted.values()];
90
- const getMeta = (raw, meta) => {
91
- return meta?.message ? {
92
- ...meta,
93
- message: typeof meta.message === "function" ? meta.message(raw) : meta.message
94
- } : meta;
95
- };
96
- const matchBlocked = async (raw) => {
97
- if (blocked.has(raw))
98
- return;
99
- const rule = uno.getBlocked(raw);
100
- if (rule) {
101
- blocked.set(raw, getMeta(raw, rule[1]));
102
- return;
103
- }
104
- let current = raw;
105
- for (const p of uno.config.preprocess)
106
- current = p(raw);
107
- const results = await uno.matchVariants(raw, current);
108
- const rules = results.map((r) => r && uno.getBlocked(r[1]));
109
- for (const rule2 of rules) {
110
- if (rule2)
111
- blocked.set(raw, getMeta(raw, rule2[1]));
112
- }
113
- };
114
- await Promise.all(values.map(matchBlocked));
115
- return [...blocked];
76
+ const uno = await getGenerator(configPath, id);
77
+ const blocked = /* @__PURE__ */ new Map();
78
+ const values = [...(await uno.applyExtractors(classes, id)).values()];
79
+ const getMeta = (raw, meta) => {
80
+ return (meta === null || meta === void 0 ? void 0 : meta.message) ? {
81
+ ...meta,
82
+ message: typeof meta.message === "function" ? meta.message(raw) : meta.message
83
+ } : meta;
84
+ };
85
+ const matchBlocked = async (raw) => {
86
+ if (blocked.has(raw)) return;
87
+ const rule = uno.getBlocked(raw);
88
+ if (rule) {
89
+ blocked.set(raw, getMeta(raw, rule[1]));
90
+ return;
91
+ }
92
+ let current = raw;
93
+ for (const p of uno.config.preprocess) current = p(raw);
94
+ const rules = (await uno.matchVariants(raw, current)).map((r) => r && uno.getBlocked(r[1]));
95
+ for (const rule$1 of rules) if (rule$1) blocked.set(raw, getMeta(raw, rule$1[1]));
96
+ };
97
+ await Promise.all(values.map(matchBlocked));
98
+ return [...blocked];
116
99
  }
117
100
  async function runAsync(configPath, action, ...args) {
118
- switch (action) {
119
- case "sort":
120
- return actionSort(configPath, ...args);
121
- case "blocklist":
122
- return actionBlocklist(configPath, ...args);
123
- }
101
+ switch (action) {
102
+ case "sort": return actionSort(configPath, ...args);
103
+ case "blocklist": return actionBlocklist(configPath, ...args);
104
+ }
124
105
  }
125
106
  function run(configPath, action, ...args) {
126
- return runAsync(configPath, action, ...args);
107
+ return runAsync(configPath, action, ...args);
127
108
  }
128
109
  runAsWorker(run);
129
110
 
130
- export { getGenerator, run, runAsync, setGenerator };
111
+ //#endregion
112
+ 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.5.10-beta.1",
4
+ "version": "66.5.11",
5
5
  "description": "ESLint plugin for UnoCSS",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -22,12 +22,19 @@
22
22
  "sideEffects": false,
23
23
  "exports": {
24
24
  ".": {
25
- "import": "./dist/index.mjs",
26
- "require": "./dist/index.cjs"
25
+ "import": {
26
+ "types": "./dist/index.d.mts",
27
+ "default": "./dist/index.mjs"
28
+ },
29
+ "require": {
30
+ "types": "./dist/index.d.cts",
31
+ "default": "./dist/index.cjs"
32
+ }
27
33
  }
28
34
  },
29
35
  "main": "dist/index.cjs",
30
36
  "module": "dist/index.mjs",
37
+ "types": "dist/index.d.mts",
31
38
  "files": [
32
39
  "dist"
33
40
  ],
@@ -35,23 +42,22 @@
35
42
  "node": ">=14"
36
43
  },
37
44
  "dependencies": {
38
- "@typescript-eslint/utils": "^8.46.4",
45
+ "@typescript-eslint/utils": "^8.50.1",
39
46
  "magic-string": "^0.30.21",
40
47
  "synckit": "^0.11.11",
41
- "@unocss/config": "66.5.10-beta.1",
42
- "@unocss/core": "66.5.10-beta.1",
43
- "@unocss/rule-utils": "66.5.10-beta.1"
48
+ "@unocss/config": "66.5.11",
49
+ "@unocss/core": "66.5.11",
50
+ "@unocss/rule-utils": "66.5.11"
44
51
  },
45
52
  "devDependencies": {
46
53
  "@typescript/native-preview": "latest",
47
- "svelte-eslint-parser": "^1.4.0",
54
+ "svelte-eslint-parser": "^1.4.1",
48
55
  "vue-eslint-parser": "^10.2.0",
49
- "@unocss/eslint-plugin": "66.5.10-beta.1"
56
+ "@unocss/eslint-plugin": "66.5.11"
50
57
  },
51
58
  "scripts": {
52
- "build": "unbuild",
59
+ "build": "tsdown --config-loader unrun",
53
60
  "typecheck": "tsgo --noEmit",
54
- "lint": "nr build && cd ./fixtures && eslint ./src",
55
- "test:attw": "attw --pack"
61
+ "lint": "nr build && cd ./fixtures && eslint ./src"
56
62
  }
57
63
  }
package/dist/dirs.d.ts DELETED
@@ -1,3 +0,0 @@
1
- declare const distDir: string;
2
-
3
- export { distDir };
package/dist/index.d.ts DELETED
@@ -1,45 +0,0 @@
1
- import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
2
-
3
- declare module '@typescript-eslint/utils/ts-eslint' {
4
- interface SharedConfigurationSettings {
5
- unocss?: {
6
- configPath?: string;
7
- };
8
- }
9
- }
10
-
11
- declare const _default: {
12
- configs: {
13
- recommended: {
14
- plugins: string[];
15
- rules: {
16
- readonly '@unocss/order': "warn";
17
- readonly '@unocss/order-attributify': "warn";
18
- };
19
- };
20
- flat: {
21
- plugins: {
22
- unocss: {
23
- rules: {
24
- order: _typescript_eslint_utils_ts_eslint.AnyRuleModule;
25
- 'order-attributify': _typescript_eslint_utils_ts_eslint.AnyRuleModule;
26
- blocklist: _typescript_eslint_utils_ts_eslint.AnyRuleModule;
27
- 'enforce-class-compile': _typescript_eslint_utils_ts_eslint.AnyRuleModule;
28
- };
29
- };
30
- };
31
- rules: {
32
- readonly 'unocss/order': "warn";
33
- readonly 'unocss/order-attributify': "warn";
34
- };
35
- };
36
- };
37
- rules: {
38
- order: _typescript_eslint_utils_ts_eslint.AnyRuleModule;
39
- 'order-attributify': _typescript_eslint_utils_ts_eslint.AnyRuleModule;
40
- blocklist: _typescript_eslint_utils_ts_eslint.AnyRuleModule;
41
- 'enforce-class-compile': _typescript_eslint_utils_ts_eslint.AnyRuleModule;
42
- };
43
- };
44
-
45
- export = _default;