Lint Rules

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);
style/noShoutyConstants.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.
  
   Suggested 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;
}