gruntwork-io / pre-commit

A collection of pre-commit hooks used by Gruntwork tools
https://gruntwork.io/
Apache License 2.0
484 stars 155 forks source link

`gofmt` check fails if `go.mod` and `go.sum` are not in the root directory #67

Open gchappel opened 2 years ago

gchappel commented 2 years ago

Describe the bug The gofmt check fails if Go code is stored in a subdirectory of the repository:

gofmt....................................................................Failed
- hook id: gofmt
- exit code: 1

go: cannot find main module, but found .git/config in /Users/gchappel/code/sample-directory
    to create a module there, run:
    go mod init

To Reproduce

import ( "fmt" // this line starts with two spaces )

func main() { fmt.Println("test") // this line starts with two spaces }


* `git add .` to add the Go code and the `.pre-commit-config.yaml` to the staging area
* run `pre-commit run gofmt`
* see error

**Expected behavior**
The malformed Go file has its spaces replaced with tabs

**Nice to have**
- [ ] Terminal output
- [ ] Screenshots

**Additional context**
Add any other context about the problem here.