Skip to content

Auto-fixer for PSR2.Namespaces.UseDeclaration incorrect for some parse errors #333

Open
@fredden

Description

@fredden

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:

  1. Create a file called test.php with the code sample above.
  2. Run php bin/phpcbf --suffix=.fixed --standard=PSR2 --sniffs=PSR2.Namespaces.UseDeclaration -ps test.php
  3. Review differences between test.php and test.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 (293b617)
Standard PSR2
Install type git clone

Additional context

Add any other context about the problem here.

Please confirm:

  • I have searched the issue list and am not opening a duplicate issue.
  • I confirm that this bug is a bug in PHP_CodeSniffer and not in one of the external standards.
  • I have verified the issue still exists in the master branch of PHP_CodeSniffer.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions