useLiteralKeys
Diagnostic Category: lint/complexity/useLiteralKeys
Since: v1.0.0
Sources:
- Same as: 
dot-notation - Same as: 
@typescript-eslint/dot-notation 
Description
Section titled DescriptionEnforce the usage of a literal access to properties over computed property access.
Examples
Section titled ExamplesInvalid
Section titled Invalida.b["c"];code-block.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`]code-block.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[</strong></span><span style="color: Tomato;"><strong>d</strong></span><span style="color: Tomato;"><strong>]
      1 │ + a.c.d
    2 2 │   
  
a.c[`d`] = "something"code-block.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[</strong></span><span style="color: Tomato;"><strong>d</strong></span><span style="color: Tomato;"><strong>]·=·“something”
      1 │ + a.c.d·=·“something”
    2 2 │   
  
a = {  ['b']: d}code-block.js:2:3 lint/complexity/useLiteralKeys  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ✖ The computed expression can be simplified to a string literal.
  
    1 │ a = {
  > 2 │ 	[‘b’]: d
      │ 	 ^^^
    3 │ }
    4 │ 
  
  ℹ Unsafe fix: Use a literal key instead.
  
    1 1 │   a = {
    2   │ - → [‘b’]:·d
      2 │ + → “b”:·d
    3 3 │   }
    4 4 │   
  
Valid
Section titled Valida["c" + "d"];a[d.c];How to configure
Section titled How to configure{  "linter": {    "rules": {      "complexity": {        "useLiteralKeys": "error"      }    }  }}