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).
Gate diagnostic console logging to development only
Wrap debug/error console statements behind an environment check so they don't ship as noise to production users.
Bad example
| 1 | import('./Modal').catch(error => { |
| 2 | console.error('Failed to load modal chunk, falling back', error); |
| 3 | window.location.assign('/login'); |
| 4 | }); |
Explanation (EN)
This logs to the browser console for every real user in production, leaking internals and adding noise. Production diagnostics should go to a real error reporter, not raw console output.
Objašnjenje (HR)
Ovo ispisuje u konzolu preglednika za svakog stvarnog korisnika u produkciji, otkriva interne detalje i stvara buku. Produkcijska dijagnostika treba ici u pravi reporter gresaka, a ne u sirovi ispis konzole.
Good example
| 1 | import('./Modal').catch(error => { |
| 2 | if (import.meta.env.DEV) { |
| 3 | console.error('Failed to load modal chunk, falling back', error); |
| 4 | } |
| 5 | reportError(error); // production-grade reporter |
| 6 | window.location.assign('/login'); |
| 7 | }); |
Explanation (EN)
The verbose console output is gated to development, while production sends the failure to a proper error-reporting pipeline. Users never see raw console noise.
Objašnjenje (HR)
Opsiran ispis u konzolu ogranicen je na razvoj, dok produkcija salje gresku u pravi sustav za prijavu gresaka. Korisnici nikad ne vide sirovu buku u konzoli.
Notes (EN)
Use the env flag your tooling provides (import.meta.env.DEV for Vite, process.env.NODE_ENV !== 'production' for Node/Webpack).
Bilješke (HR)
Koristi env zastavicu koju ti alat nudi (import.meta.env.DEV za Vite, process.env.NODE_ENV !== 'production' za Node/Webpack).