Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Prefer a bare return over an explicit return undefined
In a function that may yield undefined, use a bare `return;` for early exits instead of `return undefined;`.
Bad example
| 1 | const resolveUrl = (): string | undefined => { |
| 2 | if (!enabled) return undefined; |
| 3 | return config.url; |
| 4 | }; |
Explanation (EN)
`return undefined;` adds a token without adding meaning — the function already declares it can return undefined, so the explicit value is just noise on the early-exit path.
Objašnjenje (HR)
`return undefined;` dodaje token bez dodavanja značenja — funkcija već deklarira da može vratiti undefined, pa je eksplicitna vrijednost na putu ranog izlaza samo šum.
Good example
| 1 | const resolveUrl = (): string | undefined => { |
| 2 | if (!enabled) return; |
| 3 | return config.url; |
| 4 | }; |
Explanation (EN)
A bare `return;` yields undefined just the same and reads as a clean early exit. Less to parse, identical behavior.
Objašnjenje (HR)
Goli `return;` jednako vraća undefined i čita se kao čist rani izlaz. Manje za pročitati, identično ponašanje.
Notes (EN)
Reserve an explicit `return undefined;` only where it genuinely aids clarity (e.g. distinguishing from `return null;` in the same function).
Bilješke (HR)
Eksplicitni `return undefined;` zadržite samo gdje stvarno pomaže jasnoći (npr. razlikovanje od `return null;` u istoj funkciji).