chore: reformat go, add commitizen for commit message
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 11e24bd..7660034 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml
@@ -1,15 +1,33 @@ +# See instructions in CONTRIBUTING.md +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks repos: - - repo: https://github.com/syntaqx/git-hooks + # Locally-authored hooks for better hermeticity + - repo: local + hooks: + - id: go-fmt + name: go fmt + description: Runs `go fmt` and asserts no changes are needed. + entry: ./hooks/go-fmt.sh + language: script + files: \.go$ + - repo: https://github.com/syntaqx/git-hooks rev: v0.0.17 hooks: + # Requires that shellcheck is already installed - id: shellcheck - - id: go-fmt + - repo: https://github.com/commitizen-tools/commitizen + rev: v2.18.0 + hooks: + # Requires that commitizen is already installed + - id: commitizen + stages: [commit-msg] - repo: https://github.com/keith/pre-commit-buildifier rev: 4.0.1.1 hooks: + # Requires that buildifier is already installed - id: buildifier args: &args - # Keep this argument in sync with .bazelci/presubmit.yaml - --warnings=all - id: buildifier-lint args: *args \ No newline at end of file
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..597ead9 --- /dev/null +++ b/CONTRIBUTING.md
@@ -0,0 +1,14 @@ +Want to contribute? Great! + +## Formatting/linting + +We suggest using a pre-commit hook to automate this. +First [install pre-commit](https://pre-commit.com/#installation), +then run + +```shell +pre-commit install +pre-commit install --hook-type commit-msg +``` + +Otherwise the CI will yell at you about formatting/linting violations.
diff --git a/cmd/root.go b/cmd/root.go index a8e545d..430dc8a 100644 --- a/cmd/root.go +++ b/cmd/root.go
@@ -10,10 +10,10 @@ "github.com/spf13/cobra" "os" + "github.com/fatih/color" + "github.com/mattn/go-isatty" homedir "github.com/mitchellh/go-homedir" "github.com/spf13/viper" - "github.com/mattn/go-isatty" - "github.com/fatih/color" ) var cfgFile string
diff --git a/hooks/go-fmt.sh b/hooks/go-fmt.sh new file mode 100755 index 0000000..fdc14c7 --- /dev/null +++ b/hooks/go-fmt.sh
@@ -0,0 +1,13 @@ +#!/usr/bin/env bash +set -e + +output="$(bazel 2>/dev/null run -- @go_sdk//:bin/gofmt -l "$@")" + +[[ -z "$output" ]] && exit 0 + +echo >&2 "Go files must be formatted with gofmt. Please run:" +for f in $output; do + echo >&2 " bazel run -- @go_sdk//:bin/gofmt -w $PWD/$f" +done + +exit 1