@lsby/eslint-plugin 0.0.11 → 0.0.12
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/lib/rules/prefer-let.js +8 -3
- package/package.json +1 -1
package/lib/rules/prefer-let.js
CHANGED
|
@@ -13,16 +13,21 @@ module.exports = {
|
|
|
13
13
|
create(context) {
|
|
14
14
|
return {
|
|
15
15
|
VariableDeclaration(node) {
|
|
16
|
-
// 检查变量声明的类型(排除 declare)
|
|
17
16
|
if ((node.kind === 'const' || node.kind === 'var') && !node.declare) {
|
|
17
|
+
// 避免 unique symbol 类型
|
|
18
|
+
const hasUniqueSymbol = node.declarations.some(
|
|
19
|
+
(decl) => decl.id.typeAnnotation?.typeAnnotation.type === 'TSUniqueKeyword',
|
|
20
|
+
)
|
|
21
|
+
if (hasUniqueSymbol) {
|
|
22
|
+
return // 跳过 unique symbol
|
|
23
|
+
}
|
|
24
|
+
|
|
18
25
|
// 使用修复功能将 const 或 var 替换为 let
|
|
19
26
|
context.report({
|
|
20
27
|
node,
|
|
21
28
|
message: '使用let代替const或var',
|
|
22
29
|
fix(fixer) {
|
|
23
|
-
// 获取变量声明的范围
|
|
24
30
|
const range = node.range
|
|
25
|
-
// 确保给定的 range 是有效的
|
|
26
31
|
return fixer.replaceTextRange([range[0], range[0] + node.kind.length], 'let')
|
|
27
32
|
},
|
|
28
33
|
})
|