eslint arrow-body-style
labelled safe
Analysis Nemotron 3 Super
Flags arrow functions whose implicit/explicit brace usage conflicts with the configured style.
Fix: Adds or removes braces and inserts 'return' statements as needed to match the configured style while preserving semantic equivalence.
8 hazards
- Rewriting '() => expr;' to '() => { return expr; }' changes behavior if 'expr' contains commas due to altered precedence grouping.
- Adding braces around '() => {}' introduces a new block scope that could capture 'this' or 'arguments' differently in non-strict mode.
- Inserting 'return' for '() => { expr; }' may cause early exit if the original block contained multiple statements where later ones were intended to run.
- Removing braces from '() => { return expr; }' breaks if 'expr' is an object literal without parentheses, causing parsing as a block.
- The fix may relocate or delete trailing comments attached to the arrow function's original syntax (e.g., after '=>').
- Wrapping a multi-expression body in braces without adjusting semicolons could trigger ASI issues if the caller expects a specific expression value.
- Converting '() => { throw e; }' to '() => throw e;' alters control flow because the implicit return wraps the throw in an expression context.
- Adding braces around '() => void 0;' creates a block where 'void 0' is a statement, which is harmless but may affect code coverage tools that track statement execution.
Programs
| id | result | title | hazard |
|---|---|---|---|
| r1-p001 | silent prediction off | Hazard 1: Arrow function empty body - block scope captures this/arguments | Adding braces around '() => {}' introduces a new block scope that could capture 'this' or 'arguments' differently in non-strict mode. |
| r1-p002 | silent | Hazard 2: Regular expressions with unicode flag and lastIndex | regular expressions: escapes, unicode flag, lastIndex with the g flag |
| r1-p003 | invalid | Hazard 3: Comma in expression body changed by braces | Rewriting '() => expr;' to '() => { return expr; }' changes behavior if 'expr' contains commas due to altered precedence grouping. |
| r1-p004 | silent prediction off | Hazard 4: Proto keys, prototype access, Object.assign vs spread | __proto__ keys, prototype access, Object.assign vs spread |
| r1-p005 | silent prediction off | Hazard 5: Multi-expression body wrapped in braces triggers ASI | Wrapping a multi-expression body in braces without adjusting semicolons could trigger ASI issues if the caller expects a specific expression value. |
| r1-p006 | silent prediction off | Hazard 6: Void 0 in block affects coverage tools | Adding braces around '() => void 0;' creates a block where 'void 0' is a statement, which is harmless but may affect code coverage tools that track statement execution. |
| r1-p007 | invalid | Hazard 7: Class fields, static blocks, private names, super calls | class fields, static blocks, private names, super calls |
| r1-p008 | fix ok | Hazard 8: ASI and semicolon-less code with leading ( or [ | ASI and semicolon-less code, leading ( or [ on the next line |
| r2-p001 | invalid | Trailing Comment Relocation | Fix may relocate or delete trailing comments attached to the arrow function's original syntax |
| r2-p002 | silent prediction off | Early Return in Multi-Statement Block | Inserting 'return' for '() => { expr; }' may cause early exit if the original block contained multiple statements where later ones were intended to run |
| r2-p003 | silent prediction off | Throw in Expression Context | Converting '() => { throw e; }' to '() => throw e;' alters control flow because the implicit return wraps the throw in an expression context |
| r2-p004 | silent | Sparse Arrays and Holes | sparse arrays, holes, Array(n) vs [n], array-likes |
| r2-p005 | invalid | Comma Precedence in Expression Body | Rewriting '() => expr;' to '() => { return expr; }' changes behavior if 'expr' contains commas due to altered precedence grouping |
| r2-p006 | silent prediction off | Name Collision After Scope Move | name collisions across scopes after a move (shadowing) |
| r2-p007 | silent | Null/Undefined Distinction with Optional Chaining | null/undefined distinction, optional chaining short-circuit, nullish vs falsy |
| r2-p008 | silent prediction off | Order of Evaluation Side Effects | order of evaluation when expressions are merged, duplicated or deleted (side effects run twice or never) |
Sources
r1-p001 · Hazard 1: Arrow function empty body - block scope captures this/arguments
1(function(){ var f = () => {}; console.log('unwrapped:', typeof f); })();
2(function(){ var f = () => {}; console.log('wrapped:', typeof f()); })();
unwrapped: function wrapped: undefined
r1-p002 · Hazard 2: Regular expressions with unicode flag and lastIndex
1var r = /\u{61}/gu; console.log(r.lastIndex, r.exec('a')); r.lastIndex = 0; console.log(r.lastIndex, r.exec('a'));
0 [ 'a', index: 0, input: 'a', groups: undefined ] 0 [ 'a', index: 0, input: 'a', groups: undefined ]
r1-p003 · Hazard 3: Comma in expression body changed by braces (generated program does not parse: /home/sun/dev/diaghunt/runs/2026-10-22T18-11-2)
1var obj = { prop: 42 }; var get = () => obj.prop, 0; console.log(get());
r1-p004 · Hazard 4: Proto keys, prototype access, Object.assign vs spread
1var o = { __proto__: null }; var f = () => ({ __proto__: Object.prototype }); console.log(f().__proto__ === Object.prototype);
true
r1-p005 · Hazard 5: Multi-expression body wrapped in braces triggers ASI
1var f = () => { a = 1, b = 2 }; console.log(f(), a, b);
undefined 1 2
r1-p006 · Hazard 6: Void 0 in block affects coverage tools
1var count = 0; var inc = () => { count++; }; var f = () => void 0; console.log(count, f(), inc());
0 undefined undefined
r1-p007 · Hazard 7: Class fields, static blocks, private names, super calls (generated program does not parse: /home/sun/dev/diaghunt/runs/2026-10-22T18-11-2)
1class C { static { console.log('static') } #x = 1; getX() { return #x; } } console.log(new C().getX());
r1-p008 · Hazard 8: ASI and semicolon-less code with leading ( or [
1var f = () => { return 42 }; (() => { console.log(f()) })()
--- orig.js 2026-10-22 14:11:34.323545296 -0400 +++ fixed.js 2026-10-22 14:11:37.937542398 -0400 @@ -1 +1 @@ -var f = () => { return 42 }; (() => { console.log(f()) })() +var f = () => 42; (() => { console.log(f()) })()
42
r2-p001 · Trailing Comment Relocation (generated program does not parse: /home/sun/dev/diaghunt/runs/2026-10-22T18-11-2)
1// initial value
2let result = [];
3(() => 42 // comment after arrow)
4 .forEach(v => result.push(v));
5console.log(result);
r2-p002 · Early Return in Multi-Statement Block
1let log = '';
2const fn = () => {
3 log += 'first';
4 log += 'second';
5};
6fn();
7console.log(log);
firstsecond
r2-p003 · Throw in Expression Context
1try {
2 const x = () => { throw new Error('test'); };
3 x();
4} catch (e) {
5 console.log(e.message);
6}
test
r2-p004 · Sparse Arrays and Holes
1const arr = Array(3);
2arr[0] = 1;
3arr[2] = 3;
4console.log(arr.length, arr[1]);
3 undefined
r2-p005 · Comma Precedence in Expression Body (generated program does not parse: /home/sun/dev/diaghunt/runs/2026-10-22T18-11-2)
1let a = 1, b = 2;
2const getVals = () => a++, b++;
3const res = getVals();
4console.log(a, b, res);
r2-p006 · Name Collision After Scope Move
1let x = 1;
2(() => {
3 let x = 2;
4 return () => x;
5})()();
6console.log(x);
1
r2-p007 · Null/Undefined Distinction with Optional Chaining
1const obj = { a: null };
2console.log(obj.a ?? 'default', obj.a || 'fallback');
default fallback
r2-p008 · Order of Evaluation Side Effects
1let counter = 0;
2const inc = () => counter++;
3const val = (inc(), inc());
4console.log(counter, val);
2 1