Skip to content

Latest commit

Β 

History

History
74 lines (53 loc) Β· 1.53 KB

File metadata and controls

74 lines (53 loc) Β· 1.53 KB

class-reference-in-static-methods

πŸ“ Enforce consistent class references in static methods.

πŸ’ΌπŸš« This rule is enabled in the βœ… recommended config. This rule is disabled in the β˜‘οΈ unopinionated config.

πŸ’‘ This rule is manually fixable by editor suggestions.

This rule enforces either dynamic static dispatch with this and super, or direct references with class names.

Choosing one style makes it clear whether a static method is intended to follow subclass dispatch or stay tied to a specific class.

By default, it prefers this and super.

Examples

// ❌
class Foo extends Bar {
	static baz() {
		Foo.qux();
		Bar.qux();
	}
}

// βœ…
class Foo extends Bar {
	static baz() {
		this.qux();
		super.qux();
	}
}

With {preferThis: false, preferSuper: false}:

// ❌
class Foo extends Bar {
	static baz() {
		this.qux();
		super.qux();
	}
}

// βœ…
class Foo extends Bar {
	static baz() {
		Foo.qux();
		Bar.qux();
	}
}

Options

Type: object

preferThis

Type: boolean
Default: true

Prefer this over the current class name in static methods.

preferSuper

Type: boolean
Default: true

Prefer super over the superclass name in static methods.