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).
backend ruleP1universalStack: javascript
statemutationcorrectnessconfig
Update keys on a shared object in place rather than reassigning it
When a module-level config object must be updated, mutate the specific keys instead of spreading into a new object and reassigning, which can silently retain stale keys across calls.
PR: frontpage-web · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codejavascript
| 1 | config.targeting = { |
| 2 | ...config.targeting, |
| 3 | 4: a, |
| 4 | 5: b, |
| 5 | }; // old keys 4/5 persist if a/b are falsy/absent across calls |
Explanation (EN)
Objašnjenje (HR)
Good example
New codejavascript
| 1 | config.targeting = { ...baseTargeting }; // start from a clean base |
| 2 | if (a) config.targeting[4] = a; |
| 3 | if (b) config.targeting[5] = b; |
Explanation (EN)
Objašnjenje (HR)