Skip to content

Commit

Permalink
Only print lint fixes with verbose mode (#444)
Browse files Browse the repository at this point in the history
  • Loading branch information
keith authored and vladmos committed Nov 26, 2018
1 parent 4a45da7 commit 59972e3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion buildifier/buildifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func processFile(filename string, data []byte, inputType, lint string, warningsL
case "warn":
warn.PrintWarnings(f, pkg, warningsList, false)
case "fix":
warn.FixWarnings(f, pkg, warningsList)
warn.FixWarnings(f, pkg, warningsList, *vflag)
}

if *filePath != "" {
Expand Down
3 changes: 2 additions & 1 deletion buildifier/integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ EOF

cat > test/fix_report_golden <<EOF
test/to_fix.bzl: applied fixes, 0 warnings left
fixed test/to_fix.bzl
EOF

$1 --lint=warn test/to_fix.bzl 2> test/error
diff test/error test/error_golden

$1 --lint=fix test/to_fix.bzl 2> test/fix_report
$1 --lint=fix -v test/to_fix.bzl 2> test/fix_report
diff test/to_fix.bzl test/fixed_golden.bzl
diff test/fix_report test/fix_report_golden
10 changes: 6 additions & 4 deletions warn/warn.go
Original file line number Diff line number Diff line change
Expand Up @@ -992,11 +992,13 @@ func PrintWarnings(f *build.File, pkg string, enabledWarnings []string, showRepl
}

// FixWarnings fixes all warnings that can be fixed automatically.
func FixWarnings(f *build.File, pkg string, enabledWarnings []string) {
func FixWarnings(f *build.File, pkg string, enabledWarnings []string, verbose bool) {
warnings := FileWarnings(f, pkg, enabledWarnings, true)
fmt.Fprintf(os.Stderr, "%s: applied fixes, %d warnings left\n",
f.Path,
len(warnings))
if verbose {
fmt.Fprintf(os.Stderr, "%s: applied fixes, %d warnings left\n",
f.Path,
len(warnings))
}
}

func collectAllWarnings() []string {
Expand Down
2 changes: 1 addition & 1 deletion warn/warn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func checkFix(t *testing.T, category, input, expected string, scope, fileType bu
panic(fmt.Sprintf("%v", err))
}

FixWarnings(buildFile, "the_package", []string{category})
FixWarnings(buildFile, "the_package", []string{category}, false)
have := build.Format(buildFile)
want := build.Format(goldenFile)
if !bytes.Equal(have, want) {
Expand Down

0 comments on commit 59972e3

Please sign in to comment.