noStringCaseMismatch
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
诊断类别:
lint/correctness/noStringCaseMismatch¥Diagnostic Category:
lint/correctness/noStringCaseMismatch -
此规则为推荐规则,默认启用。
¥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:
-
¥Same as
match_str_case_mismatch
-
¥How to configure
{ "linter": { "rules": { "correctness": { "noStringCaseMismatch": "error" } } }}¥Description
禁止比较使用不合规值修改字符串大小写的表达式。
¥Disallow comparison of expressions modifying the string case with non-compliant value.
¥Examples
¥Invalid
if (s.toUpperCase() === "Abc") {}code-block.js:1:5 lint/correctness/noStringCaseMismatch FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This expression always returns false.
> 1 │ if (s.toUpperCase() === “Abc”) {}
│ ^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ This call convert the string to upper case
> 1 │ if (s.toUpperCase() === “Abc”) {}
│ ^^^^^^^^^^^^^^^
2 │
ℹ … but this value is not in upper case
> 1 │ if (s.toUpperCase() === “Abc”) {}
│ ^^^^^
2 │
ℹ Unsafe fix: Use upper case string value.
1 │ - if·(s.toUpperCase()·===·“Abc”)·{}
1 │ + if·(s.toUpperCase()·===·“ABC”)·{}
2 2 │
while (s.toLowerCase() === "Abc") {}code-block.js:1:8 lint/correctness/noStringCaseMismatch FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This expression always returns false.
> 1 │ while (s.toLowerCase() === “Abc”) {}
│ ^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ This call convert the string to lower case
> 1 │ while (s.toLowerCase() === “Abc”) {}
│ ^^^^^^^^^^^^^^^
2 │
ℹ … but this value is not in lower case
> 1 │ while (s.toLowerCase() === “Abc”) {}
│ ^^^^^
2 │
ℹ Unsafe fix: Use lower case string value.
1 │ - while·(s.toLowerCase()·===·“Abc”)·{}
1 │ + while·(s.toLowerCase()·===·“abc”)·{}
2 2 │
¥Valid
if (s.toUpperCase() === "ABC") {}while (s.toLowerCase() === "abc") {}for (;s.toLocaleLowerCase() === "ABC";) {}while (s.toLocaleUpperCase() === "abc") {}for (let s = "abc"; s === "abc"; s = s.toUpperCase()) {}¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号