🚧 An auto-fix is still under development.
Disallows creating arrays with the Array
constructor.
Use of the Array
constructor to construct a new array is generally
discouraged in favor of array literal notation because of the
single-argument pitfall and because the Array
global may be redefined.
The exception is when the Array
constructor is used to intentionally
create sparse arrays of a specified size by giving the constructor a
single numeric argument.
Examples of incorrect code for this rule:
let arr = new Array();
Examples of correct code for this rule:
let arr = [];
let arr2 = Array.from(iterable);
let arr3 = new Array(9);
To enable this rule in the CLI or using the config file, you can use:
::: code-group
oxlint --deny no-array-constructor
{
"rules": {
"no-array-constructor": "error"
}
}
:::