Skip to content

Commit

Permalink
Merge pull request #144 from VincentLanglet/phpcsDoc
Browse files Browse the repository at this point in the history
Avoid false positiv with phpcs tags
  • Loading branch information
VincentLanglet authored Jul 25, 2021
2 parents b95b985 + bd5d44b commit 12d33a8
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Util\Tokens;
use SymfonyCustom\Helpers\FixerHelper;
use SymfonyCustom\Helpers\SniffHelper;

Expand Down Expand Up @@ -43,7 +44,11 @@ public function process(File $phpcsFile, $stackPtr): void

$commentTagLine = $tokens[$commentTag]['line'];

$previousString = $phpcsFile->findPrevious(T_DOC_COMMENT_STRING, $commentTag, $stackPtr);
$previousString = $phpcsFile->findPrevious(
array_merge(Tokens::$phpcsCommentTokens, [T_DOC_COMMENT_STRING]),
$commentTag,
$stackPtr
);
$previousLine = -1;

if (false !== $previousString) {
Expand Down
26 changes: 26 additions & 0 deletions SymfonyCustom/Tests/Commenting/DocCommentGroupSameTypeUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,29 @@
*
* @param string $b
*/

/**
* An override of Twig's Lexer to add whitespace and new line detection.
*
* Since the regex are using bytes as position, mb_ methods are voluntary not used.
* phpcs:disable SymfonyCustom.PHP.EncourageMultiBytes
*
* @phpstan-type TokenizerOptions = array{
* tag_comment: array{string, string},
* tag_block: array{string, string},
* tag_variable: array{string, string},
* whitespace_trim: string,
* whitespace_line_trim: string,
* interpolation: array{string, string},
* }
* @phpstan-type Regex = array{
* lex_block: string,
* lex_comment: string,
* lex_variable: string,
* operator: string,
* lex_tokens_start: string,
* interpolation_start: string,
* interpolation_end: string,
* lex_block: string,
* }
*/
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,29 @@
*
* @param string $b
*/

/**
* An override of Twig's Lexer to add whitespace and new line detection.
*
* Since the regex are using bytes as position, mb_ methods are voluntary not used.
* phpcs:disable SymfonyCustom.PHP.EncourageMultiBytes
*
* @phpstan-type TokenizerOptions = array{
* tag_comment: array{string, string},
* tag_block: array{string, string},
* tag_variable: array{string, string},
* whitespace_trim: string,
* whitespace_line_trim: string,
* interpolation: array{string, string},
* }
* @phpstan-type Regex = array{
* lex_block: string,
* lex_comment: string,
* lex_variable: string,
* operator: string,
* lex_tokens_start: string,
* interpolation_start: string,
* interpolation_end: string,
* lex_block: string,
* }
*/

0 comments on commit 12d33a8

Please sign in to comment.