Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
fullstack ruleP2universalStack: JavaScript/TypeScript
readabilityternaryconditionals
Prefer a ternary for simple value selection
Use a concise ternary expression when picking between two values, instead of a multi-line if/else assigning the same variable.
PR: hegnar-forum-web · org-mining-3rd-2026-06Created: Jun 18, 2026
Bad example
Old codets
| 1 | let ariaLabel = UPVOTE_REPLY; |
| 2 | if (direction === 'down') { ariaLabel = isVoted ? REMOVE_DOWNVOTE : DOWNVOTE; } |
| 3 | else { ariaLabel = isVoted ? REMOVE_UPVOTE : UPVOTE; } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | const ariaLabel = ARIA_LABELS[direction][isVoted ? 'active' : 'inactive']; |
Explanation (EN)
Objašnjenje (HR)