-
Notifications
You must be signed in to change notification settings - Fork 53
Create @todo format sniff. #120
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
Conversation
Amend comments in regex, add test for normal to do in comment, remove…
Tests pass, that's great. |
I believe this is ready for final review and merging. @jonathan1055 thanks for all of your feedback and help on this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks a lot!
I will do a test run against Drupal core to check if I see any false positives.
{ | ||
$debug = Config::getConfigData('todo_debug'); | ||
if ($debug !== null) { | ||
$this->debug = (bool) $debug; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should not initialize this variable on every single process() call? Can we do that once in the constructor instead?
Ah, I see that this approach is copied from ScopeIndentSniff, so also not ideal there. Anyway, then I think it is fine to keep this as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes and I also used it in Commenting/DeprecatedSniff Would you like me to start a new issus to change all three of these, when this is committed?
} | ||
|
||
$comment = trim($comment, " /\r\n"); | ||
$phpcsFile->addWarning("'%s' should match the format '@todo Some task'", $stackPtr, 'TodoFormat', [$comment]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments should end with a dot, also todo comments. So the example should be something like @todo Fix problem X here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be really cool to have a fixer here, that would help many people auto-fix this standard (also in Drupal core). I think it should be possible, we should have all info in the regex and could try a preg_replace().
Not a blocker for this pull request, we can merge this as first step.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, doc comments not ending with a period is checked for. But currently @ tags are not considered within that group, so no warning is given if they have no period at the end. I agree that if they should end in a dot then this example should include the dot. But then we should also include @ tags in the general sniff for no ending period. @see should not be included, we discussed that on the deprecation sniffs, the url should not end in a dot. Maybe this is for another issue?
Regarding a fixer, yes it should be possible. @ adamzimmermann did suggest that, but we wanted to wait until we knew you were interested in this sniff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, very considerate of you! Yep, I absolutely support this sniff.
Also yep to the ending dot discussion, should be a separate issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also yep to the ending dot discussion, should be a separate issue.
I have raised https://www.drupal.org/project/coder/issues/3183156 to check for doc tags not ending with a period.
All warnings found in Drupal core look correct to me, yay! Will merge this now and improve the warning message as I proposed. |
Adds @todo format sniff.
Drupal.org issue:
Testing/Examples:
Questions:
Will the//
be in the string that is sent to the sniff? If so, I need to adjust it.- Should we enforce a capital letter after@todo
? (I went ahead and did this.)Closing #118 in favor of this PR to simplify/avoid merge conflicts from this PR where the following was done: