Lint Rules

useShorthandArrayType (since v0.7.0)

This rule is recommended by Rome.

When expressing array types, this rule promotes the usage of T[] shorthand instead of Array<T>.

Examples

Invalid

let valid: Array<foo>;
style/useShorthandArrayType.js:1:12 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━

   Use shorthand T[] syntax instead of Array<T> syntax.
  
  > 1 │ let valid: Array<foo>;
              ^^^^^^^^^^
    2 │ 
  
   Suggested fix: Use shorthand T[] syntax to replace
  
    1  - let·valid:·Array<foo>;
      1+ let·valid:·foo[];
    2 2  
  
let invalid2: Promise<Array<string>>;
style/useShorthandArrayType.js:1:23 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━

   Use shorthand T[] syntax instead of Array<T> syntax.
  
  > 1 │ let invalid2: Promise<Array<string>>;
                         ^^^^^^^^^^^^^
    2 │ 
  
   Suggested fix: Use shorthand T[] syntax to replace
  
    1  - let·invalid2:·Promise<Array<string>>;
      1+ let·invalid2:·Promise<string[]>;
    2 2  
  
let invalid3: Array<Foo<Bar>>;
style/useShorthandArrayType.js:1:15 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━

   Use shorthand T[] syntax instead of Array<T> syntax.
  
  > 1 │ let invalid3: Array<Foo<Bar>>;
                 ^^^^^^^^^^^^^^^
    2 │ 
  
   Suggested fix: Use shorthand T[] syntax to replace
  
    1  - let·invalid3:·Array<Foo<Bar>>;
      1+ let·invalid3:·Foo<Bar>[];
    2 2  
  
let invalid: Array<[number, number]>;
style/useShorthandArrayType.js:1:14 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━

   Use shorthand T[] syntax instead of Array<T> syntax.
  
  > 1 │ let invalid: Array<[number, number]>;
                ^^^^^^^^^^^^^^^^^^^^^^^
    2 │ 
  
   Suggested fix: Use shorthand T[] syntax to replace
  
    1  - let·invalid:·Array<[number,·number]>;
      1+ let·invalid:·[number,·number][];
    2 2  
  
let invalid: Array<[number, number]>;
style/useShorthandArrayType.js:1:14 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━

   Use shorthand T[] syntax instead of Array<T> syntax.
  
  > 1 │ let invalid: Array<[number, number]>;
                ^^^^^^^^^^^^^^^^^^^^^^^
    2 │ 
  
   Suggested fix: Use shorthand T[] syntax to replace
  
    1  - let·invalid:·Array<[number,·number]>;
      1+ let·invalid:·[number,·number][];
    2 2  
  

Valid

let valid: Array<Foo | Bar>;
let valid: Array<keyof Bar>;
let valid: Array<foo | bar>;