Skip to content

Squiz/VariableComment: make errorcode for "TagNotAllowed" warning modular #1039

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
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
10 changes: 4 additions & 6 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@
<rule ref="Squiz.Commenting.PostStatementComment">
<exclude name="Squiz.Commenting.PostStatementComment.AnnotationFound"/>
</rule>
<rule ref="Squiz.Commenting.VariableComment"/>
<rule ref="Squiz.Commenting.VariableComment">
<exclude name="Squiz.Commenting.VariableComment.DeprecatedTagNotAllowed"/>
<exclude name="Squiz.Commenting.VariableComment.LinkTagNotAllowed"/>
</rule>
<rule ref="Squiz.Formatting.OperatorBracket"/>
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing"/>
<rule ref="Squiz.Operators.ComparisonOperatorUsage"/>
Expand Down Expand Up @@ -154,9 +157,4 @@
<exclude-pattern>src/Standards/Generic/Sniffs/Commenting/TodoSniff\.php</exclude-pattern>
<exclude-pattern>src/Standards/Generic/Tests/Commenting/TodoUnitTest\.php</exclude-pattern>
</rule>

<!-- @see https://github.com/PHPCSStandards/PHP_CodeSniffer/pull/122#discussion_r1414167897 -->
<rule ref="Squiz.Commenting.VariableComment">
<exclude-pattern>src/Util/Tokens\.php</exclude-pattern>
</rule>
</ruleset>
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ public function processMemberVar(File $phpcsFile, $stackPtr)
} else {
$error = '%s tag is not allowed in member variable comment';
$data = [$tokens[$tag]['content']];
$phpcsFile->addWarning($error, $tag, 'TagNotAllowed', $data);
$code = ucwords(ltrim($tokens[$tag]['content'], '@')).'TagNotAllowed';
$phpcsFile->addWarning($error, $tag, $code, $data);
}//end if
}//end foreach

Expand Down
23 changes: 23 additions & 0 deletions src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -476,3 +476,26 @@ class PHP84FinalProperties {
*/
final int $hasDocblock;
}

// phpcs:disable Squiz.Commenting.VariableComment.SinceTagNotAllowed
// phpcs:disable Squiz.Commenting.VariableComment.DeprecatedTagNotAllowed
class AllowMoreForSelectivelyIgnoringDisallowedTags {
/**
* @var string
*
* @since 3.1
* @deprecated 10.5
*/
public string $propertyWithExtraTags;

/**
* @var string
*
* @link https://example.org/some-link
* @api
* @param string This tag is not allowed.
*/
public $theAboveExtraTagsAreStillNotAllowed;
}

// phpcs:enable Squiz.Commenting.VariableComment
Original file line number Diff line number Diff line change
Expand Up @@ -476,3 +476,26 @@ class PHP84FinalProperties {
*/
final int $hasDocblock;
}

// phpcs:disable Squiz.Commenting.VariableComment.SinceTagNotAllowed
// phpcs:disable Squiz.Commenting.VariableComment.DeprecatedTagNotAllowed
class AllowMoreForSelectivelyIgnoringDisallowedTags {
/**
* @var string
*
* @since 3.1
* @deprecated 10.5
*/
public string $propertyWithExtraTags;

/**
* @var string
*
* @link https://example.org/some-link
* @api
* @param string This tag is not allowed.
*/
public $theAboveExtraTagsAreStillNotAllowed;
}

// phpcs:enable Squiz.Commenting.VariableComment
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ public function getErrorList()
*/
public function getWarningList()
{
return [93 => 1];
return [
93 => 1,
494 => 1,
495 => 1,
496 => 1,
];

}//end getWarningList()

Expand Down
Loading