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).
frontend ruleP2universalStack: javascript
dryurl-buildingreadability
Factor out repeated URL-building steps
When the same path/query assembly is duplicated across branches, consolidate it into one set of conditional appends.
PR: hegnar-web · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codejavascript
| 1 | if (tab === 'fa') { url = `/base/${tab}/${category}?page=${page}`; } |
| 2 | else if (tab !== 'all') { url = `/base/${tab}?page=${page}`; } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codejavascript
| 1 | if (tab !== 'all') { |
| 2 | url += `/${tab}`; |
| 3 | if (tab === 'fa' && category) url += `/${category}`; |
| 4 | } |
| 5 | if (page !== 1) url += `?page=${page}`; |
Explanation (EN)
Objašnjenje (HR)