noExtraBooleanCast
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
诊断类别:
lint/complexity/noExtraBooleanCast¥Diagnostic Category:
lint/complexity/noExtraBooleanCast -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则包含 safe 修复程序。
¥This rule has a safe fix.
-
此规则的默认严重级别为 information。
¥The default severity of this rule is information.
-
来源:
¥Sources:
-
¥Same as
no-extra-boolean-cast
-
¥How to configure
{ "linter": { "rules": { "complexity": { "noExtraBooleanCast": "error" } } }}¥Description
禁止不必要的布尔转换
¥Disallow unnecessary boolean casts
¥Examples
¥Invalid
if (!Boolean(foo)) {}code-block.js:1:6 lint/complexity/noExtraBooleanCast FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Avoid redundant `Boolean` call
> 1 │ if (!Boolean(foo)) {
│ ^^^^^^^^^^^^
2 │ }
3 │
ℹ It is not necessary to use `Boolean` call when a value will already be coerced to a boolean.
ℹ Safe fix: Remove redundant `Boolean` call
1 │ if·(!Boolean(foo))·{
│ -------- -
while (!!foo) {}code-block.js:1:8 lint/complexity/noExtraBooleanCast FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Avoid redundant double-negation.
> 1 │ while (!!foo) {}
│ ^^^^^
2 │
ℹ It is not necessary to use double-negation when a value will already be coerced to a boolean.
ℹ Safe fix: Remove redundant double-negation
1 │ while·(!!foo)·{}
│ --
let x = 1;do {1 + 1;} while (Boolean(x));code-block.js:4:10 lint/complexity/noExtraBooleanCast FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Avoid redundant `Boolean` call
2 │ do {
3 │ 1 + 1;
> 4 │ } while (Boolean(x));
│ ^^^^^^^^^^
5 │
ℹ It is not necessary to use `Boolean` call when a value will already be coerced to a boolean.
ℹ Safe fix: Remove redundant `Boolean` call
4 │ }·while·(Boolean(x));
│ -------- -
for (; !!foo; ) {}code-block.js:1:8 lint/complexity/noExtraBooleanCast FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Avoid redundant double-negation.
> 1 │ for (; !!foo; ) {}
│ ^^^^^
2 │
ℹ It is not necessary to use double-negation when a value will already be coerced to a boolean.
ℹ Safe fix: Remove redundant double-negation
1 │ for·(;·!!foo;·)·{}
│ --
new Boolean(!!x);code-block.js:1:13 lint/complexity/noExtraBooleanCast FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Avoid redundant double-negation.
> 1 │ new Boolean(!!x);
│ ^^^
2 │
ℹ It is not necessary to use double-negation when a value will already be coerced to a boolean.
ℹ Safe fix: Remove redundant double-negation
1 │ new·Boolean(!!x);
│ --
¥Valid
Boolean(!x);!x;!!x;¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号