Rules Hub
Code Ruleset
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
frontend ruleP2universalStack: JavaScript/TypeScript
readabilitysimplificationfunctions
Use a plain variable instead of a function that takes no input
If a helper takes no arguments and just computes a value, declare it as a variable rather than wrapping it in a function.
PR: vinify-frontend · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codetypescript
| 1 | const getLocationImage = (): string => { |
| 2 | if (type === 'STORE' || !imageUrl) return '/images/store.svg'; |
| 3 | return imageUrl; |
| 4 | }; |
Explanation (EN)
A helper called once for a pure value from stable local inputs can add needless indirection.
Objašnjenje (HR)
Good example
New codetypescript
| 1 | const locationImage = type === 'STORE' || !imageUrl ? '/images/store.svg' : imageUrl; |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
Replace a zero-argument helper with a value only when evaluation time, captured inputs, laziness and exception behavior remain equivalent.
Exceptions / Tradeoffs (EN)
A getter-like function may intentionally read changing data or defer expensive work until called. Do not turn it into a stale snapshot.