Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Guard optional numbers with typeof, not !== undefined
Validate finite numeric values and their allowed range; typeof number alone does not reject NaN or Infinity.
Bad example
| 1 | ...(logo.width !== undefined && { width: String(logo.width) }) |
| 2 | // logo.width === null -> emits width: "null" |
Explanation (EN)
An undefined-only guard admits null from a nullable boundary.
Objašnjenje (HR)
Provjera samo undefined propušta null s nullable granice.
Good example
| 1 | const width = logo.width; |
| 2 | const attrs = { |
| 3 | ...(typeof width === "number" && Number.isFinite(width) && width > 0 |
| 4 | ? { width: String(width) } |
| 5 | : {}), |
| 6 | }; |
Explanation (EN)
This contract includes only positive finite widths; choose integer or zero handling according to the receiving API.
Objašnjenje (HR)
Ovaj ugovor uključuje samo pozitivne konačne širine. Obradu nule i zahtjev za cijelim brojem odredi prema API-ju primatelja.
Notes (EN)
Validate the numeric domain before formatting optional dimensions; distinguish omission from null and reject NaN/infinity when finite values are required.
Exceptions / Tradeoffs (EN)
typeof NaN and typeof Infinity are both number. Zero/negative/fractional values need the specific API's range policy; an undefined-only check is sufficient if the trusted type truly excludes other cases.