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).
fullstack ruleP1universalStack: universal
testingfixturesrefactoringsafety
Add tests with real-world fixtures before optimizing a function
Before rewriting/optimizing tricky logic, lock its behavior with unit tests built from actual production inputs so the optimization is provably safe.
PR: hegnar-web · org-mining-deep-2026-06Created: Jun 17, 2026
Bad example
Old codejavascript
| 1 | // rewrite splitTitle() for performance with no tests covering real titles |
Explanation (EN)
Objašnjenje (HR)
Good example
New codejavascript
| 1 | describe('splitTitle', () => { |
| 2 | for (const title of REAL_JOURNALIST_TITLES) { |
| 3 | it(`splits ${title}`, () => expect(splitTitle(title)).toMatchSnapshot()); |
| 4 | } |
| 5 | }); |
| 6 | // now optimize with confidence |
Explanation (EN)
Objašnjenje (HR)