An answer nobody reads, arguments in the wrong parameters: unused-answer from measured data, misplaced-argument from names #137

Merged
sionzee merged 143 commits from unread-answers into main 2026-11-22 17:34:01 +01:00
Owner

Based on values-asked-everywhere (#136), and contains it: the diff shown is this piece alone.

Two more of the kinds of bug the study in #131 found in an adopter's history and today's checker is silent on. Each of these passed tsc strict, safe-ts check --deny-warnings and oxlint:

new TextEncoder().encodeInto(text, out);     // says how much it wrote in { read, written }: ignored, a cut string is sent
name.trim();                                 // returns the trimmed string; `name` is unchanged
list.concat(more);    items.slice(1);    text.replace(a, b);    new Date(t).toISOString();

function corner(size: number, x: number, y: number, margin = 1) { ... }
corner(x, y, 1.05);                          // a parameter was inserted in front; this call kept its arguments
copy(source, target);                        // for copy(target, source)

Rust has #[must_use] for the first. For the second, every type fits, so TypeScript is content; only the names say what happened.

Two rules

unused-answer (error): a statement that calls something whose only point is its answer.

  • Which members those are is measured, not listed. A new answers section in the API maps: a script calls every member of the language map on sample receivers and arguments and keeps the 875 that answered something and changed neither receiver nor arguments. A test measures again and fails when the list differs. The 235 it leaves out are listed with the reason (they changed something, answer nothing, or belong to iterators, weak collections and promises, whose effects a snapshot cannot show).
  • A short second list: members that do something and answer how much happened (encodeInto, Atomics.compareExchange, readSync, confirm, prompt), each chosen by how real packages treat the answer. Map#delete, RegExp#test, writeSync and Reflect.set are out: their answer is dropped on purpose too often (RegExp#test 383 times in installed packages, for lastIndex).
  • A function of the program counts when a whole-program effect analysis shows it changes nothing it did not make, cannot fail, and calls only functions that meet the same test.
  • A call that can fail where it stands (JSON.parse(text);) is the failure rules', since it may be made for its throw. void expr; says the drop is meant. No quick fix: whether the answer was meant to be assigned or returned is not the checker's to guess.

misplaced-argument (warning): two or more arguments whose names are the names of other parameters of the callee, shifted the same distance or swapped in pairs, where the parameter types are the same as a call sees them (readonly, Readonly<T> and Mut<T> taken off). Names are read through pos.x, mut(x) and a const read once; methods, constructors and calls across files are covered. Exempt: both orders in one function (ranks(a, b) || -ranks(b, a)), a function calling itself, built-in signatures (the maps carry no parameter names).

The oxlint preset now names no-unused-expressions, which owns the same mistake written as c ? a.trim() : b.trim(); or c && a.trim();. It fired only through oxlint's default category.

Evidence

  • Held-out cases, written before the implementation.
    • Of 35 dropped answers in two files: 28 are reported by the rule, 6 by the gate that owns them (four by the failure rules, two by oxlint), and one is missed (through map.get(k)?.name, on the page). Receivers are found through a parameter, a member, a loop variable, an element by index, a field, a chain, a template literal, a new written in place.
    • Everything made for its effect is silent: push, sort, reverse, splice, pop, a set's add and delete, a map's set, forEach, Object.freeze, an iterator's next(), a global pattern's exec.
    • Arguments: all 10 misplaced calls are reported (a shift, a swap, member names, a constructor, a method, clamp(min, value, max), across files, destination and source, through mut(...)), and all 11 correct ones are silent, including a reversed comparator and Math.atan2(y, x). The first round missed destination and source because it wanted both parameter types written identically; fixed.
    • The rule also caught two dropped answers in my own test file that I had not meant to write.
  • An adopter's project: no finding from either rule today, and nothing else changes. The code before each of the two real fixes is reported at the place of the bug, and the code after is silent.
  • Five open-source packages: no finding from either rule. For the program's own functions the first definitions gave 2,726 and then 1,413 candidates on the adopter; the final one gives none there and none on three packages, after reading the 41 the middle definition left (all made for the type checker, such as assertNever(x)).
  • Soundness corpus: encode-into-unchecked and argument-shift-after-insert are closed, each by its rule alone, and a new class for a plain dropped answer was added and closed. 16 of 99 escape.
  • Rewrite list: the two rules add 3 silent sites (through a hoisted const the query does not follow) and two lines for quoting a callee with its parentheses.
  • Cost: per-file analysis on that project's largest entry 208 ms before, 214 ms after; whole-program pass 515 ms and 526 ms (minimum of 21 interleaved runs, mine). The first version cost 20 ms on the pass; most of it was asking a type question for every set.add(x) because add is also a method of another class.

What turns red on upgrade

  • A dropped answer is an error. Use it, or write void in front if the drop is meant.
  • no-unused-expressions is an error where it was a warning.
  • Eight lines in this repository's fixtures written for other rules dropped an answer and now say so.

For the owner to decide

set-add-counted-twice stays open. No rule can close it honestly: in the real fix the function still returns true after an unconditional add, and the repair went into the caller. What would close it is a small helper in std, insert(set, value): boolean, which says whether the value was new. Not added: an addition to std is yours to make.

What stays unseen

  • Browser and Node members with no effect but their answer (URLSearchParams#get): only the language map is measured.
  • A dropped answer that is not a statement (an arrow whose body is the call); a call of the program's code in the receiver (label(name).trim();).
  • misplaced-argument: one argument out of place alone; names that do not match the parameter (px for x); built-in signatures.
  • A date made from a number: new Date(n).toISOString() can throw and the failure rules do not say so (older than this piece).

Created with Claude Opus 5.5 (implementation and the merges) and Claude Fable 5.2 (review, acceptance tests and the last merge) in Claude Code.

Based on `values-asked-everywhere` (#136), and contains it: the diff shown is this piece alone. Two more of the kinds of bug the study in #131 found in an adopter's history and today's checker is silent on. Each of these passed `tsc` strict, `safe-ts check --deny-warnings` and oxlint: ```ts new TextEncoder().encodeInto(text, out); // says how much it wrote in { read, written }: ignored, a cut string is sent name.trim(); // returns the trimmed string; `name` is unchanged list.concat(more); items.slice(1); text.replace(a, b); new Date(t).toISOString(); function corner(size: number, x: number, y: number, margin = 1) { ... } corner(x, y, 1.05); // a parameter was inserted in front; this call kept its arguments copy(source, target); // for copy(target, source) ``` Rust has `#[must_use]` for the first. For the second, every type fits, so TypeScript is content; only the names say what happened. ## Two rules **`unused-answer`** (error): a statement that calls something whose only point is its answer. - **Which members those are is measured, not listed.** A new `answers` section in the API maps: a script calls every member of the language map on sample receivers and arguments and keeps the 875 that answered something and changed neither receiver nor arguments. A test measures again and fails when the list differs. The 235 it leaves out are listed with the reason (they changed something, answer nothing, or belong to iterators, weak collections and promises, whose effects a snapshot cannot show). - **A short second list: members that do something and answer how much happened** (`encodeInto`, `Atomics.compareExchange`, `readSync`, `confirm`, `prompt`), each chosen by how real packages treat the answer. `Map#delete`, `RegExp#test`, `writeSync` and `Reflect.set` are out: their answer is dropped on purpose too often (`RegExp#test` 383 times in installed packages, for `lastIndex`). - **A function of the program** counts when a whole-program effect analysis shows it changes nothing it did not make, cannot fail, and calls only functions that meet the same test. - A call that can fail where it stands (`JSON.parse(text);`) is the failure rules', since it may be made for its throw. `void expr;` says the drop is meant. No quick fix: whether the answer was meant to be assigned or returned is not the checker's to guess. **`misplaced-argument`** (warning): two or more arguments whose names are the names of *other* parameters of the callee, shifted the same distance or swapped in pairs, where the parameter types are the same as a call sees them (`readonly`, `Readonly<T>` and `Mut<T>` taken off). Names are read through `pos.x`, `mut(x)` and a `const` read once; methods, constructors and calls across files are covered. Exempt: both orders in one function (`ranks(a, b) || -ranks(b, a)`), a function calling itself, built-in signatures (the maps carry no parameter names). **The oxlint preset now names `no-unused-expressions`**, which owns the same mistake written as `c ? a.trim() : b.trim();` or `c && a.trim();`. It fired only through oxlint's default category. ## Evidence - **Held-out cases, written before the implementation.** - Of 35 dropped answers in two files: 28 are reported by the rule, 6 by the gate that owns them (four by the failure rules, two by oxlint), and one is missed (through `map.get(k)?.name`, on the page). Receivers are found through a parameter, a member, a loop variable, an element by index, a field, a chain, a template literal, a `new` written in place. - Everything made for its effect is silent: `push`, `sort`, `reverse`, `splice`, `pop`, a set's `add` and `delete`, a map's `set`, `forEach`, `Object.freeze`, an iterator's `next()`, a global pattern's `exec`. - Arguments: all 10 misplaced calls are reported (a shift, a swap, member names, a constructor, a method, `clamp(min, value, max)`, across files, destination and source, through `mut(...)`), and all 11 correct ones are silent, including a reversed comparator and `Math.atan2(y, x)`. The first round missed destination and source because it wanted both parameter types written identically; fixed. - The rule also caught two dropped answers in my own test file that I had not meant to write. - **An adopter's project: no finding from either rule today, and nothing else changes.** The code before each of the two real fixes is reported at the place of the bug, and the code after is silent. - **Five open-source packages:** no finding from either rule. For the program's own functions the first definitions gave 2,726 and then 1,413 candidates on the adopter; the final one gives none there and none on three packages, after reading the 41 the middle definition left (all made for the type checker, such as `assertNever(x)`). - **Soundness corpus:** `encode-into-unchecked` and `argument-shift-after-insert` are closed, each by its rule alone, and a new class for a plain dropped answer was added and closed. 16 of 99 escape. - **Rewrite list:** the two rules add 3 silent sites (through a hoisted `const` the query does not follow) and two lines for quoting a callee with its parentheses. - **Cost:** per-file analysis on that project's largest entry 208 ms before, 214 ms after; whole-program pass 515 ms and 526 ms (minimum of 21 interleaved runs, mine). The first version cost 20 ms on the pass; most of it was asking a type question for every `set.add(x)` because `add` is also a method of another class. ## What turns red on upgrade - A dropped answer is an error. Use it, or write `void` in front if the drop is meant. - `no-unused-expressions` is an error where it was a warning. - Eight lines in this repository's fixtures written for other rules dropped an answer and now say so. ## For the owner to decide `set-add-counted-twice` stays open. No rule can close it honestly: in the real fix the function still returns `true` after an unconditional `add`, and the repair went into the caller. What would close it is a small helper in std, `insert(set, value): boolean`, which says whether the value was new. Not added: an addition to std is yours to make. ## What stays unseen - Browser and Node members with no effect but their answer (`URLSearchParams#get`): only the language map is measured. - A dropped answer that is not a statement (an arrow whose body is the call); a call of the program's code in the receiver (`label(name).trim();`). - `misplaced-argument`: one argument out of place alone; names that do not match the parameter (`px` for `x`); built-in signatures. - A date made from a number: `new Date(n).toISOString()` can throw and the failure rules do not say so (older than this piece). Created with Claude Opus 5.5 (implementation and the merges) and Claude Fable 5.2 (review, acceptance tests and the last merge) in Claude Code.
unused-answer and misplaced-argument: an answer nobody reads, arguments in the wrong parameters
All checks were successful
Benchmarks / bench (pull_request) Successful in 2m5s
Tests / test (pull_request) Successful in 9m46s
7f6d171c2e
Open: a call whose only point is its answer, written as a statement (name.trim();
list.concat(more); encodeInto, whose answer says how much was written), passed every gate; so
did a call whose arguments land in the wrong parameters after a parameter was inserted, when
every type still fits. Both are classes of the field study with real fixes behind them.

unused-answer (an error) reads which members have no effect but their answer from a new
`answers` section of the API maps: 875 members of the language map, each measured by calling
it and watching what changes, with a test that measures again; and a short list of members
whose answer says how much happened (encodeInto, readSync, confirm). A function of the program
counts when a whole-program effect analysis shows it changes nothing.

misplaced-argument (a warning) reports two or more arguments whose names are the names of
other parameters of the callee, shifted the same distance or swapped in pairs, where the
parameter types are the same as a call sees them (readonly and Mut taken off), also through
mut(...) and a const read once.

The oxlint preset names no-unused-expressions, which owns the forms written as ?: and &&.

Soundness corpus: encode-into-unchecked and argument-shift-after-insert are closed, and a new
class for a plain dropped answer; 16 of 99 escape.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
sionzee changed target branch from values-asked-everywhere to main 2026-11-22 17:32:27 +01:00
Merge main: the piece below has landed
Some checks failed
Tests / test (pull_request) Has been cancelled
Benchmarks / bench (pull_request) Has been cancelled
2e13531c9e
Co-Authored-By: Claude Fable 5.2 <[email protected]>
sionzee deleted branch unread-answers 2026-11-22 17:34:01 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Evobug/Safe-Ts!137
No description provided.