Skip to main content

js/noShoutyConstants

MISSING DOCUMENTATION

Examples

Invalid

const FOO = "FOO";
console.log(FOO);

 file.ts:2:12 lint/js/noShoutyConstants  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━

  Redundant constant reference

    1const FOO = "FOO";
  > 2console.log(FOO);
                 ^^^

  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.

  This constant is declared here

  > 1const FOO = "FOO";
           ^^^
    2console.log(FOO);

  Safe fix

  - FOO
  + "FOO"


const FOO = "FOO";
function f() {
	return FOO;
}

 file.ts:3:8 lint/js/noShoutyConstants  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━

  Redundant constant reference

    1const FOO = "FOO";
    2function f() {
  > 3  return FOO;
              ^^^
    4}

  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.

  This constant is declared here

  > 1const FOO = "FOO";
           ^^^
    2function f() {
    3  return FOO;

  Safe fix

  - FOO
  + "FOO"


const FOO = "FOO", BAR = "bar";
console.log(FOO);

 file.ts:2:12 lint/js/noShoutyConstants  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━

  Redundant constant reference

    1const FOO = "FOO", BAR = "bar";
  > 2console.log(FOO);
                 ^^^

  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.

  This constant is declared here

  > 1const FOO = "FOO", BAR = "bar";
           ^^^
    2console.log(FOO);

  Safe fix

  - FOO
  + "FOO"

Valid

let FOO = "FOO";
console.log(FOO);
export const FOO = "FOO";
console.log(FOO);
function f(FOO = "FOO") {
	return FOO;
}