no-loss-of-precision
What it does
Section titled “What it does”Reports a number literal that the 64-bit double it becomes does not hold exactly: 9007199254740993 (above 2^53), 0x20000000000001, a value that is too large (1e400, becomes Infinity) or too small (2e-400, becomes 0). 9007199254740992, 0.1, a number that has an exact double (1e20) and BigInt literals (123n) are not reported.
Why it matters
Section titled “Why it matters”JavaScript rounds such a literal when the file is read, so the program computes with another number than the one written, with no error. Integers above 2^53 lose their last digits, which breaks ids and counters.
To fix, use a BigInt literal (9007199254740993n), keep the value in a string, or write the number the double really holds.
Example
Section titled “Example”...var p = 9007199254740993, q = 0.1, r = 5123000000000000000000000000001, s = 0x20000000000001, t = 0x1fffffffffffff;var u = 12345678901234567890, v = 0.30000000000000004, w = 1_000, x = 0.1000000000000000055511151231257827, y = 1e3;Configuration
Section titled “Configuration”js: lint: rules: no-loss-of-precision: warn # off, warn (default), errorEnabled by the presets: js/eslint-recommended, js/biome-recommended, js/oxlint.
Suppress one line with sudsy-disable-next-line no-loss-of-precision in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| eslint | no-loss-of-precision |
full |