Skip to content

Commit

Permalink
Fix newlines in JSON output
Browse files Browse the repository at this point in the history
This changes the JSON output to be more consistent about where newlines are included. Previously it only included them between lines in a multiline diff. That meant single line changes were treated a bit weirdly. This changes it to append a newline to every line.

When feeding the results into `arc lint` this behaves correctly. I have only done limited testing though, in particular there's a possibility it might not work with files with `\r\n` endings (though that would have been the case before too).

Fixes #4259
  • Loading branch information
Tim Hutt committed Jun 19, 2020
1 parent cf1f0cf commit 89f7e9b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/emitter/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,22 @@ impl JsonEmitter {
let mut expected_end_line = expected_begin_line;
let mut original_line_counter = 0;
let mut expected_line_counter = 0;
let mut original_lines = vec![];
let mut expected_lines = vec![];
let mut original = String::new();
let mut expected = String::new();

for line in mismatch.lines {
match line {
DiffLine::Expected(msg) => {
expected_end_line = expected_begin_line + expected_line_counter;
expected_line_counter += 1;
expected_lines.push(msg)
expected.push_str(&msg);
expected.push('\n');
}
DiffLine::Resulting(msg) => {
original_end_line = original_begin_line + original_line_counter;
original_line_counter += 1;
original_lines.push(msg)
original.push_str(&msg);
original.push('\n');
}
DiffLine::Context(_) => continue,
}
Expand All @@ -91,8 +93,8 @@ impl JsonEmitter {
original_end_line,
expected_begin_line,
expected_end_line,
original: original_lines.join("\n"),
expected: expected_lines.join("\n"),
original,
expected,
});
}
self.mismatched_files.push(MismatchedFile {
Expand Down

0 comments on commit 89f7e9b

Please sign in to comment.