1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Add switch for newline swallowing

This commit is contained in:
Brown 2019-04-17 14:29:59 -04:00
parent cf36d50c65
commit f51b073c40

View File

@ -34,26 +34,28 @@ class FileManipulationBuffer
) { ) {
$bounds = $code_location->getSnippetBounds(); $bounds = $code_location->getSnippetBounds();
$project_analyzer = \Psalm\Internal\Analyzer\ProjectAnalyzer::getInstance(); if ($swallow_newlines) {
$project_analyzer = \Psalm\Internal\Analyzer\ProjectAnalyzer::getInstance();
$codebase = $project_analyzer->getCodebase(); $codebase = $project_analyzer->getCodebase();
$file_contents = $codebase->getFileContents($code_location->file_path); $file_contents = $codebase->getFileContents($code_location->file_path);
$removed_lines = false; $removed_lines = false;
if (($file_contents[$bounds[0] - 1] ?? null) === PHP_EOL if (($file_contents[$bounds[0] - 1] ?? null) === PHP_EOL
&& ($file_contents[$bounds[0] - 2] ?? null) === PHP_EOL && ($file_contents[$bounds[0] - 2] ?? null) === PHP_EOL
) { ) {
$removed_lines = true; $removed_lines = true;
$bounds[0] -= 2; $bounds[0] -= 2;
} }
if (!$removed_lines if (!$removed_lines
&& ($file_contents[$bounds[1]] ?? null) === PHP_EOL && ($file_contents[$bounds[1]] ?? null) === PHP_EOL
&& ($file_contents[$bounds[1] + 1] ?? null) === PHP_EOL && ($file_contents[$bounds[1] + 1] ?? null) === PHP_EOL
) { ) {
$bounds[1] += 2; $bounds[1] += 2;
}
} }
self::add( self::add(