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
readabilityperformancearrays
Don't spread an array into a new one when you can return it unchanged
If you aren't mutating the array, return it directly instead of creating a needless `[...arr]` copy (and if you do copy, comment why).
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codets
| 1 | return [...prevItems]; |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | return prevItems; // when nothing was mutated |
| 2 | // or, if a copy is required for React reference change, leave a short comment |
Explanation (EN)
Objašnjenje (HR)