diff options
author | Jacob Vosmaer <jacob@gitlab.com> | 2017-03-10 13:15:14 +0300 |
---|---|---|
committer | Jacob Vosmaer <jacob@gitlab.com> | 2017-03-10 13:15:14 +0300 |
commit | 5501fa5220f7721cd3d5152ee225b30cfb4ea591 (patch) | |
tree | 0843c724c4f4d01ad1a25f5ddf96e997dc57172e /STYLE.md | |
parent | ecd3580aafc1a05fef13267eddad69e12ff9c56c (diff) |
Add style guide
Diffstat (limited to 'STYLE.md')
-rw-r--r-- | STYLE.md | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/STYLE.md b/STYLE.md new file mode 100644 index 000000000..f2e77c11e --- /dev/null +++ b/STYLE.md @@ -0,0 +1,31 @@ +# Gitaly code style + +## Errors + +### Use %v when wrapping errors + +Use `%v` when wrapping errors with context. + + return fmt.Errorf("foo context: %v", err) + +### Use %q when interpolating strings + +Unless it would lead to incorrect results, always use `%q` when +interpolating strings. The `%q` operator quotes strings and escapes +spaces and non-printable characters. This can save a lot of debugging +time. + +## Tests + +### Table-driven tests + +We like table-driven tests ([Cheney blog post], [Golang wiki]). + +- It should be clear from error messages which test case in the table + is failing. Consider giving test cases a `name` attribute and + including that name in every error message inside the loop. +- Use `t.Errorf` inside a table test loop, not `t.Fatalf`: this + provides more feedback when fixing failing tests. + + [Cheney blog post]: https://dave.cheney.net/2013/06/09/writing-table-driven-tests-in-go + [Golang wiki]: https://github.com/golang/go/wiki/TableDrivenTests |