Skip to content

Commit 3b2f66d

Browse files
authored
chore: add api design section to coding standards (#4017)
1 parent e0124bb commit 3b2f66d

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

CODING_STANDARDS.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,31 @@ prefer sticking to a _single_ API for accomplishing something.
7272

7373
### 100 column limit
7474
All code and docs in the repo should be 100 columns or fewer. This applies to TypeScript, SCSS,
75-
HTML, bash scripts, and markdown files.
75+
HTML, bash scripts, and markdown files.
76+
77+
### API Design
78+
79+
#### Boolean arguments
80+
Avoid adding boolean arguments to a method in cases where that argument means "do something extra".
81+
In these cases, prefer breaking the behavior up into different functions.
82+
83+
```ts
84+
// AVOID
85+
function getTargetElement(createIfNotFound = false) {
86+
// ...
87+
}
88+
```
89+
90+
```ts
91+
// PREFER
92+
function getExistingTargetElement() {
93+
// ...
94+
}
95+
96+
function createTargetElement() {
97+
// ...
98+
}
99+
```
76100

77101
### TypeScript
78102

@@ -121,7 +145,7 @@ Properties should have a concise description of what the property means:
121145
```ts
122146
/** The label position relative to the checkbox. Defaults to 'after' */
123147
@Input() labelPosition: 'before' | 'after' = 'after';
124-
```
148+
```
125149

126150
Methods blocks should describe what the function does and provide a description for each parameter
127151
and the return value:

0 commit comments

Comments
 (0)