noConstantCondition
诊断类别:lint/correctness/noConstantCondition
¥Diagnostic Category: lint/correctness/noConstantCondition
自从:v1.0.0
¥Since: v1.0.0
来源:
¥Sources:
-
与以下相同:
no-constant-condition
¥Same as:
no-constant-condition
禁止在条件中使用常量表达式
¥Disallow constant expressions in conditions
¥Examples
¥Invalid
code-block.js:1:5 lint/correctness/noConstantCondition ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Unexpected constant condition.
> 1 │ if (false) {
│ ^^^^^
2 │ doSomethingUnfinished();
3 │ }
code-block.js:1:5 lint/correctness/noConstantCondition ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Unexpected constant condition.
> 1 │ if (Boolean(1)) {
│ ^^^^^^^^^^
2 │ doSomethingAlways();
3 │ }
code-block.js:1:5 lint/correctness/noConstantCondition ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Unexpected constant condition.
> 1 │ if (undefined) {
│ ^^^^^^^^^
2 │ doSomethingUnfinished();
3 │ }
code-block.js:1:7 lint/correctness/noConstantCondition ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Unexpected constant condition.
> 1 │ for (;-2;) {
│ ^^
2 │ doSomethingForever();
3 │ }
code-block.js:1:8 lint/correctness/noConstantCondition ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Unexpected constant condition.
> 1 │ while (typeof x) {
│ ^^^^^^^^
2 │ doSomethingForever();
3 │ }
code-block.js:1:14 lint/correctness/noConstantCondition ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Unexpected constant condition.
> 1 │ var result = 0 ? a : b;
│ ^
2 │
¥Valid
¥Related links