Fix coding standards

Created on 20 April 2024, 7 months ago
Updated 4 August 2024, 4 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

RTBC

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 β†’ (Closed) created by ptmkenny
  • Status changed to Needs review 7 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 7 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.

  • πŸ‡ΊπŸ‡ΈUnited States xpersonas

    Thanks guys. I updated the tests a bit and took these coding standards into account. If you don't mind trying the new dev release to see if you have issues, that would be great. Right now everything is passing in phpcs for me.

  • Status changed to Needs review 4 months ago
  • πŸ‡ΊπŸ‡ΈUnited States xpersonas
  • Status changed to RTBC 4 months ago
  • πŸ‡―πŸ‡΅Japan ptmkenny

    They are passing in CI, so that's good enough for me.

    GitLab CI does a phpcs that is slightly different than the default one (it ignores phpstan errors to avoid duplicating work found in the phpstan scan). But since all tests are passing, it doesn't matter in this case.

Production build 0.71.5 2024