Coding Standard issues

Created on 16 October 2024, about 1 month ago

Problem/Motivation

phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,info,txt,md,yml .

FILE: .../web/modules/custom/ultimenu/src/UltimenuTool.php
----------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------------------------------------------------------
14 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\block\BlockInterface.
----------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------------------------

FILE: .../web/modules/custom/ultimenu/ultimenu.info.yml
-----------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------
1 | WARNING | Remove "version" from the info file, it will be added by drupal.org packaging automatically
-----------------------------------------------------------------------------------------------------------

Steps to reproduce

phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,info,txt,md,yml .

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

Active

Version

3.0

Component

Code

Created by

🇵🇪Peru alyaj2a

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

Merge Requests

Comments & Activities

  • Issue created by @alyaj2a
  • Merge request !4Coding standard issues - #3481328 → (Open) created by alyaj2a
  • Pipeline finished with Success
    about 1 month ago
    Total: 137s
    #311991
  • 🇮🇩Indonesia gausarts

    Most of the CS issues were outdated.

    Solutions:

    • Update you PHPCS. Do not use global PHPCS, use per project instances. The call it in the Drupal root:
      ./vendor/bin/phpcs \
        --standard="Drupal,DrupalPractice" -n \
        --extensions="php,module,inc,install,test,profile,theme" \
        web/modules/d10/ultimenu
        
      ./vendor/bin/phpcbf \
        --standard="Drupal,DrupalPractice" -n \
        --extensions="php,module,inc,install,test,profile,theme" \
        web/modules/d10/ultimenu
    • For CSS, use Stylelint. CSSLint was deprecated for stylelint. Call it:
      Checking for errors:
      npx stylelint "web/modules/d10/ultimenu/css/*.css"
      npx stylelint "web/modules/d10/ultimenu/css/**/*.css"

      Fixing the errors:

      npx stylelint --fix "web/modules/d10/ultimenu/css/*.css"
      npx stylelint --fix "web/modules/d10/ultimenu/css/**/*.css"
    • For JS, use ESLint.
        // Located at /modules/contrib/ultimenu, run:
        // eslint . -o ../../eslint/ultimenu.html -f html

      See here:
      https://git.drupalcode.org/project/ultimenu/-/blob/3.0.x/.eslintrc.json?...

    A good conflicting sample between old and new CS is this line:

    FILE: .../web/modules/custom/ultimenu/src/UltimenuTool.php
    ----------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ----------------------------------------------------------------------------------------------------------------------
    14 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\block\BlockInterface.

    The latest CS was actually the opposite of yours, and already committed here:
    https://git.drupalcode.org/project/ultimenu/-/commit/f23a1323ff51badcf81...

    It may confuse you since they are NOT sorted alphabetically. But it should make sense to put classes in core/lib directory at first rows, then core/modules, etc. It was the latest CS change.

    Please refer to Drupal CR and docs for more updated info and details.

    Thank you anyway.

Production build 0.71.5 2024