Skip to content

Commit

Permalink
Add staticcheck to Go pre-commit hooks
Browse files Browse the repository at this point in the history
[The Go's `lint` tool got deprecated](https://github.com/golang/lint) some time
ago. It can be replaced by the `staticcheck` tool, which offers similar
functionalities.
In the `keep-network/keep-core` project we've previously added a GH Action job
that runs the `staticcheck` tool as part of the CI. We want now to also add it
to the Go pre-commit hooks, so that developers could be informed about the
problems in their code before they push it to the remote repository.
In a separate PR we've adding a new custom hook to the
`keep-network/pre-commit-golang` repository. In this PR we're changing the
config to use that new custom hook. We're also removing deprecated `lint` hook
from the config.
Apart from modifyng the `.pre-commit-config.yaml` we're also updating the
`macos-setup.sh` script - so that it would be in line with the modified config.

To adjust the pre-commit hooks on local machine to the new configuration users
should:
1. Install the `staticcheck` tool:
```
go install honnef.co/go/tools/cmd/staticcheck@latest
```
2. Apply the pre-commit hooks config:
```
pre-commit install --install-hooks
```
  • Loading branch information
michalinacienciala committed Nov 2, 2022
1 parent 7ee8811 commit 9dbc71d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
repos:
- repo: https://github.com/keep-network/pre-commit-golang.git
rev: 4cc73f21101f9da1208719b02bbbe0a4c491497e
rev: 979f199 # update after merging https://github.com/keep-network/pre-commit-golang/pull/5
hooks:
- id: go-imports
- id: go-vet
- id: go-fmt
- id: staticcheck
- repo: https://github.com/keep-network/pre-commit-hooks.git
rev: 63e729f
hooks:
Expand Down
2 changes: 1 addition & 1 deletion scripts/macos-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
echo "Installing precommit requirements..."
brew list pre-commit &>/dev/null || brew install pre-commit
go install golang.org/x/tools/cmd/goimports@latest
go install golang.org/x/lint/golint@latest
go install honnef.co/go/tools/cmd/staticcheck@latest

echo "Installing jq..."
brew list jq &>/dev/null || brew install jq
Expand Down

0 comments on commit 9dbc71d

Please sign in to comment.