Skip to content

Prefer idiv

SuggestionAuto-fixableRoblox
small-rules/prefer-idiv

Prefer .idiv() for integer division instead of math.floor(x / y) or math.floor(x * 0.5).

Rationale

roblox-ts has a dedicated integer division operator, x.idiv(y), that does exactly what math.floor(x / y) does but compiles to x // y instead of a floor plus a division. Should be a bit faster, and it’s clearer about what you meant.

Auto-fixes math.floor(x / y) to x.idiv(y). Only fires when the divisor is a division expression, so it won’t touch anything weird.

Diagnostic Messages

useIdiv
Use .idiv() instead of math.floor(x / y) or math.floor(x * 0.5) for integer division.

Configuration

This rule does not accept options.

{
"jsPlugins": [
"@pobammer-ts/small-rules"
],
"rules": {
"small-rules/prefer-idiv": "error"
}
}

Examples

floor division expression
math.floor(x / y);

After auto-fix

x.idiv(y);
integer division method
x.idiv(y);