PHP_CodeSniffer
PHP_CodeSniffer copied to clipboard
Auto-fixer for `PSR2.Namespaces.UseDeclaration` incorrect for some parse errors
Describe the bug
While working on another task, it was noticed that the auto-fixer for PSR2.Namespaces.UseDeclaration
is incorrect for some parse errors.
Code sample
<?php
use Parse\Error { invalid,
php bin/phpcs --basepath=. --standard=PSR2 --sniffs=PSR2.Namespaces.UseDeclaration -ps test.php
2 | ERROR | [x] There must be one USE keyword per declaration (PSR2.Namespaces.UseDeclaration.MultipleDeclarations)
To reproduce
Steps to reproduce the behaviour:
- Create a file called
test.php
with the code sample above. - Run
php bin/phpcbf --suffix=.fixed --standard=PSR2 --sniffs=PSR2.Namespaces.UseDeclaration -ps test.php
- Review differences between
test.php
andtest.php.fixed
<?php
use Parse\Error { invalid;
use
Expected behaviour
The code sample is not auto-fixable. An error should either not be reported, or a non-fixable error reported.
Versions (please complete the following information)
Operating System | Debian Linux |
PHP version | 8.3 |
PHP_CodeSniffer version | master (293b61756fc40a4e555e1964ca83a15d6b7aaede) |
Standard | PSR2 |
Install type | git clone |
Additional context
Add any other context about the problem here.
Please confirm:
- [x] I have searched the issue list and am not opening a duplicate issue.
- [x] I confirm that this bug is a bug in PHP_CodeSniffer and not in one of the external standards.
- [x] I have verified the issue still exists in the
master
branch of PHP_CodeSniffer.