eslint-plugin-light 1.0.14 → 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,3 +1,9 @@
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
+
1
7
  ## <small>1.0.14 (2025-06-11)</small>
2
8
 
3
9
  * feat(eslint-plugin-light): 优化classname-per-line ([fa99594](https://github.com/novlan1/plugin-light/commits/fa99594))
package/README.md CHANGED
@@ -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)
@@ -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.14",
3
+ "version": "1.0.15",
4
4
  "description": "Simple Eslint Plugin",
5
5
  "keywords": [
6
6
  "eslint",