Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Use the numeric predicate that matches your intent (isNaN vs isFinite)
Validate the numeric domain required by the consumer; Number.isNaN is not a general numeric-input validator.
Bad example
| 1 | if (!Number.isNaN(rawId)) queryById(rawId); |
Explanation (EN)
A NaN-only check accepts infinity and nonnumeric values when the input is not already a number.
Objašnjenje (HR)
Provjera samo NaN propušta beskonačnost i nebrojčane vrijednosti ako ulaz nije već broj.
Good example
| 1 | if (typeof rawId !== "number" || !Number.isSafeInteger(rawId) || rawId <= 0) { |
| 2 | throw new TypeError("Invalid ID"); |
| 3 | } |
| 4 | queryById(rawId); |
Explanation (EN)
This domain requires a positive safe integer; other numeric domains need their own range policy.
Objašnjenje (HR)
Ova domena zahtijeva pozitivan siguran cijeli broj. Druge brojčane domene trebaju vlastiti raspon.
Notes (EN)
Choose a predicate for the actual input domain: typeof for primitive number shape, Number.isNaN for exactly NaN, Number.isFinite for finite numbers, and integer/range checks where required.
Exceptions / Tradeoffs (EN)
Number.isNaN("bad") is false and does not validate numeric input. Infinity is usually invalid for IDs, so do not weaken an ID guard from finite to not-NaN.