Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#67 0 commenti 3 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

  • #68 di @gchappel — chiusa senza merge

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
git, go, shell
Ambito
tooling

Direzione di ricerca

Inizia con l’hook gofmt configurato tramite .pre-commit-config.yaml e riproduci il problema usando un modulo Go in una sottodirectory. Traccia il modo in cui l’hook individua i file Go e la radice del modulo, quindi verifica che il codice Go malformato nel modulo annidato venga formattato correttamente senza richiedere go.mod o go.sum nella radice del repository.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Shell
Stelle
546
Fork
167
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di gruntwork-io/pre-commit

Tutte le issue di gruntwork-io/pre-commit

Issue simili

Altre issue su Shell/Bash

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.