Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Always pass a radix to parseInt and provide a fallback
Pass the intended radix to parseInt and validate missing, malformed and out-of-range inputs separately; do not replace valid zero with a truthiness fallback.
Bad example
| 1 | const step = parseInt(req.params.step); |
Explanation (EN)
A radix does not prevent NaN or partial parsing; truthiness defaults can silently replace valid values.
Objašnjenje (HR)
Good example
| 1 | const raw = req.params.step; |
| 2 | if (!/^[0-9]+$/.test(raw)) throw new Error("Invalid step"); |
| 3 | const step = parseInt(raw, 10); |
| 4 | if (!Number.isSafeInteger(step)) throw new Error("Step out of range"); |
Explanation (EN)
Decimal parsing follows whole-string validation and preserves a valid zero.
Objašnjenje (HR)
Notes (EN)
When parsing an integer string, choose the intended radix and separately validate the entire input and allowed numeric range before defaulting.
Exceptions / Tradeoffs (EN)
parseInt accepts numeric prefixes, and zero may be valid. Do not use || as a missing-value fallback when it would discard zero.