Problem/Motivation
The standard format of @todo statements is agreed. But the documentation pages need updating.
Three supporters required
- https://www.drupal.org/u/jonathan1055 (18 Nov 2023)
- https://www.drupal.org/u/{userid} (date added)
- https://www.drupal.org/u/{userid} (date added)
Proposed changes
1. DocBlock @todo tag api-documentation-and-comment-standards#todo
Current text
The current text is OK, but needs more detail.
Proposed text
Add the following after the first paragraph.
The @todo tag should be in lower case followed by a single space then the text. There should be no : or - between the 'todo' and the following text. Lines may be indented below the @todo
2. Inline @todo comment api-documentation-and-comment-standards#inline
This currently says
@todo statements in inline comments follow the same rules as using the @todo tag in docblocks.
followed by an example. Is this OK as-is? It is good that the rules should only be stated in one place. But for inline comments do we need to say that the @todo must start a new line, not be in the middle of a comment?
Remaining tasks
Create this issue in the Coding Standards queue, using the defined template- List three supporters
- Create a Change Record
- Review by the Coding Standards Committee
- Coding Standards Committee takes action as required
- Tagged with 'Needs documentation edits' if Core is not affected
- Discussed by the Core Committer Committee, if it impacts Drupal Core
- Documentation updates
- Edit all pages
- Publish change record
- Remove 'Needs documentation edits' tag
- If applicable, create follow-up issues for PHPCS rules/sniffs changes
For a fuller explanation of these steps see the Coding Standards project page
Original issue
While working on #2719649: Fix 'Drupal.Commenting.InlineComment.SpacingBefore' coding standard, it became apparent that the InlineComment sniff in coder allows TODO paragraphs to be indented if and only if they start with the exact string "@todo ".
Valid example:
// @todo Lorem ipsum dolor
// sit amet.
Invalid examples:
// @todo: Lorem ipsum dolor
// sit amet.
// @TODO Lorem ipsum dolor
// sit amet.
// @fixme Lorem ipsum dolor
// sit amet.
These are rejected because "@todo:", "@TODO" and "@fixme" are not recognized as strings that can start an indented paragraph (see https://git.drupalcode.org/project/coder/-/blob/8.x-3.x/coder_sniffer/Dr...), therefore the second line is considered to be improperly indented. This only affects multi-line @todo comments.
An argument might be made that the rule is too strict and other indented paragraphs should be allowed (some other comments start indented paragraphs with "@see" or even just "Note:"), but what is clear is that core currently mixes several different styles for writing "@todo" comments, and we might want a common style for them. (@todo is only briefly described in the coding standards at https://www.drupal.org/docs/develop/standards/api-documentation-and-comm..., and the style is currently only implicit in the code example).
Comments
Comment #2
klausiCoding standard changes are done in the "Coding Standards" project.
Can you make a concrete proposal in the issue summary what we should write into the Coding Standards?
Comment #3
adamzimmermann commentedI created a code sniffer to do this after sharing many of the sentiments expressed in the issue description. I was going to add it to our internal code checking tool, but figured it would be best to include it here and then found this issue.
re: https://www.drupal.org/docs/develop/standards/api-documentation-and-comm...
PR where I created/tested it:
Completed Sniff:
I'm happy to submit a patch or whatever works best. I don't see the standard patch upload field here though, so if someone can point me in the right direction that would be appreciated!
Comment #4
adamzimmermann commentedSeems like I should submit a patch here: https://www.drupal.org/project/coder/issues/2222435
Comment #5
jonathan1055 commentedNow that #2222435: Add a sniff to ensure @todo comments follow the coding standards is done (nice work adamzimmermann) do we need to go the 9 steps process outlined on the project front page?
Comment #6
jonathan1055 commentedThis is being addressed in core on #3180696: Fix 'Drupal.Commenting.TodoComment' coding standard so maybe the standard has been adopted fully already?
Comment #7
tr commentedThis "common style" has been part of the Drupal coding standards for years. I participated in issues more than three years ago to fix this in several different contributed modules. Contributed modules have always been informed by DrupalCI when this "common style" is violated. But Drupal core deliberately ignores a many of coding standards imposed on contrib so this hasn't been fixed in core yet.
As stated in #6, the issue to make core follow this coding standard is #3180696: Fix 'Drupal.Commenting.TodoComment' coding standard.
Comment #8
jonathan1055 commentedNow that there is renewed effort on #3180696: Fix 'Drupal.Commenting.TodoComment' coding standard it would be good to get the Coding Standards pages updated to show the expected format. In #15 a year ago I mentioned the steps to follow, so I am updating the issue summary according to our new template, to track the process.
Comment #9
larowlanI think we should add something like this
Thoughts?
Comment #10
jonathan1055 commentedMaybe. But that could also lead to new empty issues being created that never get any work done to them. Very often the inline
// @todois a reminder to the developer(s) that something needs to be thought about, or it is an early idea, which may never actually happen. If an issue does already exist then the developer writing the @todo might link to it anyway.Happy to hear other views, but I suggest we do not need to mention linking to issues.