---
# System prepended metadata

title: Coding Styles

---

# Coding Styles

## Dot Alignment

First variable in the chain is coupled with first function. All other functions must align with the first `.`.

```swift
this.map { ... }
    .filter { ... }
```

## Argument Alignment
Up to 3 arguments allowed on a single line, more than 3 it should be multi-line.
```swift
init(
  this: ...
  that: ...
  those: ...
  thems: ...
)
```

## File Structure
- Code files should be grouped by functionality not access level
- Marks should have a hyphen to separate groupings
- Functionality groupings should have a corresponding mark
- Files greater than 100 lines of code should be marked

## Fixme & Todo
- Fixmes should be used for deferred work that must be fixed before a release
- Todos are deferred work that does not need to be fixed before a release
- Fixmes and TODOs should have an accompanying ticket number for when it should be removed

## Documentation Styling
- No new line is necessary between description and parameters
- Extra callouts should have an empty line between them
- Any example could should have a `### Example` header with a 3 back-tick code block
- Callout Usage
    - Warning signals that something may break if not used according to the documentation
    - Note signals extra information that could help in the usage of an API
    - See Also signals extra documentation that may be necessary to understand an API
- https://developer.apple.com/library/archive/documentation/Xcode/Reference/xcode_markup_formatting_ref/

## Enum Cases
Enum cases should be on their own line and prefixed with `case` for jazzy to properly generate documentation

```swift
enum This { 
  case that
  case those
  case them
}
```

## Test Naming
- Test names should include the unit being tested, under the conditions being tested and the expected outcome
- https://qualitycoding.org/unit-test-naming/

## Optional Pipelines
When unwrapping optionals in guard statements it is preferred to use chained flatmaps instead of creating intermediate variables.

```
// No
guard let value = failingFunction(val),
      let value2 = failingFunction2(value),
      let value3 = failingFunction3(value2) else { return }

// Yes
guard let value = val.flatMap(failingFunction)
                     .flatMap(failingFunction2)
                     .flatMap(failingFunction3) else  { return }

```