useValidTypeof
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
诊断类别:
lint/correctness/useValidTypeof¥Diagnostic Category:
lint/correctness/useValidTypeof -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则包含 unsafe 修复程序。
¥This rule has an unsafe fix.
-
此规则的默认严重级别为 error。
¥The default severity of this rule is error.
-
来源:
¥Sources:
-
与
valid-typeof相同¥Same as
valid-typeof
-
¥How to configure
{ "linter": { "rules": { "correctness": { "useValidTypeof": "error" } } }}¥Description
此规则检查 typeof 表达式的结果是否与有效值进行比较。
¥This rule checks that the result of a typeof expression is compared to a valid value.
¥Examples
¥Invalid
typeof foo === "strnig";code-block.js:1:16 lint/correctness/useValidTypeof ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ “strnig” is not a valid typeof value.
> 1 │ typeof foo === “strnig”;
│ ^^^^^^^^
2 │
typeof foo == "undefimed";code-block.js:1:15 lint/correctness/useValidTypeof ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ “undefimed” is not a valid typeof value.
> 1 │ typeof foo == “undefimed”;
│ ^^^^^^^^^^^
2 │
typeof bar != "nunber";code-block.js:1:15 lint/correctness/useValidTypeof ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ “nunber” is not a valid typeof value.
> 1 │ typeof bar != “nunber”;
│ ^^^^^^^^
2 │
typeof foo === undefined;code-block.js:1:16 lint/correctness/useValidTypeof ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Invalid typeof comparison.
> 1 │ typeof foo === undefined;
│ ^^^^^^^^^
2 │
ℹ Compare with one of the following string literals:
- “bigint”
- “boolean”
- “function”
- “number”
- “object”
- “string”
- “symbol”
- “undefined”
typeof foo == 0;code-block.js:1:15 lint/correctness/useValidTypeof ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Invalid typeof comparison.
> 1 │ typeof foo == 0;
│ ^
2 │
ℹ Compare with one of the following string literals:
- “bigint”
- “boolean”
- “function”
- “number”
- “object”
- “string”
- “symbol”
- “undefined”
¥Valid
typeof foo === "string";typeof bar == "undefined";typeof bar === typeof qux;typeof foo === bar¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号