Fix coding standards

Created on 20 April 2024, 2 months ago
Updated 9 May 2024, about 2 months ago

Problem/Motivation

The GitLab CI template adds a coding standards test, which identifies the following issues:

FILE: ...b/modules/custom/simple_styleguide-3442149/src/Form/StyleguideSettings.php
--------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
--------------------------------------------------------------------------------
 7 | WARNING | [x] Unused use statement
   |         |     (Drupal.Classes.UnusedUseStatement.UnusedUse)
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------
FILE: ...ules/custom/simple_styleguide-3442149/src/Controller/DefaultController.php
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
 8 | ERROR | [x] Use statements should be sorted alphabetically. The first
   |       |     wrong one is Drupal\Core\Form\FormBuilderInterface.
   |       |     (SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses.IncorrectlyOrderedUses)
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------
Time: 176ms; Memory: 6MB
PHP CODE SNIFFER REPORT SUMMARY
--------------------------------------------------------------------------------
FILE                                                            ERRORS  WARNINGS
--------------------------------------------------------------------------------
...ple_styleguide-3442149/src/Controller/DefaultController.php  1       0
...m/simple_styleguide-3442149/src/Form/StyleguideSettings.php  0       1
--------------------------------------------------------------------------------
A TOTAL OF 1 ERROR AND 1 WARNING WERE FOUND IN 12 FILES
--------------------------------------------------------------------------------
PHPCBF CAN FIX 2 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------
PHP CODE SNIFFER VIOLATION SOURCE SUMMARY
--------------------------------------------------------------------------------
    SOURCE                                                                 COUNT
--------------------------------------------------------------------------------
[x] Drupal.Classes.UnusedUseStatement.UnusedUse                            1
[x] SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses.Incorrectl  1
--------------------------------------------------------------------------------
A TOTAL OF 2 SNIFF VIOLATIONS WERE FOUND IN 2 SOURCES
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SOURCES AUTOMATICALLY (2 VIOLATIONS IN TOTAL)
--------------------------------------------------------------------------------

Let's fix these.

πŸ“Œ Task
Status

Needs work

Version

2.0

Component

Code

Created by

πŸ‡―πŸ‡΅Japan ptmkenny

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

Merge Requests

Comments & Activities

  • Issue created by @ptmkenny
  • Merge request !6Coding standards β†’ (Open) created by ptmkenny
  • Status changed to Needs review 2 months ago
  • πŸ‡΅πŸ‡­Philippines clarkssquared

    Hi

    I applied the MR !6 and it says in my terminal composer.json file not found

    ➜  simple_styleguide git:(2.0.x) curl https://git.drupalcode.org/project/simple_styleguide/-/merge_requests/6.diff | git apply -v
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  1619    0  1619    0     0   3150      0 --:--:-- --:--:-- --:--:--  3199
    Checking patch composer.json...
    error: composer.json: No such file or directory
    Checking patch src/Controller/DefaultController.php...
    Checking patch src/Form/StyleguideSettings.php...
    ➜  simple_styleguide git:(2.0.x) 
  • πŸ‡―πŸ‡΅Japan ptmkenny

    @clarkssquared Whoops, the merge targeted the wrong branch. Fixed, thank you.

  • Status changed to Needs work about 2 months ago
  • πŸ‡΅πŸ‡­Philippines paraderojether

    Hi

    I reviewed MR!6, applied against Simple Style Guide 2.0x-dev, confirmed patch applied cleanly however there are still remaining phpcs issue shown below:

    jetherparadero@PrometSources-MacBook-Pro-3 contrib % phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig simple_styleguide
    
    FILE: /Users/jetherparadero/d_o/drupal-issues/web/modules/contrib/simple_styleguide/src/Tests/StyleguidePageTest.php
    ---------------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
    ---------------------------------------------------------------------------------------------------------------------------------------------------
     20 | ERROR   | Do not disable strict config schema checking in tests. Instead ensure your module properly declares its schema for configurations.
     70 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
    ---------------------------------------------------------------------------------------------------------------------------------------------------
    
    Time: 215ms; Memory: 10MB
    
    jetherparadero@PrometSources-MacBook-Pro-3 contrib %

    Please check and advise.
    Thank you.

  • πŸ‡―πŸ‡΅Japan ptmkenny

    @paraderojether As stated in the issue summary, I fixed the coding standards issues pointed out by the GitLab CI template: https://git.drupalcode.org/issue/simple_styleguide-3442149/-/jobs/1379375. I wonder why you are getting different results than the CI scan.

Production build 0.69.0 2024