Skip to content

Avoid false positiv with phpcs tags #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
* }
*/