unicorn/no-new-array
eslint-plugin-unicorn
Safe autofix
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/no-new-array": "error",
},
},
];const length = 10;
const array = new Array(length);const array = new Array(onlyElement);const array = new Array(...items);const array = [onlyElement];const array = [...items];Examples from the ESLint documentation.
unicorn/no-new-array
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/no-new-array": "error",
},
},
];unicorn/no-new-array
unicorn plugin · correctness
{
"rules": {
"unicorn/no-new-array": "error"
}
}nursery/noNewArray
nursery · since 2.6.7
{
"linter": {
"rules": {
"nursery": {
"noNewArray": "error"
}
}
}
}Prefer String#startsWith() & String#endsWith() over regexes, String#indexOf() === 0, and slice checks.
Disallow awaiting non-promise values.
Prefer using Set#size instead of Array#length.
Disallow useless array length check.