Skip to content

No Array Constructor Elements

ErrorAuto-fixableRoblox
small-rules/no-array-constructor-elements

Disallow array constructor element forms and enforce roblox-ts-aware constructor patterns.

Diagnostic Messages

avoidConstructorEnumeration
Do not use Array constructor enumeration arguments. Use an array literal instead.
avoidLengthConstructorInStandard
Length-based Array constructor is not allowed in standard mode. Prefer Array.from({ length: n }).
avoidSingleArgumentConstructor
Single-argument Array constructor form is not allowed here. Use an array literal instead.
collapseArrayPushInitialization
Collapse new Array<T>() + consecutive .push(...) calls into a single array literal initializer.
requireExplicitGenericOnNewArray
new Array() must use an explicit generic argument or a contextual Array<T>/ReadonlyArray<T> annotation.
suggestArrayFromLength
Replace with Array.from({ length: value }).
suggestArrayLiteral
Replace constructor form with an array literal.
suggestCollapseArrayPushInitialization
Collapse constructor + push sequence into a single array literal initializer.

Configuration

This rule accepts one options object after the severity.

environmentOptional

Array constructor environment mode: 'roblox-ts' allows new Array(length); 'standard' reports it.

requireExplicitGenericOnNewArrayOptional

When true, zero-argument new Array() requires explicit generic type arguments or contextual array typing.

{
"jsPlugins": [
"@pobammer-ts/small-rules"
],
"rules": {
"small-rules/no-array-constructor-elements": [
"error",
{
"environment": "roblox-ts",
"requireExplicitGenericOnNewArray": true
}
]
}
}

Examples

array constructor with elements
const values = new Array("a", "b");

After auto-fix

const values = ["a", "b"];
empty generic array constructor
const value = new Array<string>();