prefer-udim2-shorthand
Replaces new UDim2(...) with UDim2.fromScale(...) or UDim2.fromOffset(...) when the other half is zero.
Rule details Suggestion
Section titled “Rule details ”SuggestionThe rule checks new UDim2(scaleX, offsetX, scaleY, offsetY) calls with exactly four arguments.
- If
offsetXandoffsetYboth evaluate to0, it reportsUDim2.fromScale(scaleX, scaleY). - If
scaleXandscaleYboth evaluate to0, it reportsUDim2.fromOffset(offsetX, offsetY).
It can evaluate numeric literals, identifiers, unary + and -, and simple arithmetic with +, -, *, /, and
%. Mixed scale and offset constructors are left alone.
Examples
Section titled “Examples” Incorrect
new UDim2(1, 0, 1, 0);new UDim2(0, 100, 0, 50);new UDim2(x + 1, 0, 1 - y, 0); Correct
UDim2.fromScale(1, 1);UDim2.fromOffset(100, 50);UDim2.fromScale(x + 1, 1 - y);
new UDim2(0.5, 10, 0.5, 10);new UDim2(0, 0, 0, 0);What gets skipped
Section titled “What gets skipped”- constructors with fewer or more than four arguments
- constructors where the zero side cannot be evaluated
- unsupported expressions such as bitwise operators or string literals
- mixed scale and offset values
Related rules
Section titled “Related rules” prefer-sequence-overloads Uses shorter Roblox constructor overloads for simple sequence values
prefer-pattern-replacements Handles configurable constructor and method rewrites