- Notifications
You must be signed in to change notification settings - Fork 1.5k
Coding standard located under an installed_path with the same directory name throws an error #1450
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
Coding standard located under an installed_path with the same directory name throws an error #1450
Conversation
If a "Standards" directory is called the same as one of the standards it contains and that standard is requested an _"ERROR: the ... coding standard is not installed."_ will be thrown and the sniffs will not run. While I suppose this change in behaviour between PHPCS 3.x and PHPCS 2.x is intended to add support for "one standard" type of libraries, it breaks support for multi-standard libraries where one of the standards has the same name as the repository. The change I'm proposing in this PR will maintain support for the PHPCS 2.x behaviour - thus not breaking existing registered standards - while at the same time supporting the new feature.
Just curious - what does the 🔥 emoji represent in these recent PRs? |
installed_paths
in PHPCS 3.x Thanks a lot for finding and fixing this. Yes, it was to allow installed_paths to point directly to coding standards instead of having to point to the parent dir. Unfortunately my WordPress CS install dir is not called |
Regarding the 🔥 I've been playing a bit with commit messages lately to see if it helps in quick grasping of what a commit is all about, inspired by: |
Thanks for merging this!
I was running into it for both WP as well as PHPCompatibility, duh me I suppose, but it was an easy fix to make ;-) |
Interesting concept. I'd personally have no hope of remembering all that :) |
Nor me, I use what seems to make sense at the time, though I generally find that emojis can be a powerful way to underline what a commit is about. |
…`installed_paths`. If any external standard or a custom ruleset refers to a complete standard and this standard is registered in the `installed_paths` config as a one-standard directory, a `Reference sniff ... does not exist` error will be thrown and no sniffs will be run. Bug introduced in squizlabs#1450 (by me, sorry!). The reason for this is that the `getInstalledStandardPath()` method expects a string, but will in actual fact receive a `SimpleXMLElement` object when a complete standard is included by another standard. This was previously not documented in the function doc block as a possibility. While in the original code, the `$standards` name was only used as a concatenated string - which triggered the `SimpleXML.toString()` method -, the fix in squizlabs#1450 introduced a strict comparison without the `toString()` conversion, causing the bug. Installed_paths | string `$standards` | SimpleXMLElement `$standards` --------------- | ------------------- | ---------------------- "Standards" directory | :white_checkmark: | :white_checkmark: one-standard directory | :white_checkmark: | ❌ <= This is what this fixes. While debugging this, I also noticed that this method is called for every single ref in the ruleset and would go through the whole loop before returning `null`, while for `refs` which refer to a custom xml ruleset or to a sniff or sniff category, `null` can be returned a lot earlier and for paths which don't resolve to a ruleset, part of the loop can be skipped.
…`installed_paths`. If any external standard or a custom ruleset refers to a complete standard and this standard is registered in the `installed_paths` config as a one-standard directory, a `Reference sniff ... does not exist` error will be thrown and no sniffs will be run. Bug introduced in squizlabs#1450 (by me, sorry!). The reason for this is that the `getInstalledStandardPath()` method expects a string, but will in actual fact receive a `SimpleXMLElement` object when a complete standard is included by another standard. This was previously not documented in the function doc block as a possibility. While in the original code, the `$standards` name was only used as a concatenated string - which triggered the `SimpleXML.toString()` method -, the fix in squizlabs#1450 introduced a strict comparison without the `toString()` conversion, causing the bug. Installed_paths | string `$standards` | SimpleXMLElement `$standards` --------------- | ------------------- | ---------------------- "Standards" directory | ✅ | ✅ one-standard directory | ✅ | ❌ <= This is what this fixes. While debugging this, I also noticed that this method is called for every single ref in the ruleset and would go through the whole loop before returning `null`, while for `refs` which refer to a custom xml ruleset or to a sniff or sniff category, `null` can be returned a lot earlier and for paths which don't resolve to a ruleset, part of the loop can be skipped.
If a "Standards" directory is called the same as one of the standards it contains and that standard is requested, an "ERROR: the ... coding standard is not installed." error will be thrown and the sniffs will not run.
While I suppose this change in behaviour between PHPCS 3.x and PHPCS 2.x is intended to add support for "one standard" type of libraries, it breaks support for multi-standard libraries where one of the standards has the same name as the repository.
The change I'm proposing in this PR will maintain support for the PHPCS 2.x behaviour - thus not breaking existing registered standards - while at the same time supporting the new feature.