ist*_*ist 3 javascript syntax-checking typescript eslint tslint
我正在尝试检测具有相同索引的嵌套循环,如下所示:
for(let i = 0; i < 10; i++) {
for(let i = 0; i < 10; i++) {
}
}
Run Code Online (Sandbox Code Playgroud)
我已经搜索了 Eslint 规则,但到目前为止还没有找到任何解决方案。有没有办法检测这种糟糕的代码味道?非常感谢。
ESLint 有一个no-shadow规则可以标记它,以及其他你用内部作用域变量遮蔽外部作用域变量的地方。例如:
{
"no-shadow": ["error", { "builtinGlobals": false, "hoist": "functions", "allow": [] }]
}
Run Code Online (Sandbox Code Playgroud)
for(let i = 0; i < 10; i++) {
for(let i = 0; i < 10; i++) {
// ^????? 'i' is already declared in the upper scope on line 1 column 9.
console.log(i);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
71 次 |
| 最近记录: |