blob: fce6edd102002f129313ba2a53577508f751f18b [file] [log] [blame] [view]
Mateusz Zalega29043642021-12-02 15:04:14 +01001# Monogon coding standards
Serge Bazanskib309e3f2021-12-17 17:31:21 +01002
Mateusz Zalega29043642021-12-02 15:04:14 +01003## Programming languages
Serge Bazanskib309e3f2021-12-17 17:31:21 +01004
Mateusz Zalega29043642021-12-02 15:04:14 +01005### Go
Serge Bazanskib309e3f2021-12-17 17:31:21 +01006While 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
10Comment lines must not be longer than 80 characters. Non-comment lines may be any (reasonable) length.
11
12#### Imports
13
14Imports must be grouped and sorted in the following way:
15
16```go
17import (
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
29Ie., 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
31There can be multiple groups of a given class, but they must be in the right order:
32
33```go
34import (
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```
Serge Bazanski144b7862021-12-17 17:30:14 +010046
47A styleguide compliant fork of `goimports` (itself a superset of `gofmt`) can be built by running:
48
49 $ bazel build //:goimports
50
51The resulting binary can then be copied to anywhere in the filesystem (eg. $HOME/bin/goimports-monogon) and any editor which supports gofmt/goimports integration can be pointed at this tool to automatically reformat files to the required format.