noShoutyConstants
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
诊断类别:
lint/style/noShoutyConstants¥Diagnostic Category:
lint/style/noShoutyConstants -
此规则包含 unsafe 修复程序。
¥This rule has an unsafe fix.
-
此规则的默认严重级别为 information。
¥The default severity of this rule is information.
¥How to configure
{ "linter": { "rules": { "style": { "noShoutyConstants": "error" } } }}¥Description
禁止使用其值为名称大写版本的常量。
¥Disallow the use of constants which its value is the upper-case version of its name.
¥Examples
¥Invalid
const FOO = "FOO";console.log(FOO);code-block.js:1:7 lint/style/noShoutyConstants FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Redundant constant declaration.
> 1 │ const FOO = “FOO”;
│ ^^^^^^^^^^^
2 │ console.log(FOO);
3 │
ℹ Used here.
1 │ const FOO = “FOO”;
> 2 │ console.log(FOO);
│ ^^^
3 │
ℹ You should avoid declaring constants with a string that’s the same
value as the variable name. It introduces a level of unnecessary
indirection when it’s only two additional characters to inline.
ℹ Unsafe fix: Use the constant value directly
1 │ - const·FOO·=·“FOO”;
2 │ - console.log(FOO);
1 │ +
2 │ + console.log(“FOO”);
3 3 │
¥Valid
let FOO = "FOO";console.log(FOO);export const FOO = "FOO";console.log(FOO);function f(FOO = "FOO") { return FOO;}¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号