Problem/Motivation
In Coder 8.3.6, which is the version used by core 8.8, the @ doc tag sniff checked that groups of matching tags were separated by a blank comment line. In coder version 8.3.9 (which is used by core 8.9) the checking is still done for some cases but is weakened. This has the effect that if you are developing new code at 8.9 and all phpcs checks pass, then you upload to test at multiple version, e.g to drupal.org or Travis, the coding standards can fail at core 8.8. This seems counter-intuitive, because in most cases the rules get stricter as versions increase, or there is a good reason why rules are relaxed.
Steps to reproduce
Test this snippet using Coder 8.3.9. It will pass:
* @param string $message
* The message text.
* @param array $context
* Context variables for substitution.
* @todo Some task (this is line 200).
However, using Coder 8.3.6 we get the warning:
200 | ERROR | [x] Separate the @param and @todo sections by a blank line.
| | (Drupal.Commenting.DocComment.TagGroupSpacing)
Proposed resolution
Remaining tasks
Determine if this regression was intentional. If not, then fix it, and introduce tests to ensure no future regression.
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|
Comments
Comment #2
jonathan1055 commentedI will investigate what the changes were between 8.3.6 and 8.3.9, then we can decide how to proceed.
Comment #3
jonathan1055 commentedThe commit which has the changes is https://git.drupalcode.org/project/coder/commit/c8664df from issue #2947589: TagGroupSpacing coding space fix doesn't work as it should (committed between 8.3.6 and 8.3.7)
The change in question is in coder_sniffer/Drupal/Sniffs/Commenting/DocCommentSniff.php where there is switch from a 'negative' ignored set of tags
to a 'positive' list of checked tags
However, the subsequent code change is subtly different. Before we had
which has been replaced with
The key difference is that previously the check was done if either $currentTag or $previousTag were in the list, but now it is only done if both $currentTag and $previousTag are in the list. Hence, as one of the tags in my example is
@todothis is why the check was allowed to pass in the later version but failed in the earlier version. Is this the intended behaviour of the change?If so, then we could add @todo into the list of $checkTags (1)
Or (2) if the intention is to make sure that the $checkTags list are always separated from other tags, then the logic can be changed back to what we had before:
I think that the list of $checkTags are the ones that specifically need to be in a separate group with spaces either side, regardless of what the 'other' adjacent tag is. So the correct solution would be (2)
Comment #4
jonathan1055 commentedThe test input file DocCommentUnitTest.inc has
and the fixed file DocCommentUnitTest.inc.fixed has
Note that @ingroup is present in the new $checkTags array, but it is allowed to be adjacent to the @deprecated tag. This shows that we have an inconsistency between the intention of the check and the result. If @ingroup should be separated by spaces either side then we need to allow for any tag to be the adjacent one, hence we should use the OR test I propose restoring #3 option 2, and also adjust the fixed results file.
Or if @ingroup does not need to be separated by blank lines either side, it should be removed from the $checkTags array, and then the test would fail, because we would get a fixed version looking like:
and the @throws would not be reported when it should be. So either way, I think the OR logic should be restored. It was probably an accident that the || got replaced by && and it was not noticed that the fixed file does not agree with the intention of the sniff.
I will raise a PR with the proposed logic fix, for review and discussion on GitHub
Comment #5
arkener commentedInteresting issue, thank you for looking into this. Looking at
DocCommentSniffand #2947589: TagGroupSpacing coding space fix doesn't work as it should, it seems like||has been replaced with&&to fix an issue where nested tags would be flagged to be separated by a new line, for example.We'll most likely run into the same issue when adding the
@todotag to the$checkTagslist. This would result in warning when adding a todo to other tags, for example:We should probably determine if the tag is part of a comment of another tag and if this is the case, ignore it. This would also us to revert the
&&change and we would be able to add@seeand some other tags from https://www.drupal.org/docs/develop/standards/api-documentation-and-comm... to the$checkTagslist.Comment #6
jonathan1055 commentedThanks @Arkener.
That is exactly what I had just deduced from looking at my local Coder PHPunit test failures when running the tests with the change to use
||.We could ensure that the tag column number matches the column of the $currentTag being tested. So this would ignore any @ tag within the comment. I will work on this fix if you think this is a reasonable solution.
Comment #7
arkener commentedYes, this sound like a good plan.
Comment #8
jonathan1055 commentedUsefully, we already have
$tokens[$firstTag]defined from earlier. So it is nice and easy to add:This fixes the problem and allows the desired change to use
||instead of&&.However, later in the sniff, where
SpacingAfterTagGroupis being checked, we have the same problem. Now that there is accurate tag data in the$tagGroupsarray (previously it erroneously included all the inline code tags too) the$lastTagis correct, but we now detect a later inline @tag and get a complaint that the group does not have a blank line after it. Therefore this section also requires the 'column' check as above, so that only proper doc @tags are found and checked.Comment #9
jonathan1055 commentedCreated PR 128 https://github.com/pfrenssen/coder/pull/128
Comment #10
jonathan1055 commentedComment #11
jonathan1055 commentedThe tests pass now. All ready for review.
Comment #13
arkener commentedMerged, thanks!
Comment #14
jonathan1055 commentedTo fix this in core I have raised #3183656: Fix 'Drupal.Commenting.DocComment.TagGroupSpacing' coding standard [part 2]
Would you like me to add new test cases for Coder to highlight the existing behavior (in Coder 8.3.7 to 8.3.11) and show that this is now fixed (in what will become 8.3.12)?
Comment #15
jonathan1055 commentedI did not find a way to use the Coder dev version in drupal.org testing - see my comments #21 to #29 here and #3 here. So this patch is added solely for use in the core issue.
Comment #16
jonathan1055 commentedUnassigning