From 05febc37fc61f13337323cb820c8a52ef011bce6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bundyra?= Date: Wed, 13 Nov 2019 20:11:08 +0000 Subject: [PATCH] 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. --- .../Sniffs/Files/ImportStatementSniff.php | 6 +++++- .../Files/ImportStatementUnitTest.inc.fixed | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/Standards/PSR12/Tests/Files/ImportStatementUnitTest.inc.fixed diff --git a/src/Standards/PSR12/Sniffs/Files/ImportStatementSniff.php b/src/Standards/PSR12/Sniffs/Files/ImportStatementSniff.php index 3aef859086..11c25ffa85 100644 --- a/src/Standards/PSR12/Sniffs/Files/ImportStatementSniff.php +++ b/src/Standards/PSR12/Sniffs/Files/ImportStatementSniff.php @@ -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() diff --git a/src/Standards/PSR12/Tests/Files/ImportStatementUnitTest.inc.fixed b/src/Standards/PSR12/Tests/Files/ImportStatementUnitTest.inc.fixed new file mode 100644 index 0000000000..d5b3f67eed --- /dev/null +++ b/src/Standards/PSR12/Tests/Files/ImportStatementUnitTest.inc.fixed @@ -0,0 +1,19 @@ +