Skip to content

Commit 70aa3c2

Browse files
authored
chore: add guidance on getters/setters to coding standards (#7977)
1 parent 179445c commit 70aa3c2

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

CODING_STANDARDS.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,24 @@ be part of the user-facing API. This typically applies to symbols used in templa
154154
Additionally, the `@docs-private` JsDoc annotation can be used to hide any symbol from the public
155155
API docs.
156156

157+
158+
#### Getters and Setters
159+
* Avoid long or complex getters and setters. If the logic of an accessor would take more than
160+
three lines, introduce a new method to contain the logic.
161+
* A getter should immediately precede its corresponding setter.
162+
* Decorators such as `@Input` should be applied to the getter and not the setter.
163+
* Always use a `readonly` property instead of a getter (with no setter) when possible.
164+
```ts
165+
/** YES */
166+
readonly active: boolean;
167+
168+
/** NO */
169+
get active(): boolean {
170+
// Using a getter solely to make the property read-only.
171+
return this._active;
172+
}
173+
```
174+
157175
#### JsDoc comments
158176

159177
All public APIs must have user-facing comments. These are extracted and shown in the documentation

0 commit comments

Comments
 (0)