Problem/Motivation
Drupal core doesn't fully follow the @todo formatting guidelines.
https://www.drupal.org/docs/develop/standards/api-documentation-and-comm...
Steps to reproduce
Add this sniff to phpcs.xmldist and run code style checks.
Proposed resolution
Run code style check tool with fixing enabled and commit the patch.
Remaining tasks
Decide if the sniff needs to be changed. The sentence following the '@todo' is not capitalized.
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
Fix @todo comment formatting.
Comment | File | Size | Author |
---|---|---|---|
#56 | 3180696-nr-bot.txt | 90 bytes | needs-review-queue-bot |
#47 | Screenshot 2023-11-17 at 10.05.05 AM.png | 262.73 KB | smustgrave |
#44 | Screenshot 2023-11-17 at 9.27.11 AM.png | 108.27 KB | smustgrave |
Issue fork drupal-3180696
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
adamzimmermann CreditAttribution: adamzimmermann at Chromatic commentedLocally I did the following:
Installed phpcs and other core dependencies.
Pointed phpcs to the 8.x-3.x branch of the coder module that has this unreleased sniff.
Fixed things using the automatic fixing tools.
Found the things that needed manual fixing and addressed them.
Should I include any other file extensions?
I stayed away from filling out empty @todo statements. I didn't want to assume that I was the best person to fill this out. I simply documented that better documentation is needed.
Comment #3
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedThis is a great start. To make it better, you can do two things
Just for background info, in #3048495: Fix Drupal.Semantics.FunctionTriggerError coding standard I tried to pull in the -dev release. In /core/composer.json I tried
which did not work. I tried also to get the specific commit
Then I tried changing /core/drupalci.yml
None of the above worked. But finally I did get the new sniff, by patching Coder from within /core/drupalci.yml
This patch from comment #19 in the issue linked above is an example of how to change to drupalci.yml to halt after running the coding standards. I hope these two ideas help, and will save you time.
Comment #4
adamzimmermann CreditAttribution: adamzimmermann at Chromatic commented@jonathan1055 thank you! I'll get back to this next week.
Comment #5
adamzimmermann CreditAttribution: adamzimmermann at Chromatic commentedUploading a patch to run tests with the latest version of coder to verify issues are found.
Comment #6
longwaveComment #7
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedNot sure what has happened, but in the dispatcher output, phpcs sniffs.txt we get
Maybe the Coder version change does not work. The log just has
with no mention of 8.3.11. I could not make that work, and ended up having to use a patch on Coder to get the new sniff, see my comments in #3 above.
Comment #8
adamzimmermann CreditAttribution: adamzimmermann at Chromatic commented@jonathan1055 ya it seems it needs something else changed too. I'm going to change it everywhere for the moment, so I can ensure I see the sniff failure.
Fingers crossed that this patch does the trick.
Comment #9
adamzimmermann CreditAttribution: adamzimmermann at Chromatic commentedI am putting this on pause until coder 8.3.11 is included in Drupal core.
Core 9.2 is currently using 8.3.10.
Comment #10
neclimdulIt also has problems with @see and @covers annotations. Are those handled in this updated coder? Should I open some other issues for them?
Comment #11
adamzimmermann CreditAttribution: adamzimmermann at Chromatic commented@neclimdul Those are likely from a previous release and should be separate issues.
https://github.com/pfrenssen/coder/compare/8.3.10...8.3.11
Comment #12
neclimdulNot sure I understand what previous release you're referring to.I was trying to understand if the @todo sniff a generalized annotation sniffer or does it only fix todo problems?
Comment #13
adamzimmermann CreditAttribution: adamzimmermann at Chromatic commentedI'm not referring to a specific release (just some previous release). The @todo sniffing in the latest release is not generalized and only addresses @todo statements.
Hopefully that clears things up!
Comment #14
Spokje(@adamzimmermann in #9)
Core 9.2 is now using
Un-postponing.
Comment #15
SpokjeAdded parent issue.
Comment #16
SpokjeComment #17
SpokjeComment #19
SpokjeComment #20
longwaveOne little nit and one question about style, otherwise this looks pretty good.
Comment #21
SpokjeCommented on style and fixed nit.
Comment #22
quietone CreditAttribution: quietone as a volunteer commentedMy review may include items out of scope - I am not sure. There are lots of links that use 'project/drupal' instead of just node, not sure if that can be fixed here or not.
Comment #23
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedTo speed up the test runs, and to save resources, can you implement the changes to core/drupalci.yml as in patch #5. Not the change to use coder 8.3.11 but the change to remove everything below that. Then the tests just run phpcs and do not waste time and effort running phpunit.
Comment #24
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedquietone said
I think we need to:
Only when all three of these are done should we consider anything manual, such as the changes that quietone has highlighted.
Comment #25
Spokje@quitone in #22: Fixed them anyway. Maybe a follow-up to check throughout the whole source (or basically module `jsonapi`:innocent:)
@jonathan1055 in #23
I have no clue how to do both of them. I'll just put it back to Needs Work.
Sorry about the manual changes, I only read your comment after I've done those already.
Comment #26
quietone CreditAttribution: quietone as a volunteer commentedTested locally and the sniff does not care that the sentence following the '@todo' is not in sentence case. If I understand correctly that is what we want? At least that is what I think jonathan1055 is referring to. I am not sure, is a new issue made in coder for that?
Setting to NR for discussion.
Comment #27
Spokje@quietone
As far as I understand @jonathan1055 is sure there's a variant of the sniff out there that automagically makes the sentence after the
@todo
start with Uppercase.The current sniff, like you already discovered doesn't care about CaPiTaLiSaTiOn, which is not preferable.
Comment #28
SpokjeComment #30
SpokjeComment #31
SpokjeBack to "Needs Work", see #24/#27.
Comment #34
adamzimmermann CreditAttribution: adamzimmermann at Chromatic commentedBased upon my comment here, should this be Needs Review again?
It seems that we have addressed the concerns in #24 and #27
Comment #36
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedSo reading your links in https://git.drupalcode.org/project/drupal/-/merge_requests/504#note_116418 it seems we were enforcing a capital letter after the '@todo' but then it was reverted to any non-space character. Lets leave it as-is, and not enforce capitalisation, as there are bound to be examples where the first word is something code-like, such a a lowerCamelCase class and it would just be a pain. Therefore yes I agree with you lets move onwards.
Now that core development has moved on to 10.1.x you might like to start a new MR ad then leave the exitsing one at 9.x in case this gets backported. The first commit on the new MR, in addition to adding the sniff in phpcs.xml.dist, should have two changes in drupalci.yml
(a) to make all files get checked, set sniff-all-files: true
and (b) to save resources and get fast test results by not running any phpunit tests
remove everything below the 'testing' keyword
Comment #38
Nikolay ShapovalovComment #40
Nikolay ShapovalovCreate new MR for 11.x branch. Not sure what should be done with drupalci.yml, I think if we use gitlab, then .gitlab-ci.yml should be used.
Waiting for review.
Comment #41
smustgrave CreditAttribution: smustgrave at Mobomo commentedCan the changes to the drupalci file be reverted.
Comment #42
Nikolay ShapovalovRevert changes to the drupalci.yml file.
Comment #44
smustgrave CreditAttribution: smustgrave at Mobomo commentedSo searching for "todo:" for example I still get some hits.
So I wonder why the rule didn't find them?
Comment #45
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedOpen up the file > and see what they are - they might not be actual todo comments, or rather that the sniff does not think they are.
Comment #46
Nikolay ShapovalovGreat question.
I found 16 results for "todo:" in .js files the core. I believe this is not the part of this issue, because phpcs doesn't support js file.
And I made search for "todo:" in all files except .js
My suggestion, we just ignore some of the file types or locations on phpcs.
Comment #47
smustgrave CreditAttribution: smustgrave at Mobomo commentedSome of the findings in the screenshot aren't in .js file though.
Opened the folders to help, should of done that in first screenshot.
Comment #48
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedThanks for the details. Of the six ocurrences you are showing, 2 are .yml 1 is .twig and 1 is .js and the phpcs sniff does not cover those file types.
The last 2 are .php but the text 'todo' is in the middle of a comment. The sniff currently only detects and works on 'todo' when it is at the start of a comment (eiher // or *, with or without the @ tag). But a 'todo' word in the middle of a line, ie following some other words, is not treated as being wrong and needing to be re-formatted for standards.
Here is the todo sniff in Coder. I recall that we commented it quite well :-)
I suppose there could be a case for changing the Coding Standards to try to include and detect a real todo in the middle of a string. Maybe raise that for discussion in the coding standards meeting?
Comment #49
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedNow looking through the examples found by @zniki.ru in #46, there are two which are .php files with the 'todo' at the start of the comment.
Those should be found and fixed by the sniff.
Comment #50
Nikolay Shapovalov@jonathan1055
These files is already fixed in the MR.
Maybe I forgot to switch to correct git branch.
I used grep to search for "todo:" and exclude some filetypes:
I was not able to find anything.
Comment #51
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedThanks @zniki.ru that is good to hear. So I think this is back to 'needs review' now.
Comment #52
Nikolay ShapovalovDo we want to fix these violations we manually found in yml, twig, js files?
Comment #53
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedYou can do if you want to. But without any sniff/rule to enforce it, there would be nothing to prevent a new occurence being introduced later. It's up to you.
Also, with your grep, I suggest to add
-i
to the options to make it case-insensitive.Comment #54
smustgrave CreditAttribution: smustgrave at Mobomo commentedRechecked the MR and the .php files from my screenshot are still there.
Should there be a follow up for getting the other file types?
Comment #55
quietone CreditAttribution: quietone at PreviousNext commentedLet's get this back on track.
1) An issue can be made in the Coding standards project to discuss 1) changing the sniff so that the sentence following the '@todo' is capitalized or not and 2) enforcing the rule for non-php files.
2) An issue can be made in Views to decide what to do with the 'todo' statements in those files. They will take more research they are from '09 and '12. They are a special case and should not hold up this issue.
That will allow this enhancement to be added to core.
This also needs a 10.3.x MR.
Comment #56
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #57
quietone CreditAttribution: quietone at PreviousNext commented