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).
backend ruleP2universalStack: TypeScript
simplicitycouplingreadability
Instantiate a dependency where it's used rather than threading it through
If a provider/helper is only needed inside one method, create it there instead of building it in the caller and passing it down through several layers.
PR: hegnar-ws · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | const provider = new WsInstrumentDataProvider(); |
| 2 | await this.handleMissingTickerData({ data, articles, instrumentDataProvider: provider }); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | // inside getTickerData where it's actually used |
| 2 | const provider = new WsInstrumentDataProvider(); |
| 3 | const response = await provider.getTickerByIsin(isin); |
Explanation (EN)
Objašnjenje (HR)