Skip to content

Commit

Permalink
Merge branch 'feature/fixable-leading-slash' of https://github.com/mi…
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Jan 6, 2020
2 parents d90bdad + 300e069 commit 09896ea
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
<file baseinstalldir="PHP/CodeSniffer" name="FileHeaderUnitTest.10.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileHeaderUnitTest.php" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="ImportStatementUnitTest.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="ImportStatementUnitTest.inc.fixed" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="ImportStatementUnitTest.php" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="OpenTagUnitTest.1.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="OpenTagUnitTest.2.inc" role="test" />
Expand Down
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 09896ea

Please sign in to comment.