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).
Don't inject a dependency you never use
Either call an injected dependency through its API or remove it from the constructor; unused injections mislead readers.
Bad example
| 1 | constructor(private readonly configService: ConfigService) { |
| 2 | const baseUrl = process.env.SERVICE_URL || ''; |
| 3 | super(baseUrl); |
| 4 | } |
Explanation (EN)
`configService` is injected but bypassed in favour of `process.env`, leaving readers unsure which path is authoritative.
Objašnjenje (HR)
`configService` je ubrizgan ali zaobiđen u korist `process.env`, pa čitatelji ne znaju koji je put mjerodavan.
Good example
| 1 | constructor(private readonly configService: ConfigService) { |
| 2 | const baseUrl = configService.get<string>('SERVICE_URL', ''); |
| 3 | super(baseUrl); |
| 4 | } |
Explanation (EN)
The injected service is actually used, keeping configuration access consistent and the dependency honest.
Objašnjenje (HR)
Ubrizgani servis se zaista koristi, čime pristup konfiguraciji ostaje dosljedan, a ovisnost iskrena.