Skip to content

3.x: Autoloader failing to load arbitrary files when installed_paths only set via a custom ruleset #1591

Closed
@jrfnl

Description

@jrfnl

Downstream issue: WordPress/WordPress-Coding-Standards#1087

When no installed_paths has been set using --config-set and a custom ruleset is used which:

  1. Sets the installed_paths config for an external standard and
  2. Uses that external standard

arbitrary helper files for the external standard are not autoloaded properly and phpcs exits with a fatal error:

Fatal error: Class 'WordPress\AbstractArrayAssignmentRestrictionsSniff' not found in /path/to/WPCS/WordPress/Sniffs/Arrays/ArrayAssignmentRestrictionsSniff.php on line 30

Call Stack:
    0.0010     348688   1. {main}() path\to\PHP_CodeSniffer\bin\phpcs:0
    0.0060     509360   2. PHP_CodeSniffer\Runner->runPHPCS() path\to\PHP_CodeSniffer\bin\phpcs:18
    0.2260     900480   3. PHP_CodeSniffer\Runner->init() path\to\PHP_CodeSniffer\src\Runner.php:70
    0.2380    1160128   4. PHP_CodeSniffer\Ruleset->__construct() path\to\PHP_CodeSniffer\src\Runner.php:294
    0.9411    1629448   5. PHP_CodeSniffer\Ruleset->registerSniffs() path\to\PHP_CodeSniffer\src\Ruleset.php:215
    0.9411    1629448   6. PHP_CodeSniffer\Autoload::loadFile() path\to\PHP_CodeSniffer\src\Ruleset.php:1103
    0.9421    1642584   7. include('path\to\WPCS\WordPress\Sniffs\Arrays\ArrayAssignmentRestrictionsSniff.php') path\to\PHP_CodeSniffer\autoload.php:167

This can be tested and reproduced with the following steps:

  • Download/clone release 0.13.0 of the WordPress Coding Standards
  • Set up a custom ruleset like this, changing the value of installed_paths to the dir in which WPCS is installed on your system:
<?xml version="1.0"?>
<ruleset name="Test">
	<config name="installed_paths" value="path/to/WPCS"/>
	<rule ref="WordPress"/>
</ruleset>
  • Run phpcs --config-delete installed_paths
  • Run PHPCS against any code using the above ruleset

Loosely related to #1564, #1453

I'll look into - temporarily - patching this downstream in both WPCS as well as PHPCompatibility using the code I previously posted in #1564 (comment), so when testing it is imperative to use the WPCS 0.13.0 tagged release.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions