An array is built by calling Array where a literal says the same

tx0/ts:array-literal-candidatestrictwarningstyle

What it finds

Array(a, b) and new Array(a, b) build the array [a, b], but Array(3) builds an empty array of length three: the same call means two different things depending on the number of arguments. A literal says which is meant.

Reported are calls of the global Array, with or without new, with no argument or with two or more. A single argument, which sets the length, is left alone, and so is a call with a spread argument, whose number of arguments is not known. The fix writes the literal; it is safe without type arguments and unsafe with them, as new Array<T>() gives the element type that [] would leave to inference.

From the rule's source, array_literal_candidate.rs.

Example from the rule's tests
export const a = new Array(1, 2, 3);tx0 reports: builds an array that a literal writesexport const b = Array();tx0 reports: builds an array that a literal writesexport const c = new Array(10);export const d = Array.from("abc");
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/ts:array-literal-candidate" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/ts:array-literal-candidate] reason="..."

tx0 explain tx0/ts:array-literal-candidate shows the same in the terminal. Found a false positive? Report it.