@lsby/eslint-plugin 0.0.2 → 0.0.3

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/README.md CHANGED
@@ -34,6 +34,7 @@
34
34
  ],
35
35
  rules: {
36
36
  '@lsby/no-broken-link': 'error',
37
+ '@lsby/prefer-let': 'error',
37
38
  },
38
39
  };
39
40
  ```
package/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  module.exports = {
2
2
  rules: {
3
3
  'no-broken-link': require('./lib/rules/no-broken-link'),
4
+ 'prefer-let': require('./lib/rules/prefer-let'),
4
5
  },
5
6
  }
@@ -0,0 +1,33 @@
1
+ module.exports = {
2
+ meta: {
3
+ type: 'suggestion',
4
+ docs: {
5
+ description: 'Replace const and var with let',
6
+ category: 'Best Practices',
7
+ recommended: false,
8
+ },
9
+ fixable: 'code',
10
+ schema: [], // 没有配置选项
11
+ },
12
+
13
+ create(context) {
14
+ return {
15
+ VariableDeclaration(node) {
16
+ // 检查变量声明的类型
17
+ if (node.kind === 'const' || node.kind === 'var') {
18
+ // 使用修复功能将 const 或 var 替换为 let
19
+ context.report({
20
+ node,
21
+ message: 'Use let instead of const or var',
22
+ fix(fixer) {
23
+ return fixer.replaceTextRange(
24
+ [node.start, node.start + node.kind.length],
25
+ 'let'
26
+ );
27
+ },
28
+ });
29
+ }
30
+ },
31
+ };
32
+ },
33
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lsby/eslint-plugin",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "pub:public": "bumpp && npm publish --access public",