noShoutyConstants (JavaScript)
Language JavaScript (and super languages)
Summary
Section titled “Summary”- Rule available since:
v1.0.0 - Diagnostic Category:
lint/style/noShoutyConstants - This rule isn’t recommended, so you need to enable it.
- This rule has an unsafe fix.
- The default severity of this rule is information.
How to configure
Section titled “How to configure”{ "linter": { "rules": { "style": { "noShoutyConstants": "error" } } }}Description
Section titled “Description”Disallow constants whose string value is the same as their uppercase name.
A declaration such as const FOO = "FOO" adds an unnecessary name without providing
additional meaning. Use the string directly instead. The rule ignores exported constants
and constants referenced more than once.
Examples
Section titled “Examples”Invalid
Section titled “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 │
let FOO = "FOO";console.log(FOO);export const FOO = "FOO";console.log(FOO);function f(FOO = "FOO") { return FOO;}Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.