Skip to content

Commit

Permalink
chore: add api design section to coding standards (#4017)
Browse files Browse the repository at this point in the history
  • Loading branch information
jelbourn authored Apr 10, 2017
1 parent e0124bb commit 3b2f66d
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions CODING_STANDARDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,31 @@ prefer sticking to a _single_ API for accomplishing something.

### 100 column limit
All code and docs in the repo should be 100 columns or fewer. This applies to TypeScript, SCSS,
HTML, bash scripts, and markdown files.
HTML, bash scripts, and markdown files.

### API Design

#### Boolean arguments
Avoid adding boolean arguments to a method in cases where that argument means "do something extra".
In these cases, prefer breaking the behavior up into different functions.

```ts
// AVOID
function getTargetElement(createIfNotFound = false) {
// ...
}
```

```ts
// PREFER
function getExistingTargetElement() {
// ...
}

function createTargetElement() {
// ...
}
```

### TypeScript

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

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

0 comments on commit 3b2f66d

Please sign in to comment.