noUselessThisAlias
Summary
Section titled “Summary”- Rule available since: v1.0.0
- Diagnostic Category: lint/complexity/noUselessThisAlias
- This rule is recommended, which means is enabled by default.
- This rule has a safe fix.
- The default severity of this rule is information.
- Sources:
- Inspired from @typescript-eslint/no-this-alias
 
- Inspired from 
How to configure
Section titled “How to configure”{  "linter": {    "rules": {      "complexity": {        "noUselessThisAlias": "error"      }    }  }}Description
Section titled “Description”Disallow useless this aliasing.
Arrow functions inherits this from their enclosing scope;
this makes this aliasing useless in this situation.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”class A {    method() {        const self = this;        return () => {            return self;        }    }}code-block.js:3:15 lint/complexity/noUselessThisAlias  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ℹ This aliasing of this is unnecessary.
  
    1 │ class A {
    2 │     method() {
  > 3 │         const self = this;
      │               ^^^^^^^^^^^
    4 │         return () => {
    5 │             return self;
  
  ℹ Arrow functions inherits this from their enclosing scope.
  
  ℹ Safe fix: Use this instead of an alias.
  
    1 1 │   class A {
    2 2 │       method() {
    3   │ - ········const·self·=·this;
    4 3 │           return () => {
    5   │ - ············return·self;
      4 │ + ············return·this;
    6 5 │           }
    7 6 │       }
  
class A {    method() {        const self = this;        return function() {            this.g();            return self;        }    }}Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.