Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Assume standard global objects exist
Rely on standard globals guaranteed by the supported runtime baseline; feature-detect globals or methods only where supported environments require it.
Bad example
| 1 | function mergeSignals(signals: AbortSignal[]) { |
| 2 | // Bad: Redundant check for the AbortSignal class itself |
| 3 | if (typeof AbortSignal !== 'undefined' && 'any' in AbortSignal) { |
| 4 | return AbortSignal.any(signals); |
| 5 | } |
| 6 | // ...fallback logic |
| 7 | } |
Explanation (EN)
A proven baseline makes a repeated base-global guard unnecessary; the method may still need detection.
Objašnjenje (HR)
Zajamčeno izvršno okruženje čini ponovljenu provjeru osnovnog globalnog objekta suvišnom; pojedina metoda i dalje može zahtijevati provjeru podrške.
Good example
| 1 | function mergeSignals(signals: AbortSignal[]) { |
| 2 | // Good: Only check for the specific new method you need |
| 3 | if ('any' in AbortSignal) { |
| 4 | return AbortSignal.any(signals); |
| 5 | } |
| 6 | // ...fallback logic |
| 7 | } |
Explanation (EN)
We assume the base `AbortSignal` class exists and only feature-detect the specific static method (`any`) which might be missing in older versions.
Objašnjenje (HR)
Pretpostavljamo da osnovna klasa `AbortSignal` postoji i provjeravamo samo specifičnu statičku metodu (`any`) koja može nedostajati u starijim verzijama.
Notes (EN)
Remove global-existence guards only after checking the supported browser, server, worker and test-runtime baseline. Feature-detect optional newer methods separately.
Exceptions / Tradeoffs (EN)
Keep a guard or platform adapter in supported runtimes where the base global can be absent. TypeScript DOM declarations do not prove runtime availability.