Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Ship unit tests with new non-trivial logic
New custom plugins, pipelines, or parsers should come with at least one or two unit tests covering the new behavior.
Bad example
| 1 | // new viteSvgo() plugin added — optimizes and serves SVGs |
| 2 | // no test file accompanies it, so a future refactor can |
| 3 | // silently break SVG handling with no signal |
Explanation (EN)
Merging new behavior without any test leaves the path unguarded: regressions slip in unnoticed and the intended behavior is undocumented.
Objašnjenje (HR)
Spajanje novog ponašanja bez ijednog testa ostavlja taj put nezaštićenim: regresije prolaze neopaženo, a namjeravano ponašanje ostaje nedokumentirano.
Good example
| 1 | import { describe, it, expect } from 'vitest'; |
| 2 | import { optimizeSvg } from './vite-plugin-svgo'; |
| 3 |
|
| 4 | describe('optimizeSvg', () => { |
| 5 | it('strips comments and returns optimized markup', () => { |
| 6 | const out = optimizeSvg('<svg><!--x--><path/></svg>', 'icon.svg'); |
| 7 | expect(out.data).not.toContain('<!--'); |
| 8 | }); |
| 9 | }); |
Explanation (EN)
A couple of focused unit tests pin down the new logic's contract and catch regressions when the implementation changes later.
Objašnjenje (HR)
Nekoliko fokusiranih unit testova fiksira ugovor nove logike i hvata regresije kad se implementacija kasnije promijeni.