sindresorhus/eslint-plugin-unicorn
Rule proposal: `no-this-outside-of-class`
Closed
#2,450 opened on Sep 16, 2024
help wantednew rule
Repository metrics
- Stars
- (5,022 stars)
- PR merge metrics
- (Avg merge 1d 16h) (399 merged PRs in 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