Skip to content

Commit

Permalink
Feature: fixable LeadingSlash error in PSR12.Files.ImportStatement
Browse files Browse the repository at this point in the history
This can be easily fixable, just be removing the slash.
Added .fixed file with expected result of the fixer.
  • Loading branch information
michalbundyra committed Nov 13, 2019
1 parent ed879f1 commit 05febc3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Standards/PSR12/Sniffs/Files/ImportStatementSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ public function process(File $phpcsFile, $stackPtr)
}

$error = 'Import statements must not begin with a leading backslash';
$phpcsFile->addError($error, $next, 'LeadingSlash');
$fix = $phpcsFile->addFixableError($error, $next, 'LeadingSlash');

if ($fix === true) {
$phpcsFile->fixer->replaceToken($next, '');
}

}//end process()

Expand Down
19 changes: 19 additions & 0 deletions src/Standards/PSR12/Tests/Files/ImportStatementUnitTest.inc.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
use Vendor\Package\{ClassA as A, ClassB, ClassC as C};
use Vendor\Package\SomeNamespace\ClassD as D;
use /*comment*/ Vendor\Package\AnotherNamespace\ClassE as E;

use function Vendor\Package\{functionA, functionB, functionC};
use FUNCTION Another\Vendor\functionD;

use CONST Vendor\Package\{CONSTANT_A, CONSTANT_B, CONSTANT_C};
use const Another\Vendor\CONSTANT_D;

class ClassName3
{
use \FirstTrait;
use SecondTrait;
use ThirdTrait;
}

$foo = function() use($bar) {};

0 comments on commit 05febc3

Please sign in to comment.