From 5501fa5220f7721cd3d5152ee225b30cfb4ea591 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Fri, 10 Mar 2017 11:15:14 +0100 Subject: Add style guide --- STYLE.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 STYLE.md (limited to 'STYLE.md') 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 -- cgit v1.2.3