diff --git a/extract-errors.pl b/extract-errors.pl new file mode 100755 index 0000000..824ee8f --- /dev/null +++ b/extract-errors.pl @@ -0,0 +1,20 @@ +#!/usr/bin/env perl +my $new_source = "$ENV{source}.new"; +open my $source_in, "<", $ENV{source}; +open my $source_out, ">", $new_source; +open my $errors, ">>", $ENV{errors}; +my $found_error=0; +while (<$source_in>) { + if ($found_error) { + print $errors $_; + } elsif (/^error:/) { + $found_error=1; + print $errors $_; + } else { + print $source_out $_; + } +} +close $source_in; +close $source_out; +close $errors; +rename $new_source, $ENV{source}; diff --git a/run-scalafmt.sh b/run-scalafmt.sh index 03f7157..0034dd0 100755 --- a/run-scalafmt.sh +++ b/run-scalafmt.sh @@ -31,29 +31,8 @@ report() { errors=$(mktemp) -if grep -q '^error:' "$output"; then - output="$output" errors="$errors" perl -e ' - my $new_output = "$ENV{output}.new"; - open my $output_in, "<", $ENV{output}; - open my $output_out, ">", $new_output; - open my $errors, ">", $ENV{errors}; - my $found_error=0; - while (<$output_in>) { - if ($found_error) { - print $errors $_; - } elsif (/^error:/) { - $found_error=1; - print $errors $_; - } else { - print $output_out $_; - } - } - close $output_in; - close $output_out; - close $errors; - rename $new_output, $ENV{output}; - ' -fi +source="$output" errors="$errors" extract-errors.pl +source="$warnings" errors="$errors" extract-errors.pl ( echo "# scalafmt failed ($result)"