mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-22 23:02:41 +01:00
Fix some lint rendering issues when lines prior to other identical lines are removed
Summary: See PHI191. This is a rehash of an earlier fix, but we didn't have a test case for this half yet. Test Plan: - Added a failing test, made it pass. - Added a linter like the one in PHI191, ran it, got a valid lint result instead of an exception. Reviewers: amckinley Reviewed By: amckinley Differential Revision: https://secure.phabricator.com/D18759
This commit is contained in:
parent
0989343a4e
commit
9054604214
6 changed files with 62 additions and 21 deletions
|
@ -148,19 +148,17 @@ final class ArcanistConsoleLintRenderer extends ArcanistLintRenderer {
|
||||||
$old_impact--;
|
$old_impact--;
|
||||||
$new_impact--;
|
$new_impact--;
|
||||||
|
|
||||||
if ($old_impact < 0 || $new_impact < 0) {
|
// We can end up here if a patch removes a line which occurs before
|
||||||
throw new Exception(
|
// another identical line.
|
||||||
pht(
|
if ($old_impact <= 0 || $new_impact <= 0) {
|
||||||
'Modified prefix line range has become negative '.
|
break;
|
||||||
'(old = %d, new = %d).',
|
|
||||||
$old_impact,
|
|
||||||
$new_impact));
|
|
||||||
}
|
}
|
||||||
} while (true);
|
} while (true);
|
||||||
|
|
||||||
// If the lines at the end of the changed line range are actually the
|
// If the lines at the end of the changed line range are actually the
|
||||||
// same, shrink the range. This happens when a patch just removes a
|
// same, shrink the range. This happens when a patch just removes a
|
||||||
// line.
|
// line.
|
||||||
|
if ($old_impact > 0 && $new_impact > 0) {
|
||||||
do {
|
do {
|
||||||
$old_suffix = idx($old_lines, $start + $old_impact - 2, null);
|
$old_suffix = idx($old_lines, $start + $old_impact - 2, null);
|
||||||
$new_suffix = idx($new_lines, $start + $new_impact - 2, null);
|
$new_suffix = idx($new_lines, $start + $new_impact - 2, null);
|
||||||
|
@ -178,6 +176,7 @@ final class ArcanistConsoleLintRenderer extends ArcanistLintRenderer {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (true);
|
} while (true);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
|
|
@ -142,6 +142,20 @@ EOTEXT;
|
||||||
'replacement' => "\nX\nY\n",
|
'replacement' => "\nX\nY\n",
|
||||||
),
|
),
|
||||||
|
|
||||||
|
'rmmulti' => array(
|
||||||
|
'line' => 2,
|
||||||
|
'char' => 1,
|
||||||
|
'original' => "\n",
|
||||||
|
'replacement' => '',
|
||||||
|
),
|
||||||
|
|
||||||
|
'rmmulti2' => array(
|
||||||
|
'line' => 1,
|
||||||
|
'char' => 2,
|
||||||
|
'original' => "\n",
|
||||||
|
'replacement' => '',
|
||||||
|
),
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$defaults = array(
|
$defaults = array(
|
||||||
|
|
10
src/lint/renderer/__tests__/data/rmmulti.expect
Normal file
10
src/lint/renderer/__tests__/data/rmmulti.expect
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
>>> Lint for path/to/example.c:
|
||||||
|
|
||||||
|
|
||||||
|
Warning (WARN123) Lint Warning
|
||||||
|
Consider this.
|
||||||
|
|
||||||
|
1 A
|
||||||
|
2 ~
|
||||||
|
>>> - 3 ~
|
||||||
|
4 B
|
4
src/lint/renderer/__tests__/data/rmmulti.txt
Normal file
4
src/lint/renderer/__tests__/data/rmmulti.txt
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
A
|
||||||
|
|
||||||
|
|
||||||
|
B
|
10
src/lint/renderer/__tests__/data/rmmulti2.expect
Normal file
10
src/lint/renderer/__tests__/data/rmmulti2.expect
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
>>> Lint for path/to/example.c:
|
||||||
|
|
||||||
|
|
||||||
|
Warning (WARN123) Lint Warning
|
||||||
|
Consider this.
|
||||||
|
|
||||||
|
1 A
|
||||||
|
>>> - 2 ~
|
||||||
|
3 ~
|
||||||
|
4 B
|
4
src/lint/renderer/__tests__/data/rmmulti2.txt
Normal file
4
src/lint/renderer/__tests__/data/rmmulti2.txt
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
A
|
||||||
|
|
||||||
|
|
||||||
|
B
|
Loading…
Reference in a new issue