diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0e2b2fa..14338d7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,11 +18,18 @@ jobs: runs-on: ubuntu-latest steps: - uses: golang/govulncheck-action@v1 - gocritic: + gocritic_lint_ineffassign_checks: runs-on: ubuntu-latest steps: - uses: actions/setup-go@v4 - uses: actions/checkout@v3 - run: | + set -e + sudo apt-get -qq update && sudo apt-get install -y shellcheck go install github.com/go-critic/go-critic/cmd/gocritic@latest - gocritic check . + go install golang.org/x/tools/cmd/goimports@latest + go install golang.org/x/lint/golint@latest + go install github.com/gordonklaus/ineffassign@latest + pip install pre-commit + pre-commit install + pre-commit run --all-files diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..1810495 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,11 @@ +repos: + - repo: https://github.com/jessp01/pre-commit-golang.git + rev: v0.5.7 + hooks: + - id: go-fmt + - id: go-imports + - id: go-vet + - id: go-lint + - id: go-critic + - id: go-ineffassign + - id: shellcheck diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 930a603..96a5cc9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -95,6 +95,42 @@ This is easy in Go. Just use `gofmt`. End of. Your code should also pass `golint` and `go vet` without errors (and if you want to run other linters too, that would be excellent). Very, very occasionally there are situations where `golint` incorrectly detects a problem, and the workaround is awkward or annoying. In that situation, comment on the PR and we'll work out how best to handle it. +### pre-commit hooks + +Install the needed GO packages: +```sh +go install github.com/go-critic/go-critic/cmd/gocritic@latest +go install golang.org/x/tools/cmd/goimports@latest +go install golang.org/x/lint/golint@latest +go install github.com/gordonklaus/ineffassign@latest +``` + +Install the `pre-commit` util: +```sh +pip install pre-commit +``` + +Generate `.git/hooks/pre-commit`: +```sh +pre-commit install +``` + +Following that, these tests will run every time you invoke `git commit`: +```sh +go fmt...................................................................Passed +go imports...............................................................Passed +go vet...................................................................Passed +go lint..................................................................Passed +go-critic................................................................Passed +shellcheck...............................................................Passed +``` + +To manually run all tests on all repo files, invoke: + +```sh +pre-commit run --all-files +``` + # Documentation It doesn't matter if you write the greatest piece of code in the history of the world, if no one knows it exists, or how to use it.