fixhunt

biome complexity/noUselessThisAlias: fix changes program behavior

fix-changes-behaviorlabelled safereal · highrelated
Findings / 2026-10-17T20-08-24-819Z-hi5g-biome-complexity_noUselessThisAlias / r1-p007biome 2.5.1510 → 8 lines2026-10-17 20:08 UTC

Hypothesis Nemotron 3 Super predicted to fire fired 1×

If the alias variable is declared with 'var' and hoisted, removing it may affect the temporal dead zone or hoisting behavior in ways that change execution if referenced before declaration.

Program

before
1function test() {
2 console.log(typeof _this);
3 var _this = this;
4}
5try {
6 console.log(test.call({value: 'ok'}));
7} catch (e) {
8}
after
1function test() {
2 console.log(typeof this);
3}
4try {
5 console.log(test.call({value: 'ok'}));
6} catch (e) {
7}

Output

stdout beforeexit 0
undefined
undefined
stdout afterexit 0
object
undefined
fired
1 before · 0 after
runs
each version twice, same file name, no network

Judge Nemotron 3 Ultra advisory real · high

The rule removed the variable declaration `var _this = this` and replaced the read of `_this` with `this`, but the read occurs before the declaration in the original code. In the original, `typeof _this` evaluates to 'undefined' due to hoisting; after the fix, `typeof this` evaluates to the bound `this` value ('object'), changing the program's output. The documentation only mentions arrow functions, yet the fix was applied to a regular function where `this` is not lexically inherited, making the rewrite unsound for this construct.

Explanation Nemotron 3 Super unverified

The original code logs typeof _this before declaring var _this; due to hoisting, _this exists but is uninitialized (undefined), so typeof yields "undefined". After fixing, typeof this refers to the function’s this value directly. When called via .call({value:'ok'}), this becomes the passed object, so typeof returns "object". The second log remains undefined because test returns nothing. Thus the change alters behavior by moving the reference before the declaration, changing what _this denotes.

Reproduce

file
prog.js (the before program)
minimized program
r1-p007.js
evidence sheet
r1-p007.md
regression fixture
r1-p007.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/noUselessThisAlias --write prog.js
node prog.js

Upstream search GitHub issues Tavily Nemotron 3 Super + Ultra

noUselessThisAlias fix · complexity noUselessThisAlias alias usage · typeof undefined variable reference · test call context binding

  • related biomejs/biome/issues/1633 same rule (noUselessThisAlias) but different defect (extra semicolon vs behavior change from hoisting)

Details

program
Var hoisting and TDZ interaction
hazard
If the alias variable is declared with 'var' and hoisted, removing it may affect the temporal dead zone or hoisting behavior in ways that change execution if referenced before declaration.
oracle
stdout before: undefined undefined stdout after: object undefined
run
2026-10-17T20-08-24-819Z-hi5g-biome-complexity_noUselessThisAlias
generated program (10 lines) and the fix's diff
1function test() {
2 console.log(typeof _this);
3 var _this = this;
4 return _this.value;
5}
6try {
7 console.log(test.call({value: 'ok'}));
8} catch (e) {
9 console.log(e.name + ': ' + e.message);
10}
--- orig.js	2026-10-17 16:08:35.139172094 -0400
+++ fixed.js	2026-10-17 16:08:35.417161650 -0400
@@ -1,7 +1,6 @@
 function test() {
-  console.log(typeof _this);
-  var _this = this;
-  return _this.value;
+  console.log(typeof this);
+  return this.value;
 }
 try {
   console.log(test.call({value: 'ok'}));
rule documentation given to the models
Summary

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

Description

 Disallow useless `this` aliasing.

 Arrow functions inherits `this` from their enclosing scope;
 this makes `this` aliasing useless in this situation.

Examples

Invalid

 ```js,expect_diagnostic
 class A {
     method() {
         const self = this;
         return () => {
             return self;
         }
     }
 }
 ```

Valid

 ```js
 class A {
     method() {
         const self = this;
         return function() {
             this.g();
             return self;
         }
     }
 }
 ```