Skip to content

Commit 3e8fbee

Browse files
authored
feat(lint): implement useAdjacentGetterSetter rule (#5964)
1 parent 014ee7d commit 3e8fbee

File tree

13 files changed

+1098
-32
lines changed

13 files changed

+1098
-32
lines changed

.changeset/chatty-schools-win.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
"@biomejs/biome": minor
3+
---
4+
5+
Added the new rule [`useAdjacentGetterSetter`](https://biomejs.dev/linter/rules/use-adjacent-getter-setter), which enforces getters and setters for the same property
6+
to be adjacent in class and object definitions.
7+
8+
**Example (Invalid): Name getter and setter are not adjacent:**
9+
10+
```js
11+
class User {
12+
get name() { return this._name; }
13+
constructor() {}
14+
set name(value) { this._name = value; }
15+
}
16+
```
17+
18+
**Example (Invalid): Getter should go before the setter.
19+
20+
```js
21+
const user = {
22+
set name(value) { this._name = value; },
23+
get name() { return this._name; }
24+
};
25+
```
26+
27+
**Example (Valid): Name getter and setter are adjacent:**
28+
29+
```js
30+
class User {
31+
get name() { return this._name; }
32+
set name(value) { this._name = value; }
33+
get age() { return this._age; }
34+
set age(age) { this._age = age; }
35+
}
36+
```

crates/biome_cli/src/execute/migrate/eslint_any_rule_to_biome.rs

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/biome_configuration/src/analyzer/linter/rules.rs

Lines changed: 56 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/biome_diagnostics_categories/src/categories.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ define_categories! {
183183
"lint/nursery/noUselessBackrefInRegex": "https://biomejs.dev/linter/rules/no-useless-backref-in-regex",
184184
"lint/nursery/noUselessEscapeInString": "https://biomejs.dev/linter/rules/no-useless-escape-in-string",
185185
"lint/nursery/noUselessUndefined": "https://biomejs.dev/linter/rules/no-useless-undefined",
186+
"lint/nursery/useAdjacentGetterSetter": "https://biomejs.dev/linter/rules/use-adjacent-getter-setter",
186187
"lint/nursery/useBiomeSuppressionComment": "https://biomejs.dev/linter/rules/use-biome-suppression-comment",
187188
"lint/nursery/useConsistentObjectDefinition": "https://biomejs.dev/linter/rules/use-consistent-object-definition",
188189
"lint/nursery/useExhaustiveSwitchCases": "https://biomejs.dev/linter/rules/use-exhaustive-switch-cases",

0 commit comments

Comments
 (0)