From 986eaa12145e63eb03eed047131c9f0b6498405e Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Mon, 29 Apr 2019 19:04:10 +0200 Subject: [PATCH] :bug: Fix for custom tag --- .../DocCommentGroupSameTypeSniff.php | 2 + .../WhiteSpace/DocCommentTagSpacingSniff.php | 64 +++++++++++++++---- .../DocCommentTagSpacingUnitTest.inc | 10 +++ .../DocCommentTagSpacingUnitTest.inc.fixed | 10 +++ .../DocCommentTagSpacingUnitTest.php | 8 +-- 5 files changed, 79 insertions(+), 15 deletions(-) diff --git a/SymfonyCustom/Sniffs/Commenting/DocCommentGroupSameTypeSniff.php b/SymfonyCustom/Sniffs/Commenting/DocCommentGroupSameTypeSniff.php index db9d7e3..e627211 100644 --- a/SymfonyCustom/Sniffs/Commenting/DocCommentGroupSameTypeSniff.php +++ b/SymfonyCustom/Sniffs/Commenting/DocCommentGroupSameTypeSniff.php @@ -20,6 +20,8 @@ class DocCommentGroupSameTypeSniff implements Sniff '@author', '@category', '@copyright', + '@covers', + '@dataProvider', '@deprecated', '@example', '@filesource', diff --git a/SymfonyCustom/Sniffs/WhiteSpace/DocCommentTagSpacingSniff.php b/SymfonyCustom/Sniffs/WhiteSpace/DocCommentTagSpacingSniff.php index 51e7605..0de9bb9 100644 --- a/SymfonyCustom/Sniffs/WhiteSpace/DocCommentTagSpacingSniff.php +++ b/SymfonyCustom/Sniffs/WhiteSpace/DocCommentTagSpacingSniff.php @@ -10,6 +10,44 @@ */ class DocCommentTagSpacingSniff implements Sniff { + /** + * A list of PHPDoc tags that are checked. + * + * @var array + */ + public $tags = array( + '@api', + '@author', + '@category', + '@copyright', + '@covers', + '@dataProvider', + '@deprecated', + '@example', + '@filesource', + '@global', + '@ignore', + '@internal', + '@license', + '@link', + '@method', + '@package', + '@param', + '@property', + '@property-read', + '@property-write', + '@return', + '@see', + '@since', + '@source', + '@subpackage', + '@throws', + '@todo', + '@uses', + '@var', + '@version', + ); + /** * Returns an array of tokens this test wants to listen for. * @@ -49,22 +87,26 @@ public function process(File $phpcsFile, $stackPtr) if (true === $fix) { $phpcsFile->fixer->addContentBefore($stackPtr, ' '); } - } elseif (1 !== $tokens[($stackPtr - 1)]['length']) { - $error = 'There should be only one space before a doc comment tag "%s"'; - $fix = $phpcsFile->addFixableError( - $error, - ($stackPtr + 1), - 'DocCommentTagSpacing', - [$tokens[$stackPtr]['content']] - ); + } elseif (1 < $tokens[($stackPtr - 1)]['length']) { + $isCustomTag = !in_array($tokens[$stackPtr]['content'], $this->tags); - if (true === $fix) { - $phpcsFile->fixer->replaceToken($stackPtr - 1, ' '); + // Custom tags are not checked cause there is annotation with array params + if (!$isCustomTag) { + $error = 'There should be only one space before a doc comment tag "%s"'; + $fix = $phpcsFile->addFixableError( + $error, + ($stackPtr + 1), + 'DocCommentTagSpacing', + [$tokens[$stackPtr]['content']] + ); + + if (true === $fix) { + $phpcsFile->fixer->replaceToken($stackPtr - 1, ' '); + } } } } - // No need to check for space after a doc comment tag if (isset($tokens[($stackPtr + 1)]) && $tokens[$stackPtr]['line'] === $tokens[($stackPtr + 1)]['line'] && T_DOC_COMMENT_WHITESPACE === $tokens[($stackPtr + 1)]['code'] diff --git a/SymfonyCustom/Tests/WhiteSpace/DocCommentTagSpacingUnitTest.inc b/SymfonyCustom/Tests/WhiteSpace/DocCommentTagSpacingUnitTest.inc index 3a5493d..e3b5cc4 100644 --- a/SymfonyCustom/Tests/WhiteSpace/DocCommentTagSpacingUnitTest.inc +++ b/SymfonyCustom/Tests/WhiteSpace/DocCommentTagSpacingUnitTest.inc @@ -20,6 +20,16 @@ class DocCommentTagSpacingUnitTest * * @JMS\Type("string") * @JMS\SerializedName("libelle") + * @ORM\AttributeOverrides({ + * @ORM\AttributeOverride( + * name="email", + * column=@ORM\Column(type="string", name="email", length=255, unique=false, nullable=true) + * ), + * @ORM\AttributeOverride( + * name="emailCanonical", + * column=@ORM\Column(type="string", name="email_canonical", length=255, unique=false, nullable=true) + * ) + * }) */ private $label; diff --git a/SymfonyCustom/Tests/WhiteSpace/DocCommentTagSpacingUnitTest.inc.fixed b/SymfonyCustom/Tests/WhiteSpace/DocCommentTagSpacingUnitTest.inc.fixed index 40a27eb..cc587e4 100644 --- a/SymfonyCustom/Tests/WhiteSpace/DocCommentTagSpacingUnitTest.inc.fixed +++ b/SymfonyCustom/Tests/WhiteSpace/DocCommentTagSpacingUnitTest.inc.fixed @@ -20,6 +20,16 @@ class DocCommentTagSpacingUnitTest * * @JMS\Type("string") * @JMS\SerializedName("libelle") + * @ORM\AttributeOverrides({ + * @ORM\AttributeOverride( + * name="email", + * column=@ORM\Column(type="string", name="email", length=255, unique=false, nullable=true) + * ), + * @ORM\AttributeOverride( + * name="emailCanonical", + * column=@ORM\Column(type="string", name="email_canonical", length=255, unique=false, nullable=true) + * ) + * }) */ private $label; diff --git a/SymfonyCustom/Tests/WhiteSpace/DocCommentTagSpacingUnitTest.php b/SymfonyCustom/Tests/WhiteSpace/DocCommentTagSpacingUnitTest.php index a740580..52f91b5 100644 --- a/SymfonyCustom/Tests/WhiteSpace/DocCommentTagSpacingUnitTest.php +++ b/SymfonyCustom/Tests/WhiteSpace/DocCommentTagSpacingUnitTest.php @@ -25,10 +25,10 @@ public function getErrorList() 11 => 1, 13 => 1, 14 => 1, - 29 => 1, - 30 => 1, - 32 => 1, - 36 => 1, + 39 => 1, + 40 => 1, + 42 => 1, + 46 => 1, ); }