Skip to content

Commit

Permalink
Updated to new go install -style + updated tools
Browse files Browse the repository at this point in the history
  • Loading branch information
lietu committed Jun 1, 2022
1 parent 8600d4e commit bedb4e2
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 30 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This should work on Windows, Linux, Mac, and basically anything Golang does (tho

## Using the hooks

You need to first install the binary from here, `go get -u github.com/lietu/go-pre-commit`
You need to first install the binary from here, `go install github.com/lietu/go-pre-commit@latest`

You can add these to your project's `.pre-commit-config.yaml`:

Expand All @@ -22,20 +22,20 @@ You can add these to your project's `.pre-commit-config.yaml`:
- id: go-fmt-goimports
- id: go-test
- id: go-vet
- id: gofumports
- id: gofumpt
- id: golangci-lint
- id: golint
- id: staticcheck
- id: go-mod-tidy
```
If you want to use [golangci-lint](https://github.com/golangci/golangci-lint#install) you should first follow their installation guide. The other tools are automatically `go get`'d if they are not yet installed. If you choose to use `golangci-lint`, you don't need `errcheck`, `go-vet`, and `staticcheck` separately, as they are included by default.
If you want to use [golangci-lint](https://github.com/golangci/golangci-lint#install) you should first follow their installation guide. The other tools are automatically `go install`'d if they are not yet installed. If you choose to use `golangci-lint`, you don't need `errcheck`, `go-vet`, and `staticcheck` separately, as they are included by default.

Also you likely don't want to mix `go-fmt-goimports` with `gofumports` and `gofumpt` as they are just stricter variants of the same tools.
Also you likely don't want to mix `go-fmt-goimports` with `gofumpt` as it is just a stricter variant of the same tools.


## License

[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Flietu%2Fgo-pre-commit.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Flietu%2Fgo-pre-commit?ref=badge_large)


Expand Down
2 changes: 1 addition & 1 deletion commands/go-fmt-goimports.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var goFmtGoimports = &cobra.Command{
Long: ``,
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
ensureInstalled("goimports", "golang.org/x/tools/commands/goimports")
ensureInstalled("goimports", "golang.org/x/tools/cmd/goimports")
runTool("goimports", append([]string{"-l", "-w"}, args...))
},
}
Expand Down
20 changes: 0 additions & 20 deletions commands/gofumports.go

This file was deleted.

2 changes: 1 addition & 1 deletion commands/gofumpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var gofumpt = &cobra.Command{
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
ensureInstalled("gofumpt", "mvdan.cc/gofumpt")
runTool("gofumpt", append([]string{"-s", "-l", "-w"}, args...))
runTool("gofumpt", append([]string{"-l", "-w"}, args...))
},
}

Expand Down
2 changes: 1 addition & 1 deletion commands/staticcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var staticcheck = &cobra.Command{
Long: ``,
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
ensureInstalled("staticcheck", "honnef.co/go/tools/commands/staticcheck")
ensureInstalled("staticcheck", "honnef.co/go/tools/cmd/staticcheck")
runTool("staticcheck", pkgNames(dirNames(args)))
},
}
Expand Down
6 changes: 3 additions & 3 deletions commands/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ func runTool(cmd string, args []string) {
func ensureInstalled(bin string, pkg string) {
_, err := exec.LookPath(bin)
if err != nil {
fmt.Printf("%s not installed, installing from %s\n", bin, pkg)
err = exec.Command("go", "get", pkg).Run()
fmt.Printf("%s not installed, installing from %s@latest\n", bin, pkg)
err = exec.Command("go", "install", fmt.Sprintf("%s@latest", pkg)).Run()
if err != nil {
fmt.Printf("Failed to install %s via go get %s\n", bin, pkg)
fmt.Printf("Failed to install %s via go install %s@latest\n", bin, pkg)
panic(err)
}
}
Expand Down

0 comments on commit bedb4e2

Please sign in to comment.