fixhunt

biome complexity/useFlatMap: fix changes program behavior

fix-changes-behaviorlabelled safeprogram-bug · lowrelated
Findings / 2026-10-17T20-12-00-746Z-4q9e-biome-complexity_useFlatMap / r1-p006biome 2.5.155 → 4 lines2026-10-17 20:12 UTC

Hypothesis Nemotron 3 Super predicted to fire fired 1×

arguments object, function.length, default parameters, rest parameters

Program

before
1function process(a, b = [], ...rest) {
2 return arguments.map(x => [x]).flat();
3}
4const res = process(1, 2, 3);
after
1function process(a, b = [], ...rest) {
2 return arguments.flatMap(x => [x]);
3}
4const res = process(1, 2, 3);

Output

stdout beforeexit 1
(no stdout)
TypeError: arguments.map is not a function
stdout afterexit 1
(no stdout)
TypeError: arguments.flatMap is not a function
fired
1 before · 0 after
runs
each version twice, same file name, no network

Judge Nemotron 3 Ultra advisory program-bug · low

The program fails both before and after the fix because `arguments` is an array-like object without `map` or `flatMap` methods. The rewrite does not change the error; the failure is unrelated to the rule's transformation.

Explanation Nemotron 3 Super unverified

The `arguments` object is array-like but lacks built-in methods like `.map` or `.flatMap`. Both versions attempt to call these methods directly on `arguments`, which fails because they are not defined on the arguments object. The error changes from `arguments.map is not a function` to `arguments.flatMap is not a function`, but the underlying issue remains: neither method exists on `arguments`. Thus, the rewrite does not fix the core problem and still throws a TypeError, preserving the failure mode rather than correcting it. The behavior differs only in which method name appears in the error, not in semantic correctness.

Reproduce

file
prog.js (the before program)
minimized program
r1-p006.js
evidence sheet
r1-p006.md
regression fixture
r1-p006.js the minimized program with a header stating the observed change, for the tool's test suite
node prog.js
bunx @biomejs/biome lint --only=complexity/useFlatMap --write prog.js
node prog.js

Upstream search GitHub issues Tavily Nemotron 3 Super + Ultra

useFlatMap fix · biome complexity/useFlatMap arguments map flat · biome complexity/useFlatMap arguments flatMap replacement · biome complexity/useFlatMap rest parameters usage

Details

program
Arguments Object and Parameters
hazard
arguments object, function.length, default parameters, rest parameters
oracle
stderr before: TypeError: arguments.map is not a function stderr after: TypeError: arguments.flatMap is not a function
run
2026-10-17T20-12-00-746Z-4q9e-biome-complexity_useFlatMap
generated program (5 lines) and the fix's diff
1function process(a, b = [], ...rest) {
2 return arguments.map(x => [x]).flat();
3}
4const res = process(1, 2, 3);
5console.log(res.length, res.join(','));
--- orig.js	2026-10-17 16:12:13.830635639 -0400
+++ fixed.js	2026-10-17 16:12:14.086629700 -0400
@@ -1,5 +1,5 @@
 function process(a, b = [], ...rest) {
-  return arguments.map(x => [x]).flat();
+  return arguments.flatMap(x => [x]);
 }
 const res = process(1, 2, 3);
 console.log(res.length, res.join(','));
rule documentation given to the models
Summary

- Name: useFlatMap
- Fix: safe
- Default severity: info
- Available from version: 1.0.0
- Diagnostic category: lint/complexity/useFlatMap
- This rule is recommended

Description

 Promotes the use of `.flatMap()` when `map().flat()` are used together.

 Using `.flatMap()` instead of `map().flat()` avoids the creation of
 an intermediate array.

Examples

Invalid

 ```js,expect_diagnostic
 const array = ["split", "the text", "into words"];
 array.map(sentence => sentence.split(' ')).flat();
 ```

 ```js,expect_diagnostic
 const array = ["split", "the text", "into words"];
 array.map(sentence => sentence.split(' ')).flat(1);
 ```

Valid

 ```js
 const array = ["split", "the text", "into words"];
 array.map(sentence => sentence.split(' ')).flat(2);
 ```