Part of #2571965: [meta] Fix PHP coding standards in core.

Problem/Motivation

Let's add more coding standards to our phpcs-based quality workflow!

Proposed resolution

  1. Add Drupal Coder to your Drupal codebase
    $ composer require drupal/coder
    $ ./vendor/bin/phpcs --config-set installed_paths /PATH/drupal/vendor/drupal/coder/coder_sniffer/
    
  2. Patch core/phpcs.xml.dist with the desired sniff.
  3. Run phpcs:
    $ cd core
    $ ../vendor/bin/phpcs -p
    
  4. Fix the errors.

To review: Add phpcs to your codebase, apply the patch, and run phpcs. Any errors reported by phpcs mean more work is needed.

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#2 2710081-2.patch2.69 KBalexpott
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Status: Needs work » Needs review
FileSize
2.69 KB
Mile23’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Since you're patching core/phpcs.xml.dist, the instructions are much simpler. Updating issue summary.

The patch looks good.

phpcs only tells me one error which is out of scope here:

FILE: ...ul/pj2/drupal/core/modules/field/src/Tests/FieldUnitTestBase.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 3 | ERROR | [x] Namespaced classes, interfaces and traits should not
   |       |     begin with a file doc comment
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

It would be nice if phpcs told you the sniff that triggered the error.

Anyway, RTBC.

Edit: Add -s to see sniffs in reports.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 3815d7d and pushed to 8.1.x and 8.2.x. Thanks!

  • alexpott committed b264dd2 on 8.2.x
    Issue #2710081 by alexpott: Fix 'Drupal.Formatting.SpaceInlineIf' coding...

  • alexpott committed 3815d7d on 8.1.x
    Issue #2710081 by alexpott: Fix 'Drupal.Formatting.SpaceInlineIf' coding...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.