Skip to content

Prefer Udim2 Shorthand

SuggestionAuto-fixableRoblox
small-rules/prefer-udim2-shorthand

Prefer UDim2.fromScale() or UDim2.fromOffset() over new UDim2() when all offsets or all scales are zero.

Diagnostic Messages

preferFromOffset
Use UDim2.fromOffset() instead of new UDim2() when all scales are 0.
preferFromScale
Use UDim2.fromScale() instead of new UDim2() when all offsets are 0.

Configuration

This rule does not accept options.

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

Examples

long-form UDim2 scale
new UDim2(1, 0, 1, 0);

After auto-fix

UDim2.fromScale(1, 1);
mixed UDim2 components
new UDim2(1, 2, 3, 4);