Skip to content

Commit 6ef6522

Browse files
dottedmagmisha-drozd
authored andcommitted
goimports: Add an option to report non-clean files
1 parent bdaed05 commit 6ef6522

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

cmd/goimports/goimports.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ import (
2626

2727
var (
2828
// main operation modes
29-
list = flag.Bool("l", false, "list files whose formatting differs from goimport's")
30-
write = flag.Bool("w", false, "write result to (source) file instead of stdout")
31-
doDiff = flag.Bool("d", false, "display diffs instead of rewriting files")
32-
srcdir = flag.String("srcdir", "", "choose imports as if source code is from `dir`. When operating on a single file, dir may instead be the complete file name.")
29+
list = flag.Bool("l", false, "list files whose formatting differs from goimport's")
30+
write = flag.Bool("w", false, "write result to (source) file instead of stdout")
31+
doDiff = flag.Bool("d", false, "display diffs instead of rewriting files")
32+
srcdir = flag.String("srcdir", "", "choose imports as if source code is from `dir`. When operating on a single file, dir may instead be the complete file name.")
33+
failUnclean = flag.Bool("f", false, "exit with non-zero code if any of the files needed changes")
3334

3435
verbose bool // verbose logging
3536

@@ -176,6 +177,9 @@ func processFile(filename string, in io.Reader, out io.Writer, argType argumentT
176177
fmt.Printf("diff -u %s %s\n", filepath.ToSlash(filename+".orig"), filepath.ToSlash(filename))
177178
out.Write(data)
178179
}
180+
if *failUnclean {
181+
err = fmt.Errorf("%s needed reformatting", filename)
182+
}
179183
}
180184

181185
if !*list && !*write && !*doDiff {

0 commit comments

Comments
 (0)