-
-
Notifications
You must be signed in to change notification settings - Fork 61
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
Proposal: flag regular PHP comments with PHPDoc tags and convert them to DocBlocks #780
Comments
@anton-vlasenko DocBlocks are special type of comments and should only be used for structural elements. Inline comments should be used for everything else. Refs:
The PHP tokenizer does nothing with tags in the first place and at compile-time all comments will be removed anyway, so I don't understand what you are trying to say here. Turning inline comments, which are not related to structural elements, into DocBlocks sounds like an oxymoron to me. For structural elements there are already numerous sniffs - in the PEAR and Squiz standards - which check those elements have a docblock and these sniffs will already flag if a non-DocBlock style comment is found instead. All in all, I can't think of a single reason why a sniff like this would be a good idea, though I'm open to hearing valid arguments to the contrary. |
Thank you for the feedback, @jrfnl.
Yes, I know.
While I agree that the PHP tokenizer doesn't parse tags specifically, it does differentiate between "regular" comments and DocBlocks, as there are distinct tokens for comments ( For example, Consider another scenario: /* @var Foo $foo */
$foo = 'bar'; Will PHPCS catch this issue? This comment should be written as a DocBlock, but since it is formatted as a regular comment, sniffs listening for the
I'm not entirely sure what your definition of a structural element is, but there are cases, as shown above, where DocBlocks can be used for regular variables or virtually any part of the code that is not a class, trait, property, method, function, or similar (i.e., structural elements). |
It's not about my definition, but about the definition of the concept. See the reference links I posted above.
Whether this is caught depends on the sniff and is the responsibility of the sniff.
Correct, in which case, the sniff checking those comments should be improved. Blindly turning any comment which contains a tag into a DocBlock is not the correct way to go about this. |
Current situation
PHP codebases often contain inline (
//
,#
) and/or multiline (/* ... */
) comments that include PHPDoc-style tags such as@param
,@return
, or@todo
.However, these comments are not recognized as valid PHPDoc blocks because they lack the correct DocBlock delimiters (
/** ... */
).As a result, the PHP tokenizer may fail to parse these tags, leading to incomplete or inaccurate code analysis and documentation generation.
Solution
Develop a PHPCS sniff to detect inline/multiline comments that contain PHPDoc-style tags (e.g.,
@param
,@return
,@todo
).Sniff behavior:
T_COMMENT
) that include any PHPDoc-style tags;/** ... */
);Impact:
The text was updated successfully, but these errors were encountered: