slevomat / coding-standard

Slevomat Coding Standard for PHP_CodeSniffer provides many useful sniffs
MIT License
1.39k stars 173 forks source link

Alphabetically sort grouped namespaces fix breaks code #872

Closed ainehickey closed 4 years ago

ainehickey commented 4 years ago

Sniff: SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses Version: slevomat/coding-standard - 6.1.1, squizlabs/php_codesniffer - 3.5.3

I think I might have found a bug. I have a file. The Namespaces aren't alphabetic, but I'm using grouped namespaces.

Before fix code:

<?php

declare(strict_types=1);

use Illuminate\Database\Seeder;
use App\Models\Entities\{
    A,
    B,
    C
};
use Laravel\Lumen\Testing\DatabaseTransactions;

class Example
{
}

I'd like my namespaces to be alphabetic.

My ruleset:

<?xml version="1.0"?>
<ruleset name="MyRuleset">
    <config name="installed_paths" value="vendor/slevomat/coding-standard" />
    <rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses" />
</ruleset>

When I run phpcs it over my file, I get an error. Super, as this is correct

-------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-------------------------------------------------------------------------------------------------------------------------------------
 15 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Laravel\Lumen\Testing\DatabaseTransactions.
-------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------------------------------------------

But when I try to automatically fix it, I run into an issue.

PHPCBF RESULT SUMMARY
------------------------------------------------------------------------------------------
FILE                                                                      FIXED  REMAINING
------------------------------------------------------------------------------------------
C:\Example.php                                                        1      0
------------------------------------------------------------------------------------------
A TOTAL OF 1 ERROR WERE FIXED IN 1 FILE
------------------------------------------------------------------------------------------

After fix code:

declare(strict_types=1);

use A;
use Illuminate\Database\Seeder;
use Laravel\Lumen\Testing\DatabaseTransactions;

The grouped namespace outside the brackets has been deleted, and one one of the class names remains.

Please let me know if I'm doing something wrong or if you need any more info.

kukulich commented 4 years ago

Yes, we don’t support group uses.

ainehickey commented 4 years ago

Yes, we don’t support group uses.

Ah, ok. Thanks.

github-actions[bot] commented 4 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.