Drupal Coding Standards Issues | phpcs, phpstan, cspell

Created on 31 January 2023, over 1 year ago
Updated 7 May 2024, about 2 months ago

Problem/Motivation

Getting Following errors/warnings

$ phpcs --standard=Drupal username_validation

FILE: ...min\Desktop\task\username_validation\src\Form\UserNameValidationConfig.php
--------------------------------------------------------------------------------
FOUND 7 ERRORS AND 1 WARNING AFFECTING 8 LINES
--------------------------------------------------------------------------------
   1 | ERROR   | [x] End of line character is invalid; expected "\n" but found
     |         |     "\r\n"
  12 | WARNING | [ ] The class short comment should describe what the class
     |         |     does and not simply repeat the class name
  73 | ERROR   | [x] Use null coalesce operator instead of ternary operator.
  83 | ERROR   | [x] Use null coalesce operator instead of ternary operator.
  90 | ERROR   | [x] Use null coalesce operator instead of ternary operator.
  97 | ERROR   | [x] Use null coalesce operator instead of ternary operator.
 106 | ERROR   | [x] Use null coalesce operator instead of ternary operator.
 115 | ERROR   | [x] Use null coalesce operator instead of ternary operator.
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 7 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

Time: 458ms; Memory: 8MB

Proposed resolution

Fix the errors and warnings.

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇮🇳India Jay Jangid

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @Jay Jangid
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • 🇮🇳India Jay Jangid

    Created MR , please review.

    Thank you.

  • Status changed to Needs work 5 months ago
  • 🇮🇳India realsp

    Found following phpcs issues in MR #2,

    FILE: /home/contribution/drupal/web/modules/contrib/username_validation/username_validation.routing.yml
    -----------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    -----------------------------------------------------------------------------------------------------------------
     10 | ERROR | [x] Expected 1 newline at end of file; 2 found
    -----------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    -----------------------------------------------------------------------------------------------------------------
    
    
    FILE: /home/contribution/drupal/web/modules/contrib/username_validation/username_validation.links.menu.yml
    --------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    --------------------------------------------------------------------------------------------------------------------
     7 | ERROR | [x] Expected 1 newline at end of file; 0 found
    --------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /home/contribution/drupal/web/modules/contrib/username_validation/username_validation.module
    ------------------------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 11 ERRORS AND 4 WARNINGS AFFECTING 15 LINES
    ------------------------------------------------------------------------------------------------------------------------------------------------------------
       1 | ERROR   | [x] Missing file doc comment
       9 | WARNING | [ ] Format should be "* Implements hook_foo().", "* Implements hook_foo_BAR_ID_bar() for xyz_bar().",, "* Implements hook_foo_BAR_ID_bar()
         |         |     for xyz-bar.html.twig.", "* Implements hook_foo_BAR_ID_bar() for xyz-bar.tpl.php.", or "* Implements hook_foo_BAR_ID_bar() for block
         |         |     templates."
      23 | WARNING | [ ] Format should be "* Implements hook_foo().", "* Implements hook_foo_BAR_ID_bar() for xyz_bar().",, "* Implements hook_foo_BAR_ID_bar()
         |         |     for xyz-bar.html.twig.", "* Implements hook_foo_BAR_ID_bar() for xyz-bar.tpl.php.", or "* Implements hook_foo_BAR_ID_bar() for block
         |         |     templates."
      30 | ERROR   | [x] Use null coalesce operator instead of ternary operator.
      55 | ERROR   | [ ] All functions defined in a module file must be prefixed with the module's name, found "_get_username_from_db" but expected
         |         |     "username_validation__get_username_from_db"
      69 | ERROR   | [ ] Missing parameter comment
      70 | ERROR   | [ ] Missing parameter comment
      72 | ERROR   | [ ] Description for the @return value is missing
      82 | ERROR   | [x] Use null coalesce operator instead of ternary operator.
     114 | ERROR   | [x] Expected one space after the comma, 0 found
     122 | ERROR   | [ ] Missing short description in doc comment
     153 | ERROR   | [x] Expected one space after the comma, 0 found
     156 | ERROR   | [x] Whitespace found at end of line
     158 | WARNING | [ ] Only string literals should be passed to t() where possible
     161 | WARNING | [ ] Only string literals should be passed to t() where possible
    ------------------------------------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 6 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    
  • Assigned to realsp
  • Issue was unassigned.
  • Status changed to Needs review 5 months ago
  • 🇮🇳India realsp

    I've fixed the remaining phpcs issues in the MR, Please review the MR.
    Thank you.

  • First commit to issue fork.
  • Status changed to Needs work 2 months ago
  • First commit to issue fork.
  • Status changed to Needs review 2 months ago
  • 🇩🇪Germany Grevil

    Alright, this issue can be reviewed. There are a few dangerous, but necessary changes here, we need to manually test them first, before merging.

    The eslint issue needs to be fixed in a separate issue, they are related to the empty config file (which shouldn't be empty of course), but not related to this issue. I will quickly fix the remaining cspell issues tomorrow and do some quick manually tests for the form_state "getValues()" changes and then we can commit this. Codewise, this can already get reviewed!

    I'd say this will be the last commit for 1.x any further work for refactoring, etc. should be done in 2.x. (Note that we also need to cherry-pick this into 2.x once finished).

  • 🇩🇪Germany Grevil

    Alright, all fixed and working as expected, please review!

  • 🇩🇪Germany Anybody Porta Westfalica

    LGTM, thx!

  • Status changed to RTBC 2 months ago
  • 🇩🇪Germany Anybody Porta Westfalica
  • 🇩🇪Germany Grevil

    Thanks all, fixed!

  • Status changed to Fixed 2 months ago
  • 🇦🇺Australia VladimirAus Brisbane, Australia
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024