Skip to content

Commit 89f7e9b

Browse files
author
Tim Hutt
committed
Fix newlines in JSON output
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
1 parent cf1f0cf commit 89f7e9b

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Diff for: src/emitter/json.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,22 @@ impl JsonEmitter {
6767
let mut expected_end_line = expected_begin_line;
6868
let mut original_line_counter = 0;
6969
let mut expected_line_counter = 0;
70-
let mut original_lines = vec![];
71-
let mut expected_lines = vec![];
70+
let mut original = String::new();
71+
let mut expected = String::new();
7272

7373
for line in mismatch.lines {
7474
match line {
7575
DiffLine::Expected(msg) => {
7676
expected_end_line = expected_begin_line + expected_line_counter;
7777
expected_line_counter += 1;
78-
expected_lines.push(msg)
78+
expected.push_str(&msg);
79+
expected.push('\n');
7980
}
8081
DiffLine::Resulting(msg) => {
8182
original_end_line = original_begin_line + original_line_counter;
8283
original_line_counter += 1;
83-
original_lines.push(msg)
84+
original.push_str(&msg);
85+
original.push('\n');
8486
}
8587
DiffLine::Context(_) => continue,
8688
}
@@ -91,8 +93,8 @@ impl JsonEmitter {
9193
original_end_line,
9294
expected_begin_line,
9395
expected_end_line,
94-
original: original_lines.join("\n"),
95-
expected: expected_lines.join("\n"),
96+
original,
97+
expected,
9698
});
9799
}
98100
self.mismatched_files.push(MismatchedFile {

0 commit comments

Comments
 (0)