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 ShortSingleLine and will likely require a re-write of the comment text. Then if it does not end in a period this will be checked by LongFullStop anyway.

Remaining tasks

  1. Determine if the allowed set of ending characters .  !  ? or ) is correct. Are there more to add? Should some be removed?
  2. Code the change to the fixer as and when agreed
  3. 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.

CommentFileSizeAuthor
#2 3184314-2.short-full-stop.patch1.74 KBjonathan1055

Comments

jonathan1055 created an issue. See original summary.

jonathan1055’s picture

StatusFileSize
new1.74 KB

Here 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.

jonathan1055’s picture

This 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.

jonathan1055’s picture

Status: Active » Needs review

Forgot to set to 'needs review' for the PR

klausi’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Thanks, approach makes sense and only test cases missing I think.

jonathan1055’s picture

Title: Improve the auto-fixing for ShortFullStop coding standard » Improve the auto-fixing for DocComment.ShortFullStop coding standard
Issue summary: View changes
Status: Needs work » Needs review

Thanks. I have updated PR 130 with test case data.

  • jonathan1055 authored f429d1b on 8.3.x
    fix(DocComment): Improve fixer for short comments not ending in a full...
klausi’s picture

Status: Needs review » Fixed
Issue tags: -Needs tests

Merged, thanks!

jonathan1055’s picture

Assigned: jonathan1055 » Unassigned

Thanks. 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

klausi’s picture

I 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

jonathan1055’s picture

That'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

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.