Abstracts: change $exclude property from string to array #1390
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
$exclude
property which is included in most abstract sniffs and by extension in all sniffs which use these abstracts, used to expect a comma-delimited list.This comma-delimited list was then exploded to an array from within the sniff.
In other words, in reality the sniff expected an
array
.This has now been formalized. All
$exclude
properties now expectarray
input.As outlined in #1368, this is not a BC-break as properties passed as a comma-delimited string will still be supported (for now). Support for this may be removed at some point in the future.
The upside of making this change is that users who use WPCS 3.3.0, can start using the new property array format in their custom rulesets which makes for a more easily readable ruleset.
exclude
property in custom rulesets.Fixes #1368
Testing this PR
Testing this PR is a little finicky as it needs to be done manually, so here are the steps to do so:
1 - Start by saving the below code to a temporary test file.
Test file content
2 - Next, create a custom ruleset with the below content and save it to a file
Initial ruleset
3 - Run
phpcs ./test-file.php --standard=./test-ruleset.xml --report=full,source
and verify the outputSource report output
4 - Update the custom ruleset with "old-style" excludes
Ruleset with old-style excludes
5 - Run
phpcs
again and confirm no errors/warnings are displayed.6 - Update the custom ruleset with "new-style" excludes
Ruleset with new-style excludes
7 - Run
phpcs
again and confirm no errors/warnings are displayed.