diff --git a/CODING_STANDARDS.md b/CODING_STANDARDS.md index 46a16b6b31c7..e0b9da487df4 100644 --- a/CODING_STANDARDS.md +++ b/CODING_STANDARDS.md @@ -154,6 +154,24 @@ be part of the user-facing API. This typically applies to symbols used in templa Additionally, the `@docs-private` JsDoc annotation can be used to hide any symbol from the public API docs. + +#### Getters and Setters +* Avoid long or complex getters and setters. If the logic of an accessor would take more than +three lines, introduce a new method to contain the logic. +* A getter should immediately precede its corresponding setter. +* Decorators such as `@Input` should be applied to the getter and not the setter. +* Always use a `readonly` property instead of a getter (with no setter) when possible. + ```ts + /** YES */ + readonly active: boolean; + + /** NO */ + get active(): boolean { + // Using a getter solely to make the property read-only. + return this._active; + } + ``` + #### JsDoc comments All public APIs must have user-facing comments. These are extracted and shown in the documentation