Skip to content

useLiteralKeys (since v1.0.0)

Diagnostic Category: lint/complexity/useLiteralKeys

Sources:

Enforce the usage of a literal access to properties over computed property access.

a.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
    -- --   
a["c" + "d"];
a[d.c];