Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jrfnl opened this issue Aug 5, 2017 · 2 comments
Milestone

Comments

@jrfnl
Copy link
Contributor

jrfnl commented Aug 5, 2017

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.

@gsherwood
Copy link
Member

The easiest thing to do here was to go through the installed standards and register the autoloader search paths again. This ends up re-registering some paths (no actual harm there, just extra time) so the code could be changed to do this just for the new paths after they are explod'ed and realpath'ed, but this method will at least work the same way in all cases.

The 0.13.0 release now works fine for me, as do the latest master and develop branches.

@jrfnl
Copy link
Contributor Author

jrfnl commented Aug 16, 2017

Awesome! Thank you.

jrfnl added a commit to PHPCSStandards/PHPCSUtils that referenced this issue Nov 6, 2019
When `installed_paths` is set via a custom, the PHPCS native autoloader cannot find non-sniff files provided by an external standard, including the PHPCSUtils files.

As PHPCS 3.0.2 is rarely used anymore anyway, let's just not support it.

Ref: squizlabs/PHP_CodeSniffer#1591
jrfnl added a commit to PHPCSStandards/PHPCSUtils that referenced this issue Dec 26, 2019
When `installed_paths` is set via a custom, the PHPCS native autoloader cannot find non-sniff files provided by an external standard, including the PHPCSUtils files.

As PHPCS 3.0.2 is rarely used anymore anyway, let's just not support it.

Ref: squizlabs/PHP_CodeSniffer#1591
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants