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
domdryclasslistreadability
Spread a known collection to clear all related classes instead of per-class toggles
When swapping mutually-exclusive classes, remove the whole set with a spread (filtered) and add the active one, rather than enumerating each class with toggle calls.
PR: hegnar-zephr-components · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codejavascript
| 1 | el.classList.toggle('bg-orange-600', product === 'Kapital'); |
| 2 | el.classList.toggle('bg-gray-800', product === 'Motor'); |
| 3 | el.classList.toggle('bg-blue-700', product !== 'Kapital' && product !== 'Motor'); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codejavascript
| 1 | el.classList.remove(...allBackgroundClasses.filter(Boolean)); |
| 2 | if (theme?.background) el.classList.add(theme.background); |
Explanation (EN)
Objašnjenje (HR)