PHP_CodeSniffer
PHP_CodeSniffer copied to clipboard
Error in case file with rulesets name exists in project root
Describe the bug
In case there is a file in project root that happens to match a ruleset name the file is loaded instead as rulesets configuration.
ERROR: Ruleset /path/to/project/PSR12 is not valid
- On line 1, column 1: Start tag expected, '<' not found
To reproduce Steps to reproduce the behavior:
- Create a file called
PSR12in the project root andfooas it's content. - Create
phpcs.xmlfile with the following contents:
<?xml version="1.0"?>
<ruleset>
<rule ref="PSR12"/>
</ruleset>
- Assuming that phpcs was installed using composer run
./vendor/bin/phpcs. - See error message displayed
$ ./vendor/bin/phpcs
ERROR: Ruleset /path/to/project/PSR12 is not valid
- On line 1, column 1: Start tag expected, '<' not found
Run "phpcs --help" for usage information
Expected behavior The PSR12 standard should be used.
Versions (please complete the following information):
- OS: MacOS 10.15
- PHP: 7.4
- PHPCS: 3.5.8
- Standard: any
Can definitely confirm this issue!
We use https://github.com/cakephp/cakephp-codesniffer which is based upon this package but If I also create a cakephp file in my "root" directoy and then call vendor/bin/phpcs --colors --parallel=16 -p src/ tests/ I get the error
ERROR: Ruleset /Users/kevinpfeifer/Documents/CakePHP/cakephp/CakePHP is not valid
After I delete my cakephp file it works again as well.
But the weird thing is also, that I can circumvent this issue if I specify the used standard via
vendor/bin/phpcs --colors --parallel=16 -p --standard=CakePHP src/ tests/
Part of this whole issue may also be dependet/related on the used operating system / the used filesystem since I am on MacOS with a case-insensitive filesystem.
Alright, the main problem here is the fact, that the rule name = file name and we therefore go into this if
https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Ruleset.php#L720
Therefore we don't parse/load the set value in installed_paths and load the rules from that folder.