diff --git a/HACKING.md b/HACKING.md index 101a7757..bde2ab90 100644 --- a/HACKING.md +++ b/HACKING.md @@ -77,7 +77,8 @@ attributes to make it work in Markdown renderers that strip "id". --> * Avoid `init` and use explicit initialization functions instead. - * Avoid `new`, especially with structs. + * Avoid `new`, especially with structs, unless a temporary value is needed, + for example when checking the type of an error using `errors.As`. * Check against empty strings like this: @@ -119,6 +120,15 @@ attributes to make it work in Markdown renderers that strip "id". --> ) ``` + Or, with a struct literal: + + ```go + err := functionWithALongName(arg, structType{ + field1: val1, + field2: val2, + }) + ``` + But **never** this: ```go @@ -132,8 +142,8 @@ attributes to make it work in Markdown renderers that strip "id". --> as well. * Don't use `fmt.Sprintf` where a more structured approach to string - conversion could be used. For example, `net.JoinHostPort` or - `url.(*URL).String`. + conversion could be used. For example, `aghnet.JoinHostPort`, + `net.JoinHostPort` or `url.(*URL).String`. * Don't use naked `return`s. @@ -155,6 +165,9 @@ attributes to make it work in Markdown renderers that strip "id". --> * Prefer constants to variables where possible. Avoid global variables. Use [constant errors] instead of `errors.New`. + * Prefer defining `Foo.String` and `ParseFoo` in terms of `Foo.MarshalText` + and `Foo.UnmarshalText` correspondingly and not the other way around. + * Prefer to use named functions for goroutines. * Program code lines should not be longer than one hundred (**100**) columns. @@ -198,8 +211,8 @@ attributes to make it work in Markdown renderers that strip "id". --> ### Formatting - * Decorate `break`, `continue`, `fallthrough`, `return`, and other terminating - statements with empty lines unless it's the only statement in that block. + * Decorate `break`, `continue`, `return`, and other terminating statements + with empty lines unless it's the only statement in that block. * Don't group type declarations together. Unlike with blocks of `const`s, where a `iota` may be used or where all constants belong to a certain type, diff --git a/scripts/hooks/pre-commit b/scripts/hooks/pre-commit index 41fd72fc..e38e9aa5 100755 --- a/scripts/hooks/pre-commit +++ b/scripts/hooks/pre-commit @@ -2,6 +2,10 @@ set -e -f -u +# Show all temporary todos to the programmer but don't fail the commit +# if there are any, because the commit could be in a temporary branch. +git grep -e 'TODO.*!!' -- ':!HACKING.md' ':!scripts/hooks/pre-commit' | more || : + if [ "$( git diff --cached --name-only -- 'client/*.js' )" ] then make js-lint js-test