Skip to content

Commit

Permalink
If the file contains a Group Use then ignore the file completely
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan1055 authored and kukulich committed Sep 11, 2023
1 parent c452646 commit 65aaff7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use function uasort;
use const T_COMMA;
use const T_OPEN_TAG;
use const T_OPEN_USE_GROUP;
use const T_SEMICOLON;

class AlphabeticallySortedUsesSniff implements Sniff
Expand Down Expand Up @@ -60,6 +61,12 @@ public function process(File $phpcsFile, $openTagPointer): void
return;
}

// If there are any 'use group' statements then we cannot sort and fix the file.
$groupUsePointer = TokenHelper::findNext($phpcsFile, T_OPEN_USE_GROUP, $openTagPointer);
if ($groupUsePointer !== null) {
return;
}

$fileUseStatements = UseStatementHelper::getFileUseStatements($phpcsFile);
foreach ($fileUseStatements as $useStatements) {
$lastUse = null;
Expand Down
13 changes: 13 additions & 0 deletions tests/Sniffs/Namespaces/AlphabeticallySortedUsesSniffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ public function testIncorrectOrderNotFixable(): void
self::assertAllFixedInFile($report);
}

public function testIncorrectOrderGroupUseNotFixable(): void
{
$report = self::checkFile(
__DIR__ . '/data/alphabeticalGroupUseNotFixable.php',
[],
[AlphabeticallySortedUsesSniff::CODE_INCORRECT_ORDER]
);

self::assertNoSniffErrorInFile($report);

self::assertAllFixedInFile($report);
}

public function testFixable(): void
{
$report = self::checkFile(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

use thirdproject\D;
use otherproject\{B, C};
use myproject\A;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

use thirdproject\D;
use otherproject\{B, C};
use myproject\A;

0 comments on commit 65aaff7

Please sign in to comment.