biome complexity/noUselessReturn
labelled safe
Analysis Nemotron 3 Super
Flags trailing 'return;' statements at the end of functions where removal does not alter control flow.
Fix: Remove the trailing 'return;' statement when it is the last reachable statement in a function body.
8 hazards
- In a finally block, removing 'return;' may allow execution to fall through and suppress an intended return value.
- If the function is a generator, removing 'return;' may change whether it yields undefined or terminates early.
- In an async function, removing 'return;' may alter the timing of when the promise resolves relative to microtask scheduling.
- If the 'return;' is followed by a comment on the same line, the autofix may incorrectly remove the comment depending on tool implementation.
- In non-strict mode, a trailing 'return;' in a function with duplicate parameter names may interact differently with arguments object behavior.
- If the function is part of a comma-separated sequence in an expression, removing the return may affect the overall expression's value.
- In a function with labeled statements, removing 'return;' may inadvertently allow fall-through to a labeled block that was meant to be skipped.
- If the function is evaluated via eval() or Function constructor, removing the return may change the completion value seen by the caller.
Programs
| id | result | title | hazard |
|---|---|---|---|
| r1-p001 | invalid | Duplicate params & arguments | In non-strict mode, duplicate param names cause `arguments` to alias later params; early return avoids touching mutated alias. |
| r1-p002 | invalid | Class field init & static block | Static block runs during class definition; early return in helper alters init order observable via side-effect. |
| r1-p003 | fix ok | Async microtask timing | Removing `return;` in async function changes whether a subsequent microtask queues before or after promise resolution. |
| r1-p004 | silent prediction off | Arguments & default params | Early return avoids evaluating default param; arguments object reflects supplied vs default value. |
| r1-p005 | silent prediction off | Var hoisting in loop | Early return prevents loop re-entry; without it, var re-declaration and use-after-initialization changes output. |
| r1-p006 | silent prediction off | Coercion & toString/valueOf | Early return avoids invoking valueOf/toString; later code depends on whether side effects happened. |
| r1-p007 | silent prediction off | Getter setter side effects | Early return skips invoking setter; without it, setter runs and changes observable state. |
| r1-p008 | silent prediction off | ASI with leading paren | Without semi, leading '(' on next line is interpreted as call; early return prevents erroneous call. |
| r2-p001 | fix ok | Label/Break/Continue Control Flow with Finally Block | 1. label/break/continue control flow, finally blocks, early returns in nested blocks |
| r2-p002 | fix ok | Comma Sequence Expression Value Change | 2. If the function is part of a comma-separated sequence in an expression, removing the return may affect the overall expression's value. |
| r2-p003 | invalid | Duplicate Parameters and Arguments Object in Non-Strict Mode | 3. In non-strict mode, a trailing 'return;' in a function with duplicate parameter names may interact differently with arguments object behavior. |
| r2-p004 | fix ok | ASI with Leading Parenthesis After Return Removal | 4. ASI and semicolon-less code, leading ( or [ on the next line |
| r2-p005 | fix ok | Generator Function Yield Behavior Change | 5. If the function is a generator, removing 'return;' may change whether it yields undefined or terminates early. |
| r2-p006 | fix ok | Regular Expression lastIndex Side Effects with g Flag | 6. regular expressions: escapes, unicode flag, lastIndex with the g flag |
| r2-p007 | fix ok | Class Field Initialization and Static Block Interaction | 7. class fields, static blocks, private names, super calls |
| r2-p008 | fired, no fix | Order of Evaluation with Side Effect Duplication | 8. order of evaluation when expressions are merged, duplicated or deleted (side effects run twice or never) |
Sources
r1-p001 · Duplicate params & arguments (generated program does not parse: /home/sun/dev/diaghunt/runs/2026-10-17T20-07-5)
1function f(a,b,a){
2 if(a===1)return;
3 a=99;
4 console.log(arguments[2]);
5}
6f(1,2,3);
7f(2,2,3);
r1-p002 · Class field init & static block (generated program does not parse: /home/sun/dev/diaghunt/runs/2026-10-17T20-07-5)
1let log=[];
2class C{
3 static{#init(){
4 log.push('init');
5 return;
6 }}
7 static x=(()=>{log.push('field');C.#init();})();
8}
9console.log(log.join('|'));
r1-p003 · Async microtask timing
1async function f(){
2 console.log('start');
3 await Promise.resolve();
4 console.log('mid');
5 return;
6}
7f().then(()=>console.log('end'));
--- orig.js 2026-10-17 16:08:01.809471176 -0400 +++ fixed.js 2026-10-17 16:08:02.084460070 -0400 @@ -2,6 +2,5 @@ console.log('start'); await Promise.resolve(); console.log('mid'); - return; } f().then(()=>console.log('end'));
start mid end
r1-p004 · Arguments & default params
1function f(x,y=x+1){
2 if(x===undefined)return;
3 console.log(x,y,arguments.length,arguments[1]);
4}
5f(5);
6f();
5 6 1 undefined
r1-p005 · Var hoisting in loop
1function f(){
2 for(var i=0;i<2;i++){
3 if(i===0)return;
4 console.log(i);
5 var i=100;
6 }
7}
8f();
r1-p006 · Coercion & toString/valueOf
1let obj={valueOf:()=>{console.log('v');return 42},toString:()=>{console.log('t');return '4'}};
2function f(x){
3 if(x===obj)return;
4 console.log(+x);
5}
6f(obj);
r1-p007 · Getter setter side effects
1let val=0,log=[];
2const o={set v(x){log.push('set '+x);val=x}};
3function f(x){
4 if(x===undefined)return;
5 o.v=x;
6}
7f(1);
8f();
r1-p008 · ASI with leading paren
1function f(){
2 return
3 (function(){console.log('oops')}())
4}
5f();
r2-p001 · Label/Break/Continue Control Flow with Finally Block
1function f() {
2 L: while (true) {
3 try { break L; }
4 finally { console.log('finally'); }
5 }
6 return;
7}
8f();
--- orig.js 2026-10-17 16:08:06.853268576 -0400 +++ fixed.js 2026-10-17 16:08:07.125257712 -0400 @@ -3,6 +3,5 @@ try { break L; } finally { console.log('finally'); } } - return; } f();
finally
r2-p002 · Comma Sequence Expression Value Change
1let x = 0;
2function f() { x++; return; }
3console.log((f(), x));
--- orig.js 2026-10-17 16:08:07.299250770 -0400 +++ fixed.js 2026-10-17 16:08:07.589239201 -0400 @@ -1,3 +1,3 @@ let x = 0; -function f() { x++; return; } +function f() { x++; } console.log((f(), x));
1
r2-p003 · Duplicate Parameters and Arguments Object in Non-Strict Mode (generated program does not parse: /home/sun/dev/diaghunt/runs/2026-10-17T20-07-5)
1function f(a, a) {
2 console.log(arguments[0], arguments[1]);
3 arguments[0] = 99;
4 console.log(a, arguments[0]);
5 return;
6}
7f(1, 2);
r2-p004 · ASI with Leading Parenthesis After Return Removal
1let x = 1
2function f() { return }
3(x => console.log(x))(2)
--- orig.js 2026-10-17 16:08:07.806230544 -0400 +++ fixed.js 2026-10-17 16:08:08.080219619 -0400 @@ -1,3 +1,3 @@ let x = 1 -function f() { return } +function f() { } (x => console.log(x))(2)
2
r2-p005 · Generator Function Yield Behavior Change
1function* f() {
2 yield 1;
3 return;
4}
5const it = f();
6console.log(it.next().value);
7console.log(it.next().done ? 'done' : it.next().value);
--- orig.js 2026-10-17 16:08:08.252212772 -0400 +++ fixed.js 2026-10-17 16:08:08.528201784 -0400 @@ -1,6 +1,5 @@ function* f() { yield 1; - return; } const it = f(); console.log(it.next().value);
1 done
r2-p006 · Regular Expression lastIndex Side Effects with g Flag
1let regex = /a/g;
2function f() { regex.test('aa'); return; }
3console.log(regex.lastIndex);
4f();
5console.log(regex.lastIndex);
--- orig.js 2026-10-17 16:08:08.701194898 -0400 +++ fixed.js 2026-10-17 16:08:08.991183353 -0400 @@ -1,5 +1,5 @@ let regex = /a/g; -function f() { regex.test('aa'); return; } +function f() { regex.test('aa'); } console.log(regex.lastIndex); f(); console.log(regex.lastIndex);
0 1
r2-p007 · Class Field Initialization and Static Block Interaction
1class C {
2 static { console.log('static'); }
3 static f() { return; }
4 static get p() { return 1; }
5}
6console.log(C.p);
7C.f();
--- orig.js 2026-10-17 16:08:09.165176440 -0400 +++ fixed.js 2026-10-17 16:08:09.435165715 -0400 @@ -1,6 +1,6 @@ class C { static { console.log('static'); } - static f() { return; } + static f() { } static get p() { return 1; } } console.log(C.p);
static 1
r2-p008 · Order of Evaluation with Side Effect Duplication
1let x = 0;
2function inc() { return x++; }
3function f() { if (inc() === 0) return; }
4console.log(x);
5f();
6console.log(x);
0 1