Skip to main content

noShoutyConstants (since v0.7.0)

This rule is recommended by Rome.

Disallow the use of constants which its value is the upper-case version of its name.

Examples

Invalid

const FOO = "FOO";
console.log(FOO);
error[js/noShoutyConstants]: Redundant constant declaration.
   js/noShoutyConstants.js:1:7
  
1  const FOO = "FOO";
         ^^^^^^^^^^^
2  console.log(FOO);
               --- Used here.

Suggested fix: Use the constant value directly
    | @@ -1,2 +1,2 @@
0   | - const FOO = "FOO";
1   | - console.log(FOO);
  0 | + 
  1 | + console.log("FOO");

=  note: 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.