Do not print files with fatal errors as the file format breaks completely (#5967)

This commit is contained in:
Tomas Votruba 2021-03-23 23:29:59 +01:00 committed by GitHub
parent 27e9ad030a
commit ae8ead946b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -179,4 +179,15 @@ final class ErrorAndDiffCollector
$this->errors[] = new RectorError($fileInfo, $throwable->getMessage(), $throwable->getCode());
}
}
public function hasErrors(SmartFileInfo $phpFileInfo): bool
{
foreach ($this->errors as $error) {
if ($error->getFileInfo() === $phpFileInfo) {
return true;
}
}
return false;
}
}

View File

@ -166,6 +166,12 @@ final class RectorApplication
// 4. print to file or string
foreach ($phpFileInfos as $phpFileInfo) {
// cannot print file with errors, as print would break everything to orignal nodes
if ($this->errorAndDiffCollector->hasErrors($phpFileInfo)) {
$this->advance($phpFileInfo, 'printing');
continue;
}
$this->tryCatchWrapper($phpFileInfo, function (SmartFileInfo $smartFileInfo): void {
$this->printFileInfo($smartFileInfo);
}, 'printing');