10up / phpcs-composer

Official 10up PHPCS rules.
MIT License
49 stars 8 forks source link

phpcs fail if installing globably #9

Closed nicholasio closed 5 years ago

nicholasio commented 6 years ago

I know the purpose is installing it as a dependency, but I just tried to install this globally to be able to user on a project that hasn't included it yet and it failed with the following error:

ERROR: the "10up-Default" coding standard is not installed. PHP Fatal error:  Uncaught UnexpectedValueException: DirectoryIterator::__construct(vendor/10up/phpcs-composer/10up-Default): failed to open dir: No such file or directory in /home/nicholas_io/.config/composer/vendor/squizlabs/php_codesniffer/CodeSniffer.php:2141

The reason has to do with the relative paths to the vendor dir that assumes a local installation.

I was able to get a quick hotfix for this by setting the config path dynamically based on the vendor dir (this should be the safest way to set the path I believe).

$vendor = $this->composer->getConfig()->get('vendor-dir');
$this->PHPCS_CONFIG_PATH = sprintf('%1$s/10up/phpcs-composer,%1$s/wp-coding-standards/wpcs,%1$s/wimg/php-compatibility', $vendor);

I also had to comment out the rule below as it was giving me an error about not being able to find that rule (apparently extending a specific a rule still doesn't work with the fix above when installing globally):

<!--<rule ref="WordPress.WP.I18n.MissingTranslatorsComment">
        <type>warning</type>
</rule>-->

Any thoughts on this? I didn't submit a PR request as I'm not sure what is the best way to fix this.

sudar commented 5 years ago

@nicholasio

Try out #16 and let me know if this fixes the issue that you are facing.

nicholasio commented 5 years ago

Confirmed. #16 fixes the issue.