Improve focus of multi-line string diffs when there are loads of lines #68
Open
Description
See discussion: avajs/ava#2665
When comparing two strings that are many lines long, the diff output should focus on the lines that are actually different, not the potentially dozens or hundreds of lines that are the same.
- If the diff is longer than, say, 30 lines, divide it into sections of changes and non-changes.
- If the non-change sections are 5 lines or less, merge the surrounding change sections into one larger change section.
- For the sections with changes, provide 5 lines of context before and after the actual change. Take 5 lines from the preceding and succeeding non-change sections, if any. Due to step 2, these sections must be larger than 5 lines.
- Prefix the change sections with a hunk heading
@@ -l, +l @@
, where the line numbersl
correspond to the-
and+
sides of the diff. - Print the change sections, prefixed with their heading, and separated with an empty line between them.