Skip to content

Commit 1524e57

Browse files
authored
Add auto-fixing to DiscourageFitzinator sniff (#185)
1 parent 78e3b0b commit 1524e57

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Symfony/Sniffs/Whitespace/DiscourageFitzinatorSniff.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@ public function process(File $phpcsFile, $stackPtr)
8080
|| strpos($tokens[$stackPtr]['content'], "\r") > 0
8181
) {
8282
$warning = 'Please trim any trailing whitespace';
83-
$phpcsFile->addWarning($warning, $stackPtr, 'Invalid');
83+
$fix = $phpcsFile->addFixableWarning($warning, $stackPtr, 'Invalid');
84+
if ($fix === true) {
85+
$phpcsFile->fixer->beginChangeset();
86+
$phpcsFile->fixer->replaceToken($stackPtr, '');
87+
$phpcsFile->fixer->addNewlineBefore($stackPtr);
88+
$phpcsFile->fixer->endChangeset();
89+
}
8490
}
8591
}
8692
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
4+
5+
6+
7+
8+
$a = 'a';
9+
$b = 'b';

0 commit comments

Comments
 (0)