Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pre-commit hook config #188

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading