Problem/Motivation

Getting the following phpcs errors/warnings:

FILE: tests/src/Functional/ColorFieldFormatterTest.php
-----------------------------------------------
FOUND 0 ERRORS AND 8 WARNINGS AFFECTING 8 LINES
------------------------------------------------
  49 | WARNING | t() calls should be avoided in classes, use
     |         | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
  69 | WARNING | t() calls should be avoided in classes, use
     |         | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
  88 | WARNING | t() calls should be avoided in classes, use
     |         | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 107 | WARNING | t() calls should be avoided in classes, use
     |         | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 136 | WARNING | t() calls should be avoided in classes, use
     |         | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 156 | WARNING | t() calls should be avoided in classes, use
     |         | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 186 | WARNING | t() calls should be avoided in classes, use
     |         | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 208 | WARNING | t() calls should be avoided in classes, use
     |         | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
------------------------------------------------


FILE: tests/src/Functional/ColorFieldWidgetTest.php
------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
------------------------------------------------
 43 | WARNING | t() calls should be avoided in classes, use
    |         | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
------------------------------------------------


FILE: tests/src/Functional/ColorFieldFormatterTokenTest.php
------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
------------------------------------------------
 55 | WARNING | t() calls should be avoided in classes, use
    |         | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 94 | WARNING | t() calls should be avoided in classes, use
    |         | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
------------------------------------------------


FILE: src/Plugin/Field/FieldFormatter/ColorFieldFormatterCss.php
------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
------------------------------------------------
 155 | WARNING | t() calls should be avoided in classes, use
     |         | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 162 | WARNING | t() calls should be avoided in classes, use
     |         | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
------------------------------------------------

Steps to reproduce

Run the following command from the module folder:
phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml .

Proposed resolution

Fix the errors and warnings.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mrinalini9 created an issue. See original summary.

mrinalini9’s picture

Assigned: mrinalini9 » Unassigned
Status: Active » Needs review
StatusFileSize
new7.04 KB

Added patch for the above fixes here, please review it.

arisen’s picture

Status: Needs review » Needs work
StatusFileSize
new291.15 KB

Reviewed the patch on 3.0.x branch. The patch is applying cleanly but getting additional code standards error.

FILE: ...color_field/src/Plugin/Field/FieldFormatter/ColorFieldFormatterCss.php
----------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------------------------------------------
 70 | ERROR | Unknown type hint "mixed" found for $plugin_definition
----------------------------------------------------------------------------------------------------------

Time: 921ms; Memory: 12MB
adil_siddiqui’s picture

Status: Needs work » Needs review
StatusFileSize
new8.03 KB

Patch created with all above issue fixed

avpaderno’s picture

Title: Drupal Coding Standards Issues | phpcs » Fix the issues reported by phpcs
Category: Bug report » Task

urvashi_vora made their first commit to this issue’s fork.

urvashi_vora’s picture

Assigned: Unassigned » urvashi_vora
Status: Needs review » Needs work

Reviewed and Tested Patch 3338149-4.patch.

The patch applied smoothly

urvasi@urvasi-Inspiron-15-3552:/var/www/html/contribution/drupal/web/modules/contrib/color_field-3338149$ git apply -v 3338149-4.patch
Checking patch src/ColorHex.php...
Checking patch src/Plugin/Field/FieldFormatter/ColorFieldFormatterCss.php...
Checking patch tests/src/Functional/ColorFieldFormatterTest.php...
Checking patch tests/src/Functional/ColorFieldFormatterTokenTest.php...
Checking patch tests/src/Functional/ColorFieldWidgetTest.php...
Applied patch src/ColorHex.php cleanly.
Applied patch src/Plugin/Field/FieldFormatter/ColorFieldFormatterCss.php cleanly.
Applied patch tests/src/Functional/ColorFieldFormatterTest.php cleanly.
Applied patch tests/src/Functional/ColorFieldFormatterTokenTest.php cleanly.
Applied patch tests/src/Functional/ColorFieldWidgetTest.php cleanly.

Still there are a few issues left, which can fixed by phpcbf, I will fix them and create a MR.

urvasi@urvasi-Inspiron-15-3552:/var/www/html/contribution/drupal/web/modules/contrib$ phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,js,info,txt,md,yml,twig color_field-3338149/

FILE: ...dules/contrib/color_field-3338149/js/color_field_widget_spectrum.jquery.js
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
 29 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "TRUE" but
    |       |     found "true"
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------


FILE: ...upal8/web/modules/contrib/color_field-3338149/js/color_field_widget_box.js
--------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
--------------------------------------------------------------------------------
 21 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "TRUE" but
    |       |     found "true"
 23 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "NULL" but
    |       |     found "null"
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

Time: 2.46 secs; Memory: 12MB
urvashi_vora’s picture

Assigned: urvashi_vora » Unassigned
Status: Needs work » Needs review

Fixed all the issue, Please review.

urvasi@urvasi-Inspiron-15-3552:/var/www/html/contribution/drupal/web/modules/contrib$ phpcbf --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,js,info,txt,md,yml,twig color_field-3338149/

PHPCBF RESULT SUMMARY
--------------------------------------------------------------------------------
FILE                                                            FIXED  REMAINING
--------------------------------------------------------------------------------
...olor_field-3338149/js/color_field_widget_spectrum.jquery.js  1      0
...es/contrib/color_field-3338149/js/color_field_widget_box.js  2      0
--------------------------------------------------------------------------------
A TOTAL OF 3 ERRORS WERE FIXED IN 2 FILES
--------------------------------------------------------------------------------

Time: 2.55 secs; Memory: 12MB

paraderojether’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new279.9 KB
new109.12 KB

I reviewed MR!13, and applied it against Color Field 3.0.x-dev cleanly and confirmed it fixes all the issues reported by phpcs.

I added screenshots for reference.
Thank You.

avpaderno’s picture

Priority: Normal » Minor
Status: Reviewed & tested by the community » Needs work

Yashaswi18 made their first commit to this issue’s fork.

zkhan.aamir’s picture

Issue tags: +Coding standards
avpaderno’s picture

The MR is still using NULL and TRUE in JavaScript files, while they are used in PHP code. In JavaScript, it is correct to use null and true.

sakthi_dev made their first commit to this issue’s fork.

sakthi_dev’s picture

Status: Needs work » Needs review

Updated to lower case in JS.

avpaderno’s picture

Status: Needs review » Needs work
sakthi_dev’s picture

Status: Needs work » Needs review

Addressed comments in MR. Please review.

nikolay shapovalov’s picture

Issue summary: View changes

Update IS, add new phpcs report.

nikolay shapovalov’s picture

Status: Needs review » Needs work

Please remove changes that is not necessary, and not marked as violation by phpcs report.

nikolay shapovalov’s picture

Arijit Acharya made their first commit to this issue’s fork.

arijit acharya’s picture

Added a MR which resolves the errors thrown by phpcs.
Please review and merge.

arijit acharya’s picture

Status: Needs work » Needs review
silvi.addweb’s picture

Status: Needs review » Reviewed & tested by the community

Hi, I have tested MR 22. There are no remaining issues. Moving to RTBC.

addweb@addweb-HP-ZBook-15-G2:~$ .config/composer/vendor/squizlabs/php_codesniffer/bin/phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,info,txt,md,yml,css Drupal8-vagrant/web/web/contribution/drupal-10-3/web/modules/custom/color_field/
addweb@addweb-HP-ZBook-15-G2:~$ 

apaderno changed the visibility of the branch 3338149-fix-the-issues to hidden.

apaderno changed the visibility of the branch 3.0.x to hidden.

avpaderno’s picture

Status: Reviewed & tested by the community » Closed (outdated)