sindresorhus/eslint-plugin-unicorn
Disallow `super` and `this` in static methods
Geschlossen
#1.050 geöffnet am 23.01.2021
help wantednew rule
Repository-Metriken
- Stars
- (5.022 Sterne)
- PR-Merge-Metriken
- (Durchschn. Merge 1T 16h) (399 gemergte PRs in 30 T)
Beschreibung
The this keyword on static methods refers the class instance (the constructor). This can be confusing.
Fail
class A {
static foo() {
doSomething()
}
static bar() {
this.foo() //ERROR: Unexpected 'this'.
}
}
class B extends A {
static foo() {
super.foo() //ERROR: Unexpected 'super'.
}
}
Pass
class A {
static foo() {
doSomething()
}
static bar() {
A.foo()
}
}
class B extends A {
static foo() {
A.foo()
}
}