Linter · Rules
grouped-accessor-pairs
Require the getter and setter of a property to be next to each other
When other members sit between a property's getter and setter, someone who finds the getter can miss that there's a setter further down.
The rule checks object literals and classes. In a class, a static pair and an instance pair with the same name are separate.
Configure
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"grouped-accessor-pairs" = "error" # or "warn"
Every option, set to its default:
bunfig.toml
[lint.rules]
"grouped-accessor-pairs" = [
"error",
"anyOrder", # "anyOrder", "getBeforeSet" or "setBeforeGet"
{
enforceForTSTypes = false,
},
]
Examples
Reported:
class User {
get name() {
return this.first;
}
save() {}
set name(value) {
this.first = value;
}
}
Not reported:
class User {
get name() {
return this.first;
}
set name(value) {
this.first = value;
}
save() {}
}
Options
bunfig.toml
[lint.rules]
grouped-accessor-pairs = ["error", "getBeforeSet"]
| Option | What it does |
|---|---|
"anyOrder" (default) | The pair must be adjacent, in either order. |
"getBeforeSet" | The getter must also come first. |
"setBeforeGet" | The setter must also come first. |
| Option | Default | What it does |
|---|---|---|
enforceForTSTypes | false | Also check get and set signatures in interfaces and type literals. |
const volume = {
set level(value) {
this.raw = value;
},
get level() {
return this.raw;
},
};
const volume = {
get level() {
return this.raw;
},
set level(value) {
this.raw = value;
},
};
enforceForTSTypes
interface Volume {
get level(): number;
mute(): void;
set level(value: number);
}
interface Volume {
get level(): number;
mute(): void;
set level(value: number);
}