eslint-plugin-light 1.0.12 → 1.0.15

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/CHANGELOG.md CHANGED
@@ -1,6 +1,25 @@
1
+ ## <small>1.0.15 (2025-06-16)</small>
2
+
3
+ * feat(eslint-plugin-light): add img v-lazy ([5807b47](https://github.com/novlan1/plugin-light/commits/5807b47))
4
+
5
+
6
+
7
+ ## <small>1.0.14 (2025-06-11)</small>
8
+
9
+ * feat(eslint-plugin-light): 优化classname-per-line ([fa99594](https://github.com/novlan1/plugin-light/commits/fa99594))
10
+
11
+
12
+
13
+ ## <small>1.0.13 (2025-06-10)</small>
14
+
15
+ * feat(eslint-plugin-light): 优化规则名称 ([73affad](https://github.com/novlan1/plugin-light/commits/73affad))
16
+ * chore: update t-comm@1.5.40 ([d019355](https://github.com/novlan1/plugin-light/commits/d019355))
17
+
18
+
19
+
1
20
  ## <small>1.0.12 (2025-05-30)</small>
2
21
 
3
- * feat(eslint-plugin-light): add css-per-line rule ([bc1d247](https://github.com/novlan1/plugin-light/commits/bc1d247))
22
+ * feat(eslint-plugin-light): add classname-per-line rule ([bc1d247](https://github.com/novlan1/plugin-light/commits/bc1d247))
4
23
 
5
24
 
6
25
 
package/README.md CHANGED
@@ -387,7 +387,7 @@ module.exports = {
387
387
  }
388
388
  ```
389
389
 
390
- ### 3.11. css-per-line
390
+ ### 3.11. classname-per-line
391
391
 
392
392
  限制 Vue 中每行只有`1`个CSS类名,可以配置阈值。
393
393
 
@@ -401,7 +401,7 @@ module.exports = {
401
401
  'light',
402
402
  ],
403
403
  rules: {
404
- 'light/css-per-line': 2,
404
+ 'light/classname-per-line': 2,
405
405
  },
406
406
  }
407
407
  ```
@@ -412,6 +412,25 @@ module.exports = {
412
412
  | ------ | -------------------------------- | ------ |
413
413
  | counts | 检查阈值,小于阈值时,可以在一行 | `3` |
414
414
 
415
+ ### 3.12. img-v-lazy
416
+
417
+ 强制 `img` 标签使用 `v-lazy` 而不是 `:src`。
418
+
419
+ Usage:
420
+
421
+ ```js
422
+ // .eslintrc.js
423
+
424
+ module.exports = {
425
+ plugins: [
426
+ 'light',
427
+ ],
428
+ rules: {
429
+ 'light/img-v-lazy': 2,
430
+ },
431
+ }
432
+ ```
433
+
415
434
  ## 4. 更新日志
416
435
 
417
436
  [点此查看](./CHANGELOG.md)
@@ -40,7 +40,7 @@ module.exports = {
40
40
  const classValue = node.value.value.trim();
41
41
 
42
42
  // 检查是否已经是多行格式
43
- if (isAlreadyMultiLine(text)) {
43
+ if (isAlreadyMultiLine(text, threshold)) {
44
44
  return;
45
45
  }
46
46
 
@@ -88,8 +88,11 @@ function getQuoteChars(sourceCode, node) {
88
88
  }
89
89
 
90
90
 
91
- function isAlreadyMultiLine(text) {
91
+ function isAlreadyMultiLine(text, threshold) {
92
92
  const lines = text.split('\n');
93
+
94
+ const bad = lines.find(line => line.split(/\s+/).length > threshold);
95
+
93
96
  // 多于1行且不是空行
94
- return lines.length > 1 && lines.some(line => line.trim().length > 0);
97
+ return lines.length > 1 && lines.some(line => line.trim().length > 0) && !bad;
95
98
  }
@@ -0,0 +1,56 @@
1
+ const utils = require('eslint-plugin-vue/lib/utils');
2
+
3
+ module.exports = {
4
+ meta: {
5
+ type: 'problem',
6
+ docs: {
7
+ description: 'Enforce using v-lazy instead of :src on img tags',
8
+ category: 'Best Practices',
9
+ recommended: true,
10
+ },
11
+ fixable: 'code',
12
+ schema: [],
13
+ },
14
+ create(context) {
15
+ return utils.defineTemplateBodyVisitor(context, {
16
+ 'VElement[name=\'img\']'(node) {
17
+ const srcBinding = node.startTag.attributes.find(attr => attr.directive
18
+ && attr.key.name
19
+ && attr.key.name.name === 'bind'
20
+ && attr.key.argument
21
+ && attr.key.argument.name === 'src');
22
+
23
+
24
+ const hasVLazy = node.startTag.attributes.some(attr => attr.directive
25
+ && attr.key.name.name === 'lazy');
26
+
27
+ if (srcBinding && !hasVLazy) {
28
+ context.report({
29
+ node,
30
+ message: 'Use v-lazy instead of :src for image loading',
31
+ fix(fixer) {
32
+ // 获取 :src 绑定的完整表达式文本
33
+ const srcText = context.getSourceCode().getText(srcBinding.value.expression);
34
+
35
+ // 获取 :src 属性的完整文本
36
+ const fullSrcText = context.getSourceCode().getText(srcBinding);
37
+
38
+ // 计算替换文本
39
+ let replacement;
40
+ if (fullSrcText.startsWith(':')) {
41
+ replacement = `v-lazy="${srcText}"`;
42
+ } else if (fullSrcText.startsWith('v-bind:')) {
43
+ replacement = `v-lazy="${srcText}"`;
44
+ } else {
45
+ replacement = `v-lazy="${srcText}"`;
46
+ }
47
+
48
+ // 精确替换,不添加额外空格
49
+ return fixer.replaceText(srcBinding, replacement);
50
+ },
51
+ });
52
+ }
53
+ },
54
+ });
55
+ },
56
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-light",
3
- "version": "1.0.12",
3
+ "version": "1.0.15",
4
4
  "description": "Simple Eslint Plugin",
5
5
  "keywords": [
6
6
  "eslint",
@@ -8,7 +8,7 @@
8
8
  "eslint-plugin",
9
9
  "eslint-plugin-light"
10
10
  ],
11
- "homepage": "https://novlan1.github.io/plugin-light/zh/eslint-plugin-light.html",
11
+ "homepage": "https://novlan1.github.io/docs/plugin-light/zh/eslint-plugin-light.html",
12
12
  "bugs": {
13
13
  "url": "https://github.com/novlan1/plugin-light/issues"
14
14
  },