Merge pull request #37 from weirdan/dont-crash-on-invalid-docblock

Don't crash on invalid docblocks
This commit is contained in:
Matthew Brown 2019-07-10 17:04:35 -04:00 committed by GitHub
commit 2215d64562
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 1 deletions

View File

@ -7,6 +7,7 @@ use PhpParser\Node\Stmt\ClassMethod;
use Psalm\CodeLocation;
use Psalm\Codebase;
use Psalm\DocComment;
use Psalm\Exception\DocblockParseException;
use Psalm\FileSource;
use Psalm\IssueBuffer;
use Psalm\Issue;
@ -528,7 +529,11 @@ class TestCaseHandler implements
$docblock = $method->getDocComment();
if ($docblock) {
$parsed_comment = DocComment::parse((string)$docblock->getReformattedText(), $docblock->getLine());
try {
$parsed_comment = DocComment::parse((string)$docblock->getReformattedText(), $docblock->getLine());
} catch (DocblockParseException $e) {
return [];
}
if (isset($parsed_comment['specials'])) {
return $parsed_comment['specials'];
}

View File

@ -1003,3 +1003,48 @@ Feature: TestCase
"""
When I run Psalm with dead code detection
Then I see no errors
Scenario: Invalid psalm annotation on a class does not crash psalm
Given I have the following code
"""
/** @psalm-ignore Everything */
class MyTestCase extends TestCase {}
"""
When I run Psalm
Then I see these errors
| Type | Message |
| InvalidDocblock | %@psalm-ignore% |
Scenario: Invalid psalm annotation on an before initializer does not crash psalm
Given I have the following code
"""
class MyTestCase extends TestCase {
/**
* @before
* @psalm-rm-Rf-slash
* @return void
*/
public function preparation() {}
}
"""
When I run Psalm
Then I see these errors
| Type | Message |
| InvalidDocblock | %@psalm-rm-Rf-slash% |
Scenario: Invalid psalm annotation on a test does not crash psalm
Given I have the following code
"""
class MyTestCase extends TestCase {
/**
* @test
* @psalm-force-push-master
* @return void
*/
public function doThings() {}
}
"""
When I run Psalm
Then I see these errors
| Type | Message |
| InvalidDocblock | %@psalm-force-push-master% |