diff --git a/.coderabbit.yml b/.coderabbit.yml index 6d25d08b8942..b33c1e4b8b8e 100644 --- a/.coderabbit.yml +++ b/.coderabbit.yml @@ -16,3 +16,16 @@ reviews: # avoiding. base_branches: - 'v7' + path_instructions: + - path: '**/*.{ts,tsx,mts,cts,js,mjs,cjs}' + instructions: >- + Decimal, bigint and 64-bit integer types exist to hold values a JavaScript number would round, so flag + a change that routes such a value through a number for convenience: Number() or parseFloat() on it + without a check that proves the conversion is exact (a safe-integer range check is enough for a bigint or + 64-bit integer, but not for a Decimal, since 1.0000000000000001 passes a range check and becomes 1), or + an override of valueOf or Symbol.toPrimitive on a value class (Prisma.Decimal included) meant to make + <, >, == or arithmetic work. A string-returning override is wrong too, because < then compares "10" + and "2" as text. Native bigint comparison, addition, subtraction and multiplication are already exact (division drops the fraction). Decimal has no exact operators, since + JavaScript has no operator overloading, so ask for its own methods instead, such as a.lt(b) or + a.cmp(b). Also flag a subclass or patch that changes a third-party library's documented behaviour; + that belongs upstream. diff --git a/AGENTS.md b/AGENTS.md index ac5a6034743c..370a46e18146 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -147,6 +147,7 @@ - Do write documentation comments, and mainly do so for exported items (although intra-module documentation may sometimes be useful as well). - The correct and official abbreviation of WebAssembly is "Wasm", not "WASM". There are instances of "WASM" in the codebase, but they are wrong and you should not repeat them. Fix the capitalization whenever you incidentally touch the corresponding lines or surrounding code for other reasons. - Prefer native JavaScript private properties and methods (`#field`) over the `private` keyword in TypeScript. + - **Never make a value lossy for convenience.** `Decimal`, `bigint` and 64-bit integer values exist to hold numbers a JavaScript number would round, so do not convert one with `Number()` or `parseFloat()` unless the code first proves the conversion is exact (for a `bigint` or 64-bit integer, a check that it is within `Number.MAX_SAFE_INTEGER`; a range check does not make a `Decimal` exact, since `1.0000000000000001` is within any range around 1 and still becomes `1`), and do not override `valueOf` or `Symbol.toPrimitive` on a value class (`Prisma.Decimal` included) to make `<`, `>` or arithmetic work: a number-returning override rounds, so decimals that differ beyond about 15 significant digits compare as equal, and a string-returning one compares `"10"` and `"2"` as text. Native `bigint` comparison, addition, subtraction and multiplication are already exact (division drops the fraction: `5n / 2n` is `2n`). `Decimal` has no exact operators, since JavaScript has no operator overloading, so point users at its own methods (`a.lt(b)`, `a.cmp(b)`). A third-party library's documented behaviour is changed upstream, not by subclassing or patching it here. Reviewers flag any pull request that does either. - **Workflow reminders**: - Respect existing structure: modifications often require updating both command implementation and tests/fixtures.