sindresorhus/eslint-plugin-unicorn

Rule proposal: `no-this-outside-of-class`

Fechada

#2.450 aberto em 16 de set. de 2024

 (13 comentários) (6 reações) (0 responsável)JavaScript (468 forks)user submission
help wantednew rule

Métricas do repositório

Stars
 (5.022 estrelas)
Métricas de merge de PR
 (Mesclagem média 4h 30m) (26 fundiu PRs em 30d)

Description

Description

In modern JavaScript, this should not appear outside of an class.

Fail

function foo () {
  this.bar;
}
function Foo(name) {
  this.name = name;
}
class Foo {
  foo() {
    function bar() {
      this.baz;
    }
  }
}

Pass

class Foo {
  foo() {
    this.name;
  }
}

class Foo {
  foo() {
    const bar = () => {
      this.name;
    }
  }
}

Proposed rule name

no-this-outside-of-class

Additional Info

No response

Guia do colaborador