Problem/Motivation
The sniff Drupal.Commenting.DocComment.ShortFullStop auto-fixes short comments by adding a period when the line does not end in one. The current coded logic will add a period if the line does not end in . ! ? or ) and is also not {@inheritDoc} and does not match the base filename.
This produces odd fixes which are not correct and require manual fixing. Some examples in Core files:
--- a/core/core.api.php
+++ b/core/core.api.php
/**
- * Prepares a message based on parameters;
+ * Prepares a message based on parameters;.
*
--- a/core/lib/Drupal/Core/Entity/Query/ConditionFundamentals.php
+++ b/core/lib/Drupal/Core/Entity/Query/ConditionFundamentals.php
/**
- * The conjunction of this condition group. The value is one of the following:
+ * The conjunction of this condition group. The value is one of the following:.
*
--- a/core/modules/workspaces/tests/src/Kernel/WorkspaceTestTrait.php
+++ b/core/modules/workspaces/tests/src/Kernel/WorkspaceTestTrait.php
* - dev
* - local_1
* - local_2
- * - qa
+ * - qa.
*/
protected function createWorkspaceHierarchy() {
Novice programmers assume that anything Coder produces will be correct and this had led to lots of review effort being spent in Core issues. It would be better not to attempt the fix when we can determine that the resulting change is not very good and will just require manual intervention. In these cases we should just report the error, and let the developer fix it correctly first time.
See #2572635-4: Fix 'Drupal.Commenting.DocComment.LongFullStop' coding standard comments #4 and #9-11 for examples of the incorrect fixes and unnecessary review time. This sniff can be improved too in the same way.
Proposed resolution
- If the short comment does not end with an alpha-numeric character then do not attempt the fix.
- If the short comment includes a newline do not attempt the fix. The fact that it spans on to more than one line is reported by
ShortSingleLineand will likely require a re-write of the comment text. Then if it does not end in a period this will be checked byLongFullStopanyway.
Remaining tasks
- Determine if the allowed set of ending characters
.!?or)is correct. Are there more to add? Should some be removed? - Code the change to the fixer as and when agreed
- Test on core files to determine the impact
In #3183673: Fix 'Drupal.Commenting.DocComment.ShortFullStop' coding standard - part 1 auto-fixes I am working on fixing the Core files. That issue can be used to show work-in-progress.
| Comment | File | Size | Author |
|---|
Comments
Comment #2
jonathan1055 commentedHere is my first draft of implementing the ideas I suggested in the issue summary. This patch can be used in the core issue to demonstrate the changes.
I will also open a PR and expand the test coverage to cover the changes.
Comment #3
jonathan1055 commentedhttps://github.com/pfrenssen/coder/pull/130
The results of this can bee seen in #2 and #3 on #3183673: Fix 'Drupal.Commenting.DocComment.ShortFullStop' coding standard - part 1 auto-fixes
Comment #4
jonathan1055 commentedThis coder patch has now been used sucessfully to generate the fixes for 211 core warnings, now committed in #3183673-10: Fix 'Drupal.Commenting.DocComment.ShortFullStop' coding standard - part 1 auto-fixes and also being used in the follow-up issue #3185652: Fix 'Drupal.Commenting.DocComment.ShortFullStop' coding standard - part 2
I will work on test coverage if you let me know that this change would be considered for committing. I can then also make the same improvements to the LongFullStop sniff, but won't start that until I have heard back. Thanks.
Comment #5
jonathan1055 commentedForgot to set to 'needs review' for the PR
Comment #6
klausiThanks, approach makes sense and only test cases missing I think.
Comment #7
jonathan1055 commentedThanks. I have updated PR 130 with test case data.
Comment #9
klausiMerged, thanks!
Comment #10
jonathan1055 commentedThanks. Unassigning.
Just wondering what your plans were for the timetable to release 8.3.12? See Longwave's comment #3183656-15: Fix 'Drupal.Commenting.DocComment.TagGroupSpacing' coding standard [part 2] and mine #3187025-10: Update dependencies for Drupal 9.2
Comment #11
klausiI usually do releases every 3 months (latest), but of course we can do them more often if needed. I can make one! Done: https://www.drupal.org/project/coder/releases/8.3.12
Comment #12
jonathan1055 commentedThat's great. Thank you for the mention on the release page. I like your release code names.
@catch has just committed on #3187025-11: Update dependencies for Drupal 9.2 15 hours ago which still had 8.3.11. But it's fine, as he says there will be more updates to 9.2 dependencies before the release of 9.2.0