MCPcopy Index your code
hub / github.com/perkeep/perkeep / hookGofmt

Method hookGofmt

dev/devcam/hook.go:150–167  ·  view source on GitHub ↗

hookGofmt runs a gofmt check on the local files matching the files in the git staging area. An error is returned if something went wrong or if some of the files need gofmting. In the latter case, the instruction is printed.

()

Source from the content-addressed store, hash-verified

148// An error is returned if something went wrong or if some of the files need
149// gofmting. In the latter case, the instruction is printed.
150func (c *hookCmd) hookGofmt() error {
151 if os.Getenv("GIT_GOFMT_HOOK") == "off" {
152 printf("gofmt disabled by $GIT_GOFMT_HOOK=off\n")
153 return nil
154 }
155
156 files, err := c.runGofmt()
157 if err != nil {
158 printf("gofmt hook reported errors:\n\t%v\n", strings.Replace(strings.TrimSpace(err.Error()), "\n", "\n\t", -1))
159 return errors.New("gofmt errors")
160 }
161 if len(files) == 0 {
162 return nil
163 }
164 printf("You need to format with gofmt:\n\tgofmt -w %s\n",
165 strings.Join(files, " "))
166 return errors.New("gofmt required")
167}
168
169func (c *hookCmd) hookTrailingSpace() error {
170 // see 'pathspec' for the ':!' syntax to ignore a directory.

Callers 1

hookPreCommitMethod · 0.95

Calls 3

runGofmtMethod · 0.95
printfFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected