useValidTypeof
诊断类别:lint/suspicious/useValidTypeof
¥Diagnostic Category: lint/suspicious/useValidTypeof
自从:v1.0.0
¥Since: v1.0.0
来源:
¥Sources:
-
与以下相同:
valid-typeof
¥Same as:
valid-typeof
此规则验证 typeof $expr
一元表达式的结果是否与有效值进行比较,有效值可以是包含有效类型名称的字符串文字或其他 typeof
表达式
¥This rule verifies the result of typeof $expr
unary expressions is being compared to valid values, either string literals containing valid type names or other typeof
expressions
¥Examples
¥Invalid
code-block.js:1:16 lint/suspicious/useValidTypeof ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Invalid typeof
comparison value
> 1 │ typeof foo === “strnig”
│ ^^^^^^^^
2 │
ℹ not a valid type name
code-block.js:1:15 lint/suspicious/useValidTypeof ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Invalid typeof
comparison value
> 1 │ typeof foo == “undefimed”
│ ^^^^^^^^^^^
2 │
ℹ not a valid type name
code-block.js:1:15 lint/suspicious/useValidTypeof ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Invalid typeof
comparison value
> 1 │ typeof bar != “nunber”
│ ^^^^^^^^
2 │
ℹ not a valid type name
code-block.js:1:16 lint/suspicious/useValidTypeof ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Invalid typeof
comparison value
> 1 │ typeof bar !== “fucntion”
│ ^^^^^^^^^^
2 │
ℹ not a valid type name
code-block.js:1:16 lint/suspicious/useValidTypeof FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Invalid typeof
comparison value
> 1 │ typeof foo === undefined
│ ^^^^^^^^^
2 │
ℹ not a string literal
ℹ Unsafe fix: Compare the result of typeof
with a valid type name
1 │ typeof·foo·===·“undefined”
│ + +
code-block.js:1:15 lint/suspicious/useValidTypeof FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Invalid typeof
comparison value
> 1 │ typeof bar == Object
│ ^^^^^^
2 │
ℹ not a string literal
ℹ Unsafe fix: Compare the result of typeof
with a valid type name
1 │ - typeof·bar·==·Object
1 │ + typeof·bar·==·“object”
2 2 │
code-block.js:1:16 lint/suspicious/useValidTypeof ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Invalid typeof
comparison value
> 1 │ typeof foo === baz
│ ^^^
2 │
ℹ not a string literal
code-block.js:1:15 lint/suspicious/useValidTypeof ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Invalid typeof
comparison value
> 1 │ typeof foo == 5
│ ^
2 │
ℹ not a string literal
code-block.js:1:15 lint/suspicious/useValidTypeof ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Invalid typeof
comparison value
> 1 │ typeof foo == -5
│ ^^
2 │
ℹ not a string literal
¥Valid
¥Related links