Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

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

Open
#67 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

  • #68 by @gchappel — closed without merging

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
git, go, shell
Domain
tooling

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

bug

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.

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from gruntwork-io/pre-commit

All issues in gruntwork-io/pre-commit

Similar issues

More Shell/Bash issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.