Replace the WordPress.Array.CommaAfterArrayItem sniff #2310
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.
... with two sniffs from PHPCSExtra.
The original WPCS native sniff did two things:
The sniff will now be replaced by the following upstream sniffs:
NormalizedArrays.Arrays.CommaAfterLastfor the comma after the last item in an array.Universal.WhiteSpace.CommaSpacingfor the spacing around commas (and not just in arrays).The behaviour of the sniffs is 100% in line with the original sniff (verified by running both the old and the new sniffs over the test case file for the WPCS sniff being removed).
Additionally, the
Universal.WhiteSpace.CommaSpacingsniff will now check the spacing around commas in more places, where WPCS previously did not check the comma spacing and will make sure the comma is before a trailing comment, not after.The
Universal.WhiteSpace.CommaSpacingsniff by default checks the spacing for all commas with the following exceptions:php_versionconfig directive is set to a version higher than PHP 7.3.0, a new line before will be enforced to prevent parse errors on PHP < 7.3.This also means that the sniff will flag issues with the spacing around commas in function declarations, function calls and closure use statements, while WPCS already has other sniffs in place to handle this.
Luckily, the upstream sniff offers very modular error codes, so we can selectively silence those errors in the most common situations to prevent duplicate notices about the same issue. For those places were the
Universalsniff doesn't offer modular codes, we can, in most cases, selectively silence the errors coming from other sniffs. This commit includes some of those exclusions, but we may need to add more if we discover additional message duplications.There may, however, still be some places which could get duplicate messages. It is, however, not expected that those will ever lead to fixer conflicts.
Both upstream sniffs contain fixers for all issues.
Ref:
NormalizedArrays.Arrays.CommaAfterLastsniff PHPCSStandards/PHPCSExtra#11Universal.WhiteSpace.CommaSpacingsniff PHPCSStandards/PHPCSExtra#254