prefer-pattern-replacements
Replace configured constructor and static method patterns with shorter forms.
Rule details Suggestion
Section titled “Rule details ”SuggestionThis rule matches new Type(...) and Type.method(...) calls against the patterns you configure. When a pattern
matches, the rule reports the original call and can replace it with the configured text.
Pattern order matters. The rule tries them in the order you list them and stops at the first safe match.
Configuration
Section titled “Configuration”import ceaseNonsense from "eslint-plugin-cease-nonsense";
export default [ { plugins: { "cease-nonsense": ceaseNonsense }, rules: { "cease-nonsense/prefer-pattern-replacements": [ "error", { patterns: [ { match: "new Vector2($x, $x)", replacement: "fromUniform($x)", }, ], }, ], }, },];Options
Section titled “Options”| Option | Type | Default | Notes |
|---|---|---|---|
patterns | Pattern[] | [] | Ordered list of constructor or static method rewrites |
Each pattern object has these fields:
| Field | Required | Description |
|---|---|---|
match | Yes | A constructor form like new Vector2($x, $y) or a static method form like UDim2.fromScale($x, $y) |
replacement | Yes | Replacement text such as vec($x, $y) or Vector2.zero |
when | No | Numeric conditions for captures, such as { x: "> 0" } |
Pattern syntax
Section titled “Pattern syntax”| Syntax | Meaning |
|---|---|
$x | Capture a value and reuse it in the replacement |
_ | Match any single argument without capturing it |
number? | Match that numeric literal, undefined, or a missing argument |
repeated capture, like $x, $x | Both arguments must be the same value |
when conditions only work for captures that resolve to numeric constants.
Examples
Section titled “Examples”pattern({ match: "new Vector2($x, $x)", replacement: "fromUniform($x)",});
pattern({ match: "UDim2.fromScale($x, $x)", replacement: "scale($x)", when: { x: "> 0" },});
pattern({ match: "new Vector2($x, 0?)", replacement: "fromX($x)",});Related rules
Section titled “Related rules” no-color3-constructor A fixed constructor rule for one specific Roblox API
prefer-udim2-shorthand A built-in shorthand rule for common UDim2 patterns