-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Feature request: add sniff support for constant comments #2221
Comments
I think a ConstantComment sniff sounds like a good idea. I haven't reviewed the doc comment sniffs because I've been waiting for PSR-5 to be complete so I could (hopefully) standardise the checks instead of using the Squiz-specific ones. That, and a lack of time. If you want to give any of the comment sniffs a go, please do. Huge bonus if you have it enforce PSR-2's recommendations. |
Thank you @gsherwood. I hope to start working on this soon. |
@rjgwiz 👍 You can basically copy https://github.com/Symplify/Symplify/blob/master/packages/CodingStandard/src/Sniffs/Commenting/VarConstantCommentSniff.php + extends a bit to match your needs. /**
* @var int
*/
private const VALUE = 10; It works great with static analysis rule - https://github.com/Symplify/Symplify/blob/master/packages/PHPStanExtensions/src/Rules/Classes/MatchingTypeConstantRule.php, e.g.: /**
* @var int
*/
private const VALUE = '10'; // Error! |
Related to #2222 which will make creating this sniff so much easier ;-) |
Thank you both. I plan to get to this in the next week or two. |
@jrfnl Any ETA on that feature coming to tagged version? |
@TomasVotruba I expect it to be ready for PHPCS 3.5.0 which includes lots of other goodies which will be useful for this too. See #2189 |
@jrfnl That would be amazing! |
I guess this wasnt pursued further so far? |
phpdoc mentions constants under the programming constructs that should be preceded by a DocBlock.
I can't find anyway to enforce docblock comments for constants.
Docblock comments are currently enforceable via
ClassCommentSniff
,FunctionCommentSniff
,VariableCommentSniff
, andFileCommentSniff
. None seem appropriate to add support for constants (VariableCommentSniff
would be the closest, but it extendsAbstractVariableSniff
and addingT_CONST
to the listen list would break a lot of other sniffs, class constants aren't normal variables, and it wouldn't cover defined constants.Some sniffs exist for constants, for example
UpperCaseConstantNameSniff
. Any hesitations around adding a new sniff calledConstantCommentSniff
? Scope would be the same asUpperCaseConstantNameSniff
so any constant defined via thedefine()
function or theconst
keyword (e.g. class constant).With buy-in I could work on
ConstantCommentSniff
and submit a PR when it's ready.The text was updated successfully, but these errors were encountered: