useWhile
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
¥Diagnostic Category:
lint/complexity/useWhile -
此规则包含 safe 修复程序。
¥This rule has a safe fix.
-
此规则的默认严重级别为 warning。
¥The default severity of this rule is warning.
-
来源:
¥Sources:
-
与
sonarjs/prefer-while相同¥Same as
sonarjs/prefer-while
-
¥How to configure
{ "linter": { "rules": { "complexity": { "useWhile": "error" } } }}¥Description
当不需要初始化程序和更新表达式时,强制使用 while 循环而不是 for 循环。
¥Enforce the use of while loops instead of for loops when the initializer and update expressions are not needed.
¥Examples
¥Invalid
for (; x.running;) { x.step();}code-block.js:1:1 lint/complexity/useWhile FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Use a while loop instead of a for loop.
> 1 │ for (; x.running;) {
│ ^^^^^^^^^^^^^^^^^^
2 │ x.step();
3 │ }
ℹ Prefer a while loop over a for loop without initialization and update.
ℹ Safe fix: Use a while loop.
1 │ - for·(;·x.running;)·{
1 │ + while·(x.running)·{
2 2 │ x.step();
3 3 │ }
¥Valid
for (let x = 0; x < 10; i++) {}let x = 0for (; x < 10; i++) {}for (let x = 0; x < 10;) { i++}¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号