Problem/Motivation

While reviewing #2805449: Comment out 'extension_discovery_scan_tests' in example.settings.local.php I found that example.settings.php has a code style violation in:

assert_options(ASSERT_ACTIVE, TRUE);
\Drupal\Component\Assertion\Handle::register();

The class reference should use a "use" statement.

Proposed resolution

Ignore coding standards in sites/* PHP files as these files are not really for code but are used to configure your drupal install.

Remaining tasks

Do it.

User interface changes

N/A.

API changes

N/A.

Data model changes

N/A.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Gábor Hojtsy created an issue. See original summary.

alexpott’s picture

There's a wider issue of applying coding standards declared in ./core to things outside of ./core such as this file. https://github.com/alexpott/d8githooks will blindly test any PHP file against the coding standards ignoring its location. We have 3 PHP files outside of ./core to think about:

  • sites/default/default.settings.php
  • sites/example.settings.local.php
  • sites/example.sites.php

And currently we have the following violations:

 8.5.x  alex: ~/dev/drupal/core > phpcs ../sites/

FILE: /Volumes/devdisk/dev/drupal/sites/default/default.settings.php
----------------------------------------------------------------------
FOUND 7 ERRORS AFFECTING 7 LINES
----------------------------------------------------------------------
 476 | ERROR | [x] Line indented incorrectly; expected 0 spaces,
     |       |     found 2
 477 | ERROR | [x] Line indented incorrectly; expected 0 spaces,
     |       |     found 2
 478 | ERROR | [x] Line indented incorrectly; expected 0 spaces,
     |       |     found 2
 479 | ERROR | [x] Line indented incorrectly; expected 0 spaces,
     |       |     found 2
 480 | ERROR | [x] Line indented incorrectly; expected 0 spaces,
     |       |     found 2
 481 | ERROR | [x] Line indented incorrectly; expected 0 spaces,
     |       |     found 2
 483 | ERROR | [x] Line indented incorrectly; expected 1 spaces,
     |       |     found 0
----------------------------------------------------------------------
PHPCBF CAN FIX THE 7 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: /Volumes/devdisk/dev/drupal/sites/example.settings.local.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 34 | ERROR | [x] Namespaced classes/interfaces/traits should be
    |       |     referenced with use statements
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Time: 121ms; Memory: 6Mb

We could decide that the nature of these files means that we should just add

// @codingStandardsIgnoreFile

At the top. As nothing is actually wrong. Our coding standards are not really for code include in the main execution of the file like

assert_options(ASSERT_ACTIVE, TRUE);
\Drupal\Component\Assertion\Handle::register();
alexpott’s picture

My vote is just to add

// @codingStandardsIgnoreFile

And be done.

borisson_’s picture

Status: Active » Needs review
FileSize
953 bytes

I agree with @alexpott that we should just ignore coding standards.

Attached is patch that does that.

borisson_’s picture

Oh, I didn't see that this was Novice when I started working on it. Sorry for stealing this issue.

dev.patrick’s picture

Status: Needs review » Reviewed & tested by the community

@borisson_ patch is applied cleanly. Considering suggestion by @alexpott, its worth that we can ignore coding standard here. Moving to RTBC, open for more suggestion and if need to move to N/W N/R.

alexpott’s picture

Title: example.settings.php refers to assertion handling component directly rather than using a use statement » Ignore coding standards in sites/* PHP files as they are for configuration and not real code
alexpott’s picture

Issue summary: View changes

  • xjm committed fdce9b7 on 8.5.x
    Issue #2915673 by borisson_, alexpott, Gábor Hojtsy: Ignore coding...

  • xjm committed 1e4d1e6 on 8.4.x
    Issue #2915673 by borisson_, alexpott, Gábor Hojtsy: Ignore coding...

  • xjm committed ccc6b83 on 8.4.x
    \Revert "Issue #2915673 by borisson_, alexpott, Gábor Hojtsy: Ignore...
xjm’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 8.5.x. Thanks! I originally also backported it to 8.4.x, but on second thought I came to the conclusion that it wasn't worth the settings.php changes for the production branch (since even a comment-only change to those could trigger production sites to redo their settings.php.)

Status: Fixed » Closed (fixed)

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