useWhile
诊断类别:lint/style/useWhile
¥Diagnostic Category: lint/style/useWhile
自从:v1.0.0
¥Since: v1.0.0
来源:
¥Sources:
-
与以下相同:
sonarjs/prefer-while
¥Same as:
sonarjs/prefer-while
当不需要初始化程序和更新表达式时,强制使用 while
循环而不是 for
循环。
¥Enforce the use of while
loops instead of for
loops when the initializer and update expressions are not needed.
¥Examples
¥Invalid
code-block.js:1:1 lint/style/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
¥Related links