Skip to content

No table.create().map()

SuggestionRoblox
small-rules/no-table-create-map

Disallow map(...) directly on table.create(...) and new Array(...) constructor patterns in roblox-ts.

Rationale

This pattern shows up too often. table.create(...).map(...) allocates an intermediate table, throws away the function allocation when .map() returns, and allocates another table for the result. Two allocations for a job that needs one.

  • Just write it: loop and assign by index, or use an array literal. One allocation, no intermediate garbage.

  • Readability: table.create().map() looks like you’re transforming an existing table, but you’re building a new one from scratch.

Same applies to new Array(n).map(...). Allocate first, then write. Hate this pattern.

Diagnostic Messages

avoidConstructThenMap
Do not map directly on table.create(...) or new Array(...). Allocate first, then write by index in a loop.

Configuration

This rule does not accept options.

{
"jsPlugins": [
"@pobammer-ts/small-rules"
],
"rules": {
"small-rules/no-table-create-map": "error"
}
}

Examples

table creation followed by map
const mapped = table.create(total).map((_, index) => index);
table creation without mapping
table.create(entries);