mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-22 14:52:40 +01:00
Fix a similar lint rendering issue when trimming identical lines out of patches
Summary: Ref T9846. See PHI48. See D18538 for a similar fix. We can contract the suffix lines too much if, e.g, a newline after another newline is removed. Prevent contraction to fewer than 0 lines. Test Plan: Added a failing test, made it pass. Reviewers: chad Reviewed By: chad Subscribers: alexmv Maniphest Tasks: T9846 Differential Revision: https://secure.phabricator.com/D18541
This commit is contained in:
parent
7371277d20
commit
cbc785ddce
4 changed files with 46 additions and 7 deletions
|
@ -171,13 +171,10 @@ final class ArcanistConsoleLintRenderer extends ArcanistLintRenderer {
|
|||
$old_impact--;
|
||||
$new_impact--;
|
||||
|
||||
if ($old_impact < 0 || $new_impact < 0) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'Modified suffix line range has become negative '.
|
||||
'(old = %d, new = %d).',
|
||||
$old_impact,
|
||||
$new_impact));
|
||||
// We can end up here if a patch removes a line which occurs after
|
||||
// another identical line.
|
||||
if ($old_impact <= 0 || $new_impact <= 0) {
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
|
||||
|
|
|
@ -15,6 +15,23 @@ EOTEXT;
|
|||
import apple;
|
||||
import banana;
|
||||
|
||||
import cat;
|
||||
import dog;
|
||||
EOTEXT;
|
||||
|
||||
$remline_original = <<<EOTEXT
|
||||
import apple;
|
||||
import banana;
|
||||
|
||||
|
||||
import cat;
|
||||
import dog;
|
||||
EOTEXT;
|
||||
|
||||
$remline_replacement = <<<EOTEXT
|
||||
import apple;
|
||||
import banana;
|
||||
|
||||
import cat;
|
||||
import dog;
|
||||
EOTEXT;
|
||||
|
@ -89,6 +106,13 @@ EOTEXT;
|
|||
'original' => $midline_original,
|
||||
'replacement' => $midline_replacement,
|
||||
),
|
||||
|
||||
'remline' => array(
|
||||
'line' => 1,
|
||||
'char' => 1,
|
||||
'original' => $remline_original,
|
||||
'replacement' => $remline_replacement,
|
||||
),
|
||||
);
|
||||
|
||||
$defaults = array(
|
||||
|
|
12
src/lint/renderer/__tests__/data/remline.expect
Normal file
12
src/lint/renderer/__tests__/data/remline.expect
Normal file
|
@ -0,0 +1,12 @@
|
|||
>>> Lint for path/to/example.c:
|
||||
|
||||
|
||||
Warning (WARN123) Lint Warning
|
||||
Consider this.
|
||||
|
||||
1 import apple;
|
||||
2 import banana;
|
||||
3 ~
|
||||
>>> - 4 ~
|
||||
5 import cat;
|
||||
6 import dog;
|
6
src/lint/renderer/__tests__/data/remline.txt
Normal file
6
src/lint/renderer/__tests__/data/remline.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
import apple;
|
||||
import banana;
|
||||
|
||||
|
||||
import cat;
|
||||
import dog;
|
Loading…
Reference in a new issue