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

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

Open
2 tasks
gchappel opened this issue Jan 20, 2022 · 0 comments · May be fixed by #68
Open
2 tasks

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

gchappel opened this issue Jan 20, 2022 · 0 comments · May be fixed by #68
Labels
bug Something isn't working

Comments

@gchappel
Copy link

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

  • Create an empty directory
  • git init .
  • Configure .pre-commit-config.yaml with the Gruntwork pre-commit repo and enable the gofmt hook
  • Create a subdirectory
  • In this subdirectory run go mod init test
  • In the subdirectory write a deliberately-malformed Go file, for example using spaces instead of tabs:
package main

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.

@gchappel gchappel added the bug Something isn't working label Jan 20, 2022
@gchappel gchappel linked a pull request Jan 20, 2022 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant