useLiteralKeys (since v1.0.0)
Diagnostic Category: lint/complexity/useLiteralKeys
Source: dot-notation
Enforce the usage of a literal access to properties over computed property access.
Examples
Section titled ExamplesInvalid
Section titled Invalida.b["c"];
complexity/useLiteralKeys.js:1:5 lint/complexity/useLiteralKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ The computed expression can be simplified without the use of a string literal.
> 1 │ a.b["c"];
│ ^^^
2 │
ℹ Unsafe fix: Use a literal key instead.
1 │ - a.b["c"];
1 │ + a.b.c;
2 2 │
a.c[`d`]
complexity/useLiteralKeys.js:1:5 lint/complexity/useLiteralKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ The computed expression can be simplified without the use of a string literal.
> 1 │ a.c[`d`]
│ ^^^
2 │
ℹ Unsafe fix: Use a literal key instead.
1 │ - a.c[`d`]
1 │ + a.c.d
2 2 │
a.c[`d`] = "something"
complexity/useLiteralKeys.js:1:5 lint/complexity/useLiteralKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ The computed expression can be simplified without the use of a string literal.
> 1 │ a.c[`d`] = "something"
│ ^^^
2 │
ℹ Unsafe fix: Use a literal key instead.
1 │ - a.c[`d`]·=·"something"
1 │ + a.c.d·=·"something"
2 2 │
a = { ['b']: d}
complexity/useLiteralKeys.js:2:3 lint/complexity/useLiteralKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ The computed expression can be simplified without the use of a string literal.
1 │ a = {
> 2 │ ['b']: d
│ ^^^
3 │ }
4 │
ℹ Unsafe fix: Use a literal key instead.
2 │ → ['b']:·d
│ -- --
Valid
Section titled Valida["c" + "d"];a[d.c];