-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bleeding Edge - PhpDocParser: add config for lines in its AST & enabl…
…e ignoring errors within phpdocs
- Loading branch information
Showing
13 changed files
with
205 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Rules\PhpDoc; | ||
|
||
use PhpParser\Node as PhpParserNode; | ||
use PHPStan\PhpDocParser\Ast\Node as PhpDocNode; | ||
|
||
class PhpDocLineHelper | ||
{ | ||
|
||
/** | ||
* This method returns exact line of e.g. `@param` tag in PHPDoc so that it can be used for precise error reporting | ||
* - exact position is available only when bleedingEdge is enabled | ||
* - otherwise, it falls back to given node start line | ||
*/ | ||
public static function detectLine(PhpParserNode $node, PhpDocNode $phpDocNode): int | ||
{ | ||
$phpDocTagLine = $phpDocNode->getAttribute('startLine'); | ||
$phpDoc = $node->getDocComment(); | ||
|
||
if ($phpDocTagLine === null || $phpDoc === null) { | ||
return $node->getLine(); | ||
} | ||
|
||
return $phpDoc->getStartLine() + $phpDocTagLine - 1; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace IgnoreNextLineLegacy; | ||
|
||
class Foo | ||
{ | ||
|
||
public function doFoo(): void | ||
{ | ||
fail(); // reported | ||
|
||
// @phpstan-ignore-next-line | ||
fail(); | ||
|
||
/* @phpstan-ignore-next-line */ | ||
fail(); | ||
|
||
/** @phpstan-ignore-next-line */ | ||
fail(); | ||
|
||
/* | ||
* @phpstan-ignore-next-line | ||
*/ | ||
fail(); | ||
|
||
/** | ||
* @phpstan-ignore-next-line | ||
* | ||
* This is the legacy behaviour, the next line is meant as next-non-comment-line | ||
*/ | ||
fail(); | ||
fail(); // reported | ||
|
||
// @phpstan-ignore-next-line | ||
if (fail()) { | ||
fail(); // reported | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.