Skip to content

Commit 05febc3

Browse files
committed
Feature: fixable LeadingSlash error in PSR12.Files.ImportStatement
This can be easily fixable, just be removing the slash. Added .fixed file with expected result of the fixer.
1 parent ed879f1 commit 05febc3

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/Standards/PSR12/Sniffs/Files/ImportStatementSniff.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ public function process(File $phpcsFile, $stackPtr)
6565
}
6666

6767
$error = 'Import statements must not begin with a leading backslash';
68-
$phpcsFile->addError($error, $next, 'LeadingSlash');
68+
$fix = $phpcsFile->addFixableError($error, $next, 'LeadingSlash');
69+
70+
if ($fix === true) {
71+
$phpcsFile->fixer->replaceToken($next, '');
72+
}
6973

7074
}//end process()
7175

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
use Vendor\Package\{ClassA as A, ClassB, ClassC as C};
3+
use Vendor\Package\SomeNamespace\ClassD as D;
4+
use /*comment*/ Vendor\Package\AnotherNamespace\ClassE as E;
5+
6+
use function Vendor\Package\{functionA, functionB, functionC};
7+
use FUNCTION Another\Vendor\functionD;
8+
9+
use CONST Vendor\Package\{CONSTANT_A, CONSTANT_B, CONSTANT_C};
10+
use const Another\Vendor\CONSTANT_D;
11+
12+
class ClassName3
13+
{
14+
use \FirstTrait;
15+
use SecondTrait;
16+
use ThirdTrait;
17+
}
18+
19+
$foo = function() use($bar) {};

0 commit comments

Comments
 (0)