Skip to content

Commit

Permalink
Generic/OpeningFunctionBraceKernighanRichie: improve handling of tabs
Browse files Browse the repository at this point in the history
This commit makes a tiny performance improvement to the sniff when
handling fixing code with tabs. Before this change, the sniff would need
two passes of the fixer for code with one tab before the opening brace.
First, it would add a space between the tab and the opening brace. Then,
on a second pass, it would replace the tab and the space with just one
space.

Now, it replaces the tab with the space directly without the need for a
second pass.
  • Loading branch information
rodrigoprimo committed Nov 21, 2024
1 parent 92a84a7 commit 89a17b6
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public function process(File $phpcsFile, $stackPtr)
$data = [$length];
$fix = $phpcsFile->addFixableError($error, $openingBrace, 'SpaceBeforeBrace', $data);
if ($fix === true) {
if ($length === 0 || $length === '\t') {
if ($length === 0) {
$phpcsFile->fixer->addContentBefore($openingBrace, ' ');
} else {
$phpcsFile->fixer->replaceToken(($openingBrace - 1), ' ');
Expand Down

0 comments on commit 89a17b6

Please sign in to comment.