`gofmt` check fails if `go.mod` and `go.sum` are not in the root directory
Nobody has claimed this yet.
- #68 by @gchappel — closed without merging
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
Research direction
Start with the gofmt hook configured through .pre-commit-config.yaml and reproduce the failure using a Go module in a subdirectory. Trace how the hook locates Go files and the module root, then verify that malformed Go code in the nested module is formatted successfully without requiring go.mod or go.sum at the repository root.
Written by the indexing model from the issue text.
Description
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.yamlwith the Gruntwork pre-commit repo and enable thegofmthook - 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.yamlto 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.
- Dominant language
- Shell
- Stars
- 546
- Forks
- 167
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from gruntwork-io/pre-commit
-
Documentation for shellcheck should include that it is configurable with a .shellcheckrcMay be free again A pull request for this issue was closed without being merged. Openenhancement
Difficulty 1/5 Under an hour Newbie friendliness 68/100
gruntwork-io/pre-commit#79 ·
-
Support args for terraform-fmt, remove hardcoded args.May be free again @ZachGoldberg claimed this 384 days ago, and no pull request is open. Openenhancement
gruntwork-io/pre-commit#138 · 3 reactions · 1 assignee ·
-
Sentinel Fmt Hook Does Not WorkMay be free again A pull request for this issue was closed without being merged. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 38/100
gruntwork-io/pre-commit#121 ·
-
enhancement
Difficulty 3/5 1-2 days Newbie friendliness 35/100
gruntwork-io/pre-commit#111 · 1 reaction ·
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 45/100
gruntwork-io/pre-commit#110 ·
All issues in gruntwork-io/pre-commit
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
omarchy-menu-keybindings lua bind scan spins at 100% CPU when user config iterates a mocked hl APIOpen
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
omacom/omarchy#14302 · 1 comment ·
Maintainers usually reply within 1 day
-
Link Checker ReportPossibly taken @keraron claimed this today. Openautomated issue report
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
a2aproject/A2A#2297 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
mattpocock/skills#1165 ·
-
agent-research-finding agent-research-recommend chore ready-for-agent
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
jordansmall/spindrift#4487 · 1 comment ·
Maintainers usually reply within 1 day