@unocss/eslint-plugin 0.58.5 → 0.58.6

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
@@ -224,11 +224,107 @@ const blocklist = createRule({
224
224
  }
225
225
  });
226
226
 
227
+ const enforceClassCompile = createRule({
228
+ name: "enforce-class-compile",
229
+ meta: {
230
+ type: "problem",
231
+ fixable: "code",
232
+ docs: {
233
+ description: "Enforce class compilation"
234
+ },
235
+ messages: {
236
+ missing: "prefix: `{{prefix}}` is missing"
237
+ },
238
+ schema: [{
239
+ type: "object",
240
+ properties: {
241
+ prefix: {
242
+ type: "string"
243
+ },
244
+ enableFix: {
245
+ type: "boolean"
246
+ }
247
+ },
248
+ additionalProperties: false
249
+ }]
250
+ },
251
+ defaultOptions: [{ prefix: ":uno:", enableFix: true }],
252
+ create(context, [mergedOptions]) {
253
+ const CLASS_COMPILE_PREFIX = `${mergedOptions.prefix} `;
254
+ const ENABLE_FIX = mergedOptions.enableFix;
255
+ function report({ node, fix }) {
256
+ context.report({
257
+ node,
258
+ loc: node.loc,
259
+ messageId: "missing",
260
+ data: { prefix: CLASS_COMPILE_PREFIX.trim() },
261
+ fix: (...args) => ENABLE_FIX ? fix(...args) : null
262
+ });
263
+ }
264
+ const scriptVisitor = {
265
+ JSXAttribute(_node) {
266
+ },
267
+ SvelteAttribute(_node) {
268
+ }
269
+ };
270
+ const reportClassList = (node, classList) => {
271
+ if (classList.startsWith(CLASS_COMPILE_PREFIX))
272
+ return;
273
+ report({
274
+ node,
275
+ fix(fixer) {
276
+ return fixer.replaceTextRange([node.range[0] + 1, node.range[1] - 1], `${CLASS_COMPILE_PREFIX}${classList}`);
277
+ }
278
+ });
279
+ };
280
+ const templateBodyVisitor = {
281
+ [`VAttribute[key.name=class]`](attr) {
282
+ const valueNode = attr.value;
283
+ if (!valueNode || !valueNode.value)
284
+ return;
285
+ reportClassList(valueNode, valueNode.value);
286
+ },
287
+ [`VAttribute[key.argument.name=class] VExpressionContainer Literal:not(ConditionalExpression .test Literal):not(Property .value Literal)`](literal) {
288
+ if (!literal.value || typeof literal.value !== "string")
289
+ return;
290
+ reportClassList(literal, literal.value);
291
+ },
292
+ [`VAttribute[key.argument.name=class] VExpressionContainer TemplateElement`](templateElement) {
293
+ if (!templateElement.value.raw)
294
+ return;
295
+ reportClassList(templateElement, templateElement.value.raw);
296
+ },
297
+ [`VAttribute[key.argument.name=class] VExpressionContainer Property`](property) {
298
+ if (property.key.type !== "Identifier")
299
+ return;
300
+ const classListString = property.key.name;
301
+ if (classListString.startsWith(CLASS_COMPILE_PREFIX))
302
+ return;
303
+ report({
304
+ node: property.key,
305
+ fix(fixer) {
306
+ let replacePropertyKeyText = `'${CLASS_COMPILE_PREFIX}${classListString}'`;
307
+ if (property.shorthand)
308
+ replacePropertyKeyText = `${replacePropertyKeyText}: ${classListString}`;
309
+ return fixer.replaceTextRange(property.key.range, replacePropertyKeyText);
310
+ }
311
+ });
312
+ }
313
+ };
314
+ if (context.parserServices == null || context.parserServices.defineTemplateBodyVisitor == null) {
315
+ return scriptVisitor;
316
+ } else {
317
+ return context.parserServices?.defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor);
318
+ }
319
+ }
320
+ });
321
+
227
322
  const plugin = {
228
323
  rules: {
229
324
  order,
230
325
  "order-attributify": orderAttributify,
231
- blocklist
326
+ blocklist,
327
+ "enforce-class-compile": enforceClassCompile
232
328
  }
233
329
  };
234
330
 
package/dist/index.d.cts CHANGED
@@ -16,6 +16,7 @@ declare const _default: {
16
16
  order: _typescript_eslint_utils_eslint_utils.RuleWithMeta<[], "">;
17
17
  'order-attributify': _typescript_eslint_utils_eslint_utils.RuleWithMeta<[], "">;
18
18
  blocklist: _typescript_eslint_utils_eslint_utils.RuleWithMeta<[], "">;
19
+ 'enforce-class-compile': _typescript_eslint_utils_eslint_utils.RuleWithMeta<[], "">;
19
20
  };
20
21
  };
21
22
  };
@@ -29,6 +30,7 @@ declare const _default: {
29
30
  order: _typescript_eslint_utils_eslint_utils.RuleWithMeta<[], "">;
30
31
  'order-attributify': _typescript_eslint_utils_eslint_utils.RuleWithMeta<[], "">;
31
32
  blocklist: _typescript_eslint_utils_eslint_utils.RuleWithMeta<[], "">;
33
+ 'enforce-class-compile': _typescript_eslint_utils_eslint_utils.RuleWithMeta<[], "">;
32
34
  };
33
35
  };
34
36
 
package/dist/index.d.mts CHANGED
@@ -16,6 +16,7 @@ declare const _default: {
16
16
  order: _typescript_eslint_utils_eslint_utils.RuleWithMeta<[], "">;
17
17
  'order-attributify': _typescript_eslint_utils_eslint_utils.RuleWithMeta<[], "">;
18
18
  blocklist: _typescript_eslint_utils_eslint_utils.RuleWithMeta<[], "">;
19
+ 'enforce-class-compile': _typescript_eslint_utils_eslint_utils.RuleWithMeta<[], "">;
19
20
  };
20
21
  };
21
22
  };
@@ -29,6 +30,7 @@ declare const _default: {
29
30
  order: _typescript_eslint_utils_eslint_utils.RuleWithMeta<[], "">;
30
31
  'order-attributify': _typescript_eslint_utils_eslint_utils.RuleWithMeta<[], "">;
31
32
  blocklist: _typescript_eslint_utils_eslint_utils.RuleWithMeta<[], "">;
33
+ 'enforce-class-compile': _typescript_eslint_utils_eslint_utils.RuleWithMeta<[], "">;
32
34
  };
33
35
  };
34
36
 
package/dist/index.d.ts CHANGED
@@ -16,6 +16,7 @@ declare const _default: {
16
16
  order: _typescript_eslint_utils_eslint_utils.RuleWithMeta<[], "">;
17
17
  'order-attributify': _typescript_eslint_utils_eslint_utils.RuleWithMeta<[], "">;
18
18
  blocklist: _typescript_eslint_utils_eslint_utils.RuleWithMeta<[], "">;
19
+ 'enforce-class-compile': _typescript_eslint_utils_eslint_utils.RuleWithMeta<[], "">;
19
20
  };
20
21
  };
21
22
  };
@@ -29,6 +30,7 @@ declare const _default: {
29
30
  order: _typescript_eslint_utils_eslint_utils.RuleWithMeta<[], "">;
30
31
  'order-attributify': _typescript_eslint_utils_eslint_utils.RuleWithMeta<[], "">;
31
32
  blocklist: _typescript_eslint_utils_eslint_utils.RuleWithMeta<[], "">;
33
+ 'enforce-class-compile': _typescript_eslint_utils_eslint_utils.RuleWithMeta<[], "">;
32
34
  };
33
35
  };
34
36
 
package/dist/index.mjs CHANGED
@@ -218,11 +218,107 @@ const blocklist = createRule({
218
218
  }
219
219
  });
220
220
 
221
+ const enforceClassCompile = createRule({
222
+ name: "enforce-class-compile",
223
+ meta: {
224
+ type: "problem",
225
+ fixable: "code",
226
+ docs: {
227
+ description: "Enforce class compilation"
228
+ },
229
+ messages: {
230
+ missing: "prefix: `{{prefix}}` is missing"
231
+ },
232
+ schema: [{
233
+ type: "object",
234
+ properties: {
235
+ prefix: {
236
+ type: "string"
237
+ },
238
+ enableFix: {
239
+ type: "boolean"
240
+ }
241
+ },
242
+ additionalProperties: false
243
+ }]
244
+ },
245
+ defaultOptions: [{ prefix: ":uno:", enableFix: true }],
246
+ create(context, [mergedOptions]) {
247
+ const CLASS_COMPILE_PREFIX = `${mergedOptions.prefix} `;
248
+ const ENABLE_FIX = mergedOptions.enableFix;
249
+ function report({ node, fix }) {
250
+ context.report({
251
+ node,
252
+ loc: node.loc,
253
+ messageId: "missing",
254
+ data: { prefix: CLASS_COMPILE_PREFIX.trim() },
255
+ fix: (...args) => ENABLE_FIX ? fix(...args) : null
256
+ });
257
+ }
258
+ const scriptVisitor = {
259
+ JSXAttribute(_node) {
260
+ },
261
+ SvelteAttribute(_node) {
262
+ }
263
+ };
264
+ const reportClassList = (node, classList) => {
265
+ if (classList.startsWith(CLASS_COMPILE_PREFIX))
266
+ return;
267
+ report({
268
+ node,
269
+ fix(fixer) {
270
+ return fixer.replaceTextRange([node.range[0] + 1, node.range[1] - 1], `${CLASS_COMPILE_PREFIX}${classList}`);
271
+ }
272
+ });
273
+ };
274
+ const templateBodyVisitor = {
275
+ [`VAttribute[key.name=class]`](attr) {
276
+ const valueNode = attr.value;
277
+ if (!valueNode || !valueNode.value)
278
+ return;
279
+ reportClassList(valueNode, valueNode.value);
280
+ },
281
+ [`VAttribute[key.argument.name=class] VExpressionContainer Literal:not(ConditionalExpression .test Literal):not(Property .value Literal)`](literal) {
282
+ if (!literal.value || typeof literal.value !== "string")
283
+ return;
284
+ reportClassList(literal, literal.value);
285
+ },
286
+ [`VAttribute[key.argument.name=class] VExpressionContainer TemplateElement`](templateElement) {
287
+ if (!templateElement.value.raw)
288
+ return;
289
+ reportClassList(templateElement, templateElement.value.raw);
290
+ },
291
+ [`VAttribute[key.argument.name=class] VExpressionContainer Property`](property) {
292
+ if (property.key.type !== "Identifier")
293
+ return;
294
+ const classListString = property.key.name;
295
+ if (classListString.startsWith(CLASS_COMPILE_PREFIX))
296
+ return;
297
+ report({
298
+ node: property.key,
299
+ fix(fixer) {
300
+ let replacePropertyKeyText = `'${CLASS_COMPILE_PREFIX}${classListString}'`;
301
+ if (property.shorthand)
302
+ replacePropertyKeyText = `${replacePropertyKeyText}: ${classListString}`;
303
+ return fixer.replaceTextRange(property.key.range, replacePropertyKeyText);
304
+ }
305
+ });
306
+ }
307
+ };
308
+ if (context.parserServices == null || context.parserServices.defineTemplateBodyVisitor == null) {
309
+ return scriptVisitor;
310
+ } else {
311
+ return context.parserServices?.defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor);
312
+ }
313
+ }
314
+ });
315
+
221
316
  const plugin = {
222
317
  rules: {
223
318
  order,
224
319
  "order-attributify": orderAttributify,
225
- blocklist
320
+ blocklist,
321
+ "enforce-class-compile": enforceClassCompile
226
322
  }
227
323
  };
228
324
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/eslint-plugin",
3
- "version": "0.58.5",
3
+ "version": "0.58.6",
4
4
  "description": "ESLint plugin for UnoCSS",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -34,14 +34,15 @@
34
34
  "node": ">=14"
35
35
  },
36
36
  "dependencies": {
37
- "@typescript-eslint/utils": "^6.20.0",
38
- "magic-string": "^0.30.6",
37
+ "@typescript-eslint/utils": "^7.2.0",
38
+ "magic-string": "^0.30.8",
39
39
  "synckit": "^0.9.0",
40
- "@unocss/config": "0.58.5",
41
- "@unocss/core": "0.58.5"
40
+ "@unocss/config": "0.58.6",
41
+ "@unocss/core": "0.58.6"
42
42
  },
43
43
  "devDependencies": {
44
- "@unocss/eslint-plugin": "0.58.5"
44
+ "vue-eslint-parser": "^9.4.2",
45
+ "@unocss/eslint-plugin": "0.58.6"
45
46
  },
46
47
  "scripts": {
47
48
  "build": "unbuild",