@unocss/eslint-plugin 0.59.4 → 0.60.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,4 +1,4 @@
1
- 'use strict';Object.defineProperty(exports, '__esModule', {value: true});
1
+ 'use strict';
2
2
 
3
3
  const MagicString = require('magic-string');
4
4
  const node_path = require('node:path');
@@ -48,7 +48,11 @@ const orderAttributify = createRule({
48
48
  if (!valueless.length)
49
49
  return;
50
50
  const input = valueless.map((i) => i.key.name).join(" ").trim();
51
- const sorted = syncAction("sort", input);
51
+ const sorted = syncAction(
52
+ context.settings.unocss?.configPath,
53
+ "sort",
54
+ input
55
+ );
52
56
  if (sorted !== input) {
53
57
  context.report({
54
58
  node,
@@ -100,7 +104,11 @@ const order = createRule({
100
104
  if (typeof node.value !== "string" || !node.value.trim())
101
105
  return;
102
106
  const input = node.value;
103
- const sorted = syncAction("sort", input).trim();
107
+ const sorted = syncAction(
108
+ context.settings.unocss?.configPath,
109
+ "sort",
110
+ input
111
+ ).trim();
104
112
  if (sorted !== input) {
105
113
  context.report({
106
114
  node,
@@ -155,7 +163,7 @@ const blocklist = createRule({
155
163
  recommended: "recommended"
156
164
  },
157
165
  messages: {
158
- "in-blocklist": "Utility '{{ name }}' is in blocklist"
166
+ "in-blocklist": '"{{name}}" is in blocklist{{reason}}'
159
167
  },
160
168
  schema: []
161
169
  },
@@ -165,13 +173,19 @@ const blocklist = createRule({
165
173
  if (typeof node.value !== "string" || !node.value.trim())
166
174
  return;
167
175
  const input = node.value;
168
- const blocked = syncAction("blocklist", input, context.filename);
169
- blocked.forEach((i) => {
176
+ const blocked = syncAction(
177
+ context.settings.unocss?.configPath,
178
+ "blocklist",
179
+ input,
180
+ context.filename
181
+ );
182
+ blocked.forEach(([name, meta]) => {
170
183
  context.report({
171
184
  node,
172
185
  messageId: "in-blocklist",
173
186
  data: {
174
- name: i
187
+ name,
188
+ reason: meta?.message ? `: ${meta.message}` : ""
175
189
  }
176
190
  });
177
191
  });
@@ -205,13 +219,19 @@ const blocklist = createRule({
205
219
  for (const node2 of valueless) {
206
220
  if (!node2?.key?.name)
207
221
  continue;
208
- const blocked = syncAction("blocklist", node2.key.name, context.filename);
209
- blocked.forEach((i) => {
222
+ const blocked = syncAction(
223
+ context.settings.unocss?.configPath,
224
+ "blocklist",
225
+ node2.key.name,
226
+ context.filename
227
+ );
228
+ blocked.forEach(([name, meta]) => {
210
229
  context.report({
211
230
  node: node2,
212
231
  messageId: "in-blocklist",
213
232
  data: {
214
- name: i
233
+ name,
234
+ reason: meta?.message ? `: ${meta.message}` : ""
215
235
  }
216
236
  });
217
237
  });
@@ -350,4 +370,4 @@ const index = {
350
370
  }
351
371
  };
352
372
 
353
- exports.default = index;
373
+ module.exports = index;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,13 @@
1
1
  import * as _typescript_eslint_utils_eslint_utils from '@typescript-eslint/utils/eslint-utils';
2
2
 
3
+ declare module '@typescript-eslint/utils/ts-eslint' {
4
+ interface SharedConfigurationSettings {
5
+ unocss?: {
6
+ configPath?: string;
7
+ };
8
+ }
9
+ }
10
+
3
11
  declare const _default: {
4
12
  configs: {
5
13
  recommended: {
@@ -34,4 +42,4 @@ declare const _default: {
34
42
  };
35
43
  };
36
44
 
37
- export { _default as default };
45
+ export = _default;
package/dist/index.d.mts CHANGED
@@ -1,5 +1,13 @@
1
1
  import * as _typescript_eslint_utils_eslint_utils from '@typescript-eslint/utils/eslint-utils';
2
2
 
3
+ declare module '@typescript-eslint/utils/ts-eslint' {
4
+ interface SharedConfigurationSettings {
5
+ unocss?: {
6
+ configPath?: string;
7
+ };
8
+ }
9
+ }
10
+
3
11
  declare const _default: {
4
12
  configs: {
5
13
  recommended: {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,13 @@
1
1
  import * as _typescript_eslint_utils_eslint_utils from '@typescript-eslint/utils/eslint-utils';
2
2
 
3
+ declare module '@typescript-eslint/utils/ts-eslint' {
4
+ interface SharedConfigurationSettings {
5
+ unocss?: {
6
+ configPath?: string;
7
+ };
8
+ }
9
+ }
10
+
3
11
  declare const _default: {
4
12
  configs: {
5
13
  recommended: {
@@ -34,4 +42,4 @@ declare const _default: {
34
42
  };
35
43
  };
36
44
 
37
- export { _default as default };
45
+ export = _default;
package/dist/index.mjs CHANGED
@@ -42,7 +42,11 @@ const orderAttributify = createRule({
42
42
  if (!valueless.length)
43
43
  return;
44
44
  const input = valueless.map((i) => i.key.name).join(" ").trim();
45
- const sorted = syncAction("sort", input);
45
+ const sorted = syncAction(
46
+ context.settings.unocss?.configPath,
47
+ "sort",
48
+ input
49
+ );
46
50
  if (sorted !== input) {
47
51
  context.report({
48
52
  node,
@@ -94,7 +98,11 @@ const order = createRule({
94
98
  if (typeof node.value !== "string" || !node.value.trim())
95
99
  return;
96
100
  const input = node.value;
97
- const sorted = syncAction("sort", input).trim();
101
+ const sorted = syncAction(
102
+ context.settings.unocss?.configPath,
103
+ "sort",
104
+ input
105
+ ).trim();
98
106
  if (sorted !== input) {
99
107
  context.report({
100
108
  node,
@@ -149,7 +157,7 @@ const blocklist = createRule({
149
157
  recommended: "recommended"
150
158
  },
151
159
  messages: {
152
- "in-blocklist": "Utility '{{ name }}' is in blocklist"
160
+ "in-blocklist": '"{{name}}" is in blocklist{{reason}}'
153
161
  },
154
162
  schema: []
155
163
  },
@@ -159,13 +167,19 @@ const blocklist = createRule({
159
167
  if (typeof node.value !== "string" || !node.value.trim())
160
168
  return;
161
169
  const input = node.value;
162
- const blocked = syncAction("blocklist", input, context.filename);
163
- blocked.forEach((i) => {
170
+ const blocked = syncAction(
171
+ context.settings.unocss?.configPath,
172
+ "blocklist",
173
+ input,
174
+ context.filename
175
+ );
176
+ blocked.forEach(([name, meta]) => {
164
177
  context.report({
165
178
  node,
166
179
  messageId: "in-blocklist",
167
180
  data: {
168
- name: i
181
+ name,
182
+ reason: meta?.message ? `: ${meta.message}` : ""
169
183
  }
170
184
  });
171
185
  });
@@ -199,13 +213,19 @@ const blocklist = createRule({
199
213
  for (const node2 of valueless) {
200
214
  if (!node2?.key?.name)
201
215
  continue;
202
- const blocked = syncAction("blocklist", node2.key.name, context.filename);
203
- blocked.forEach((i) => {
216
+ const blocked = syncAction(
217
+ context.settings.unocss?.configPath,
218
+ "blocklist",
219
+ node2.key.name,
220
+ context.filename
221
+ );
222
+ blocked.forEach(([name, meta]) => {
204
223
  context.report({
205
224
  node: node2,
206
225
  messageId: "in-blocklist",
207
226
  data: {
208
- name: i
227
+ name,
228
+ reason: meta?.message ? `: ${meta.message}` : ""
209
229
  }
210
230
  });
211
231
  });
package/dist/worker.mjs CHANGED
@@ -31,10 +31,13 @@ async function sortRules(rules, uno) {
31
31
  }
32
32
 
33
33
  var _a;
34
- let promise;
34
+ const promises = /* @__PURE__ */ new Map();
35
35
  (_a = process.env).ESLINT || (_a.ESLINT = "true");
36
- async function _getGenerator() {
37
- const { config, sources } = await loadConfig();
36
+ async function _getGenerator(configPath) {
37
+ const { config, sources } = await loadConfig(
38
+ process.cwd(),
39
+ configPath
40
+ );
38
41
  if (!sources.length)
39
42
  throw new Error("[@unocss/eslint-plugin] No config file found, create a `uno.config.ts` file in your project root and try again.");
40
43
  return createGenerator({
@@ -42,48 +45,54 @@ async function _getGenerator() {
42
45
  warn: false
43
46
  });
44
47
  }
45
- async function getGenerator() {
46
- promise = promise || _getGenerator();
48
+ async function getGenerator(configPath) {
49
+ let promise = promises.get(configPath);
50
+ if (!promise) {
51
+ promise = _getGenerator(configPath);
52
+ promises.set(configPath, promise);
53
+ }
47
54
  return await promise;
48
55
  }
49
- function setGenerator(generator) {
50
- promise = Promise.resolve(generator);
56
+ function setGenerator(generator, configPath) {
57
+ promises.set(configPath, Promise.resolve(generator));
51
58
  }
52
- async function actionSort(classes) {
53
- return await sortRules(classes, await getGenerator());
59
+ async function actionSort(configPath, classes) {
60
+ return await sortRules(classes, await getGenerator(configPath));
54
61
  }
55
- async function actionBlocklist(classes, id) {
56
- const uno = await getGenerator();
57
- const blocked = /* @__PURE__ */ new Set();
62
+ async function actionBlocklist(configPath, classes, id) {
63
+ const uno = await getGenerator(configPath);
64
+ const blocked = /* @__PURE__ */ new Map();
58
65
  const extracted = await uno.applyExtractors(classes, id);
59
66
  const values = [...extracted.values()];
60
67
  const matchBlocked = async (raw) => {
61
68
  if (blocked.has(raw))
62
69
  return;
63
- if (uno.isBlocked(raw)) {
64
- blocked.add(raw);
70
+ let rule = uno.getBlocked(raw);
71
+ if (rule) {
72
+ blocked.set(raw, rule[1]);
65
73
  return;
66
74
  }
67
75
  let current = raw;
68
76
  for (const p of uno.config.preprocess)
69
77
  current = p(raw);
70
78
  const applied = await uno.matchVariants(raw, current);
71
- if (applied && uno.isBlocked(applied[1]))
72
- blocked.add(raw);
79
+ rule = applied && uno.getBlocked(applied[1]);
80
+ if (rule)
81
+ blocked.set(raw, rule[1]);
73
82
  };
74
83
  await Promise.all(values.map(matchBlocked));
75
84
  return [...blocked];
76
85
  }
77
- async function runAsync(action, ...args) {
86
+ async function runAsync(configPath, action, ...args) {
78
87
  switch (action) {
79
88
  case "sort":
80
- return actionSort(...args);
89
+ return actionSort(configPath, ...args);
81
90
  case "blocklist":
82
- return actionBlocklist(...args);
91
+ return actionBlocklist(configPath, ...args);
83
92
  }
84
93
  }
85
- function run(action, ...args) {
86
- return runAsync(action, ...args);
94
+ function run(configPath, action, ...args) {
95
+ return runAsync(configPath, action, ...args);
87
96
  }
88
97
  runAsWorker(run);
89
98
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unocss/eslint-plugin",
3
3
  "type": "module",
4
- "version": "0.59.4",
4
+ "version": "0.60.1",
5
5
  "description": "ESLint plugin for UnoCSS",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -35,15 +35,15 @@
35
35
  "node": ">=14"
36
36
  },
37
37
  "dependencies": {
38
- "@typescript-eslint/utils": "^7.7.0",
38
+ "@typescript-eslint/utils": "^7.8.0",
39
39
  "magic-string": "^0.30.10",
40
40
  "synckit": "^0.9.0",
41
- "@unocss/core": "0.59.4",
42
- "@unocss/config": "0.59.4"
41
+ "@unocss/core": "0.60.1",
42
+ "@unocss/config": "0.60.1"
43
43
  },
44
44
  "devDependencies": {
45
45
  "vue-eslint-parser": "^9.4.2",
46
- "@unocss/eslint-plugin": "0.59.4"
46
+ "@unocss/eslint-plugin": "0.60.1"
47
47
  },
48
48
  "scripts": {
49
49
  "build": "unbuild",