| Mateusz Zalega | 2904364 | 2021-12-02 15:04:14 +0100 | [diff] [blame] | 1 | # Monogon coding standards |
| Serge Bazanski | b309e3f | 2021-12-17 17:31:21 +0100 | [diff] [blame^] | 2 | |
| Mateusz Zalega | 2904364 | 2021-12-02 15:04:14 +0100 | [diff] [blame] | 3 | ## Programming languages |
| Serge Bazanski | b309e3f | 2021-12-17 17:31:21 +0100 | [diff] [blame^] | 4 | |
| Mateusz Zalega | 2904364 | 2021-12-02 15:04:14 +0100 | [diff] [blame] | 5 | ### Go |
| Serge Bazanski | b309e3f | 2021-12-17 17:31:21 +0100 | [diff] [blame^] | 6 | While working on a change, please adhere to practices documented in the chapter about [frequently occurring code review comments](https://github.com/golang/go/wiki/CodeReviewComments) of [the Go wiki](https://github.com/golang/go/wiki/). In addition, some Monogon-specific style is enforced at build time as follows: |
| 7 | |
| 8 | #### Line Length |
| 9 | |
| 10 | Comment lines must not be longer than 80 characters. Non-comment lines may be any (reasonable) length. |
| 11 | |
| 12 | #### Imports |
| 13 | |
| 14 | Imports must be grouped and sorted in the following way: |
| 15 | |
| 16 | ```go |
| 17 | import ( |
| 18 | "errors" |
| 19 | "net/http" |
| 20 | |
| 21 | "example.com/some/external/thing" |
| 22 | "golang.org/x/crypto" |
| 23 | |
| 24 | "dev.source.monogon/some/internal/library" |
| 25 | apkg "dev.source.monogon/some/other/pkg" |
| 26 | ) |
| 27 | ``` |
| 28 | |
| 29 | Ie., all stdlib imports must come before all non-Monogon ('global') imports, which must come before all Monogon ('local') imports. Within each group, imports must be sorted. |
| 30 | |
| 31 | There can be multiple groups of a given class, but they must be in the right order: |
| 32 | |
| 33 | ```go |
| 34 | import ( |
| 35 | "errors" |
| 36 | "net/http" |
| 37 | |
| 38 | "dev.source.monogon/some/internal/library" |
| 39 | "dev.source.monogon/some/internal/pkg" |
| 40 | |
| 41 | "dev.source.monogon/other/subtree/a" |
| 42 | "dev.source.monogon/other/subtree/b" |
| 43 | foo "dev.source.monogon/other/subtree/c" |
| 44 | ) |
| 45 | ``` |