1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-02 09:37:59 +01:00

Make diff map more verbose so it can serve as a list of safe zones

Outside them all issues must be removed
This commit is contained in:
Matthew Brown 2019-01-08 00:54:48 -05:00
parent a2ee2f12a4
commit 370874d9b6
4 changed files with 78 additions and 20 deletions

View File

@ -411,7 +411,6 @@ class Analyzer
} }
} }
$this->shiftFileOffsets($diff_map); $this->shiftFileOffsets($diff_map);
foreach ($this->files_to_analyze as $file_path) { foreach ($this->files_to_analyze as $file_path) {
@ -443,6 +442,7 @@ class Analyzer
foreach ($file_issues as $i => &$issue_data) { foreach ($file_issues as $i => &$issue_data) {
if ($issue_data['to'] < $first_diff_offset || $issue_data['from'] > $last_diff_offset) { if ($issue_data['to'] < $first_diff_offset || $issue_data['from'] > $last_diff_offset) {
unset($file_issues[$i]);
continue; continue;
} }
@ -454,6 +454,8 @@ class Analyzer
$issue_data['snippet_to'] += $file_offset; $issue_data['snippet_to'] += $file_offset;
$issue_data['line_from'] += $line_offset; $issue_data['line_from'] += $line_offset;
$issue_data['line_to'] += $line_offset; $issue_data['line_to'] += $line_offset;
} else {
unset($file_issues[$i]);
} }
} }
} }

View File

@ -86,9 +86,7 @@ class ClassStatementsDiffer extends AstDiffer
$start_diff = $b_start - $a_start; $start_diff = $b_start - $a_start;
$line_diff = $b->getLine() - $a->getLine(); $line_diff = $b->getLine() - $a->getLine();
if ($start_diff !== 0 || $line_diff !== 0) { $diff_map[] = [$a_start, $a_end, $start_diff, $line_diff];
$diff_map[] = [$a_start, $a_end, $start_diff, $line_diff];
}
return true; return true;
} }

View File

@ -231,7 +231,7 @@ class FileDiffTest extends TestCase
['foo\a::$aB', 'foo\a::F', 'foo\a::foo', 'foo\a::bar'], ['foo\a::$aB', 'foo\a::F', 'foo\a::foo', 'foo\a::bar'],
[], [],
[], [],
[] [[0, 0], [0, 0], [0, 0], [0, 0]]
], ],
'sameFileWithDoubleDocblocks' => [ 'sameFileWithDoubleDocblocks' => [
'<?php '<?php
@ -285,7 +285,7 @@ class FileDiffTest extends TestCase
['foo\a::$aB', 'foo\a::F', 'foo\a::foo', 'foo\a::bar'], ['foo\a::$aB', 'foo\a::F', 'foo\a::foo', 'foo\a::bar'],
[], [],
[], [],
[] [[0, 0], [0, 0], [0, 0], [0, 0]]
], ],
'lineChanges' => [ 'lineChanges' => [
'<?php '<?php
@ -411,7 +411,7 @@ class FileDiffTest extends TestCase
['foo\a::foo'], ['foo\a::foo'],
[], [],
['foo\a::bar', 'foo\a::bar'], ['foo\a::bar', 'foo\a::bar'],
[] [[0, 0]]
], ],
'propertyChange' => [ 'propertyChange' => [
'<?php '<?php
@ -587,7 +587,7 @@ class FileDiffTest extends TestCase
['foo\a::foo'], ['foo\a::foo'],
[], [],
['foo\a::bar', 'foo\a::bar'], ['foo\a::bar', 'foo\a::bar'],
[] [[0, 0]]
], ],
'removeDocblock' => [ 'removeDocblock' => [
'<?php '<?php
@ -618,7 +618,7 @@ class FileDiffTest extends TestCase
['foo\a::foo'], ['foo\a::foo'],
[], [],
['foo\a::bar', 'foo\a::bar'], ['foo\a::bar', 'foo\a::bar'],
[] [[0, 0]]
], ],
'changeDocblock' => [ 'changeDocblock' => [
'<?php '<?php
@ -652,7 +652,7 @@ class FileDiffTest extends TestCase
['foo\a::foo'], ['foo\a::foo'],
[], [],
['foo\a::bar', 'foo\a::bar'], ['foo\a::bar', 'foo\a::bar'],
[] [[0, 0]]
], ],
'changeMethodVisibility' => [ 'changeMethodVisibility' => [
'<?php '<?php
@ -680,7 +680,7 @@ class FileDiffTest extends TestCase
['foo\a::foo'], ['foo\a::foo'],
[], [],
['foo\a::bar', 'foo\a::bar'], ['foo\a::bar', 'foo\a::bar'],
[] [[0, 0]]
], ],
'removeFunctionAtEnd' => [ 'removeFunctionAtEnd' => [
'<?php '<?php
@ -729,7 +729,7 @@ class FileDiffTest extends TestCase
['foo\a::foo', 'foo\a::bar'], ['foo\a::foo', 'foo\a::bar'],
[], [],
['foo\a::bat'], ['foo\a::bat'],
[] [[0, 0], [0, 0]]
], ],
'addSpaceInFunction' => [ 'addSpaceInFunction' => [
'<?php '<?php
@ -803,7 +803,7 @@ class FileDiffTest extends TestCase
['foo\a::foo', 'foo\a::bat'], ['foo\a::foo', 'foo\a::bat'],
['foo\a::bar'], ['foo\a::bar'],
[], [],
[[4, 4]] [[0, 0], [4, 4]]
], ],
'removeSpaceInFunction' => [ 'removeSpaceInFunction' => [
'<?php '<?php
@ -877,7 +877,7 @@ class FileDiffTest extends TestCase
['foo\a::foo', 'foo\a::bat'], ['foo\a::foo', 'foo\a::bat'],
['foo\a::bar'], ['foo\a::bar'],
[], [],
[[-4, -4]] [[0, 0], [-4, -4]]
], ],
'removeFunctionAtBeginning' => [ 'removeFunctionAtBeginning' => [
'<?php '<?php
@ -939,7 +939,7 @@ class FileDiffTest extends TestCase
['foo\a::foo', 'foo\a::bat'], ['foo\a::foo', 'foo\a::bat'],
[], [],
['foo\a::bar'], ['foo\a::bar'],
[[-98, -3]], [[0, 0], [-98, -3]],
], ],
'changeNamespace' => [ 'changeNamespace' => [
'<?php '<?php
@ -1036,7 +1036,7 @@ class FileDiffTest extends TestCase
['foo\a::foo', 'foo\a::bar'], ['foo\a::foo', 'foo\a::bar'],
[], [],
['foo\a::bat'], ['foo\a::bat'],
[] [[0, 0], [0, 0]]
], ],
'newFunctionAtBeginning' => [ 'newFunctionAtBeginning' => [
'<?php '<?php
@ -1134,7 +1134,7 @@ class FileDiffTest extends TestCase
['foo\a::foo', 'foo\a::bar'], ['foo\a::foo', 'foo\a::bar'],
[], [],
['foo\a::bat'], ['foo\a::bat'],
[[183, 7]] [[0, 0], [183, 7]]
], ],
'removeAdditionalComments' => [ 'removeAdditionalComments' => [
'<?php '<?php
@ -1247,7 +1247,7 @@ class FileDiffTest extends TestCase
['foo\a::__construct', 'foo\a::bar', 'foo\b::bat'], ['foo\a::__construct', 'foo\a::bar', 'foo\b::bat'],
[], [],
['foo\b::__construct', 'foo\b::bar'], ['foo\b::__construct', 'foo\b::bar'],
[[120, 2]] [[0, 0], [0, 0], [120, 2]]
], ],
'sameTrait' => [ 'sameTrait' => [
'<?php '<?php
@ -1283,7 +1283,7 @@ class FileDiffTest extends TestCase
['foo\t::$aB', 'foo\t::F', 'foo\t::foo', 'foo\t::bar'], ['foo\t::$aB', 'foo\t::F', 'foo\t::foo', 'foo\t::bar'],
[], [],
[], [],
[] [[0, 0], [0, 0], [0, 0], [0, 0]]
], ],
'traitPropertyChange' => [ 'traitPropertyChange' => [
'<?php '<?php
@ -1416,7 +1416,7 @@ class FileDiffTest extends TestCase
['bar\foo::a', 'bar\foo::c'], ['bar\foo::a', 'bar\foo::c'],
[], [],
['bar\foo::b'], ['bar\foo::b'],
[[229, 8]] [[0, 0], [229, 8]]
], ],
'removeStatementsAbove' => [ 'removeStatementsAbove' => [
'<?php '<?php

View File

@ -975,6 +975,64 @@ class TemporaryUpdateTest extends \Psalm\Tests\TestCase
], ],
'error_positions' => [[], [238], [], [238], []], 'error_positions' => [[], [238], [], [238], []],
], ],
'duplicateMethodThenRemove' => [
[
[
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
class A {
/**
* @return void
*/
public static function foo() {}
/**
* @return void
*/
public static function bar(
string $function_id
) {}
}',
],
[
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
class A {
/**
* @return void
*/
public static function foo() {}
/**
* @return void
*/
public static function foo() {}
/**
* @return void
*/
public static function bar(
string $function_id
) {}
}',
],
[
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
class A {
/**
* @return void
*/
public static function foo() {}
/**
* @return void
*/
public static function bar(
string $function_id
) {}
}',
],
],
'error_positions' => [[], [381], []],
],
]; ];
} }
} }