noNegationElse
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
诊断类别:
lint/style/noNegationElse¥Diagnostic Category:
lint/style/noNegationElse -
此规则包含 safe 修复程序。
¥This rule has a safe fix.
-
此规则的默认严重级别为 information。
¥The default severity of this rule is information.
-
来源:
¥Sources:
-
与
no-negated-condition相同¥Same as
no-negated-condition -
与
if_not_else相同¥Same as
if_not_else
-
¥How to configure
{ "linter": { "rules": { "style": { "noNegationElse": "error" } } }}¥Description
如果 if 语句有 else 子句,则禁止在 if 语句的条件中使用否定。
¥Disallow negation in the condition of an if statement if it has an else clause.
¥Examples
¥Invalid
if (!cond) { f();} else { g();}code-block.js:1:1 lint/style/noNegationElse FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Invert blocks when performing a negation test.
> 1 │ if (!cond) { f();} else { g();}
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Safe fix: Invert the condition and the blocks.
1 │ - if·(!cond)·{·f();}·else·{·g();}
1 │ + if·(cond)·{·g();}·else·{·f();}
2 2 │
!cond ? 0 : 1code-block.js:1:1 lint/style/noNegationElse FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Invert blocks when performing a negation test.
> 1 │ !cond ? 0 : 1
│ ^^^^^^^^^^^^^
2 │
ℹ Safe fix: Invert the condition and the blocks.
1 │ - !cond·?·0·:·1
1 │ + cond·?·1·:·0
2 2 │
¥Valid
if (!cond) { f(); }cond ? 1 : 0if (!cond) { f(); }if (!!val) { f(); } else { g(); }¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号