noShoutyConstants
Ce contenu n’est pas encore disponible dans votre langue.
Diagnostic Category: lint/style/noShoutyConstants
Since: v1.0.0
Description
Section titled DescriptionDisallow the use of constants which its value is the upper-case version of its name.
Examples
Section titled ExamplesInvalid
Section titled Invalidconst 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
Section titled Validlet FOO = "FOO";console.log(FOO);
export const FOO = "FOO";console.log(FOO);
function f(FOO = "FOO") { return FOO;}
How to configure
Section titled How to configure{ "linter": { "rules": { "style": { "noShoutyConstants": "error" } } }}