@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 +1 -0
- package/index.js +1 -0
- package/lib/rules/prefer-let.js +33 -0
- package/package.json +1 -1
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -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
|
+
};
|