unsafe-numbers
What it does
Section titled “What it does”Reports a number that a double-precision parser (JavaScript and most JSON libraries) cannot hold exactly: an integer beyond 2^53 - 1, a value that overflows to infinity, or one that underflows to zero or is subnormal.
Why it matters
Section titled “Why it matters”JSON allows any number of digits, but most parsers read numbers as 64-bit floating point. A large integer such as an id then changes silently (12345678901234567890 becomes 12345678901234567000), and 1e999 becomes infinity, so the receiver sees a different value from the one that was written.
To fix, write the value as a string.
Example
Section titled “Example”[9007199254740991, 9007199254740992, -12345678901234567890, 1e999, 1e-999, 5e-324, 0, 0.0e5, 1.5, 12345678901234567890.5]Configuration
Section titled “Configuration”json: lint: rules: unsafe-numbers: warn # off (default), warn, errorSuppress one line with sudsy-disable-next-line unsafe-numbers in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.
| Tool | Rule | Match | What differs |
|---|---|---|---|
| Biome | nursery/noJsonUnsafeValues |
partial | lone UTF-16 surrogates in strings are not reported |