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: typescript
immutabilityside-effectscorrectnessfunctions
Copy an input object before mutating it inside a function
Don't mutate a parameter you were handed; spread into a new object first so callers don't see surprising side effects.
PR: frontpage-web · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | let params = queryParam; |
| 2 | if (queryParam.excludeId) { |
| 3 | params.limit = (params.limit || 10) + 1; // mutates caller's object |
| 4 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | const params = { ...queryParam }; |
| 2 | if (queryParam.excludeId) { |
| 3 | params.limit = (params.limit || 10) + 1; |
| 4 | } |
Explanation (EN)
Objašnjenje (HR)