Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion PhpCollective/Sniffs/WhiteSpace/EmptyEnclosingLineSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ public function process(File $phpcsFile, $stackPtr): void
if ($contentLine < $braceLine + 1) {
$phpcsFile->fixer->addNewline($curlyBraceStartIndex);
} else {
for ($i = $curlyBraceStartIndex + 1; $i < $beginningOfLine - 1; $i++) {
// Replace first token with newline, remove the rest
$phpcsFile->fixer->replaceToken($curlyBraceStartIndex + 1, $phpcsFile->eolChar);
for ($i = $curlyBraceStartIndex + 2; $i < $beginningOfLine; $i++) {
$phpcsFile->fixer->replaceToken($i, '');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,31 @@ public function testEmptyEnclosingLineFixer(): void
{
$this->assertSnifferCanFixErrors(new EmptyEnclosingLineSniff());
}

/**
* Tests that tabs are preserved when fixing empty enclosing line.
*
* @return void
*/
public function testTabsPreservedSniffer(): void
{
$this->prefix = 'tabs-';
$this->assertSnifferFindsErrors(new EmptyEnclosingLineSniff(), 1);
$this->prefix = null;
}

/**
* Tests fixer preserves indentation with tabs.
*
* This test verifies the fix for the bug where indentation was lost
* when removing empty lines after opening braces.
*
* @return void
*/
public function testTabsPreservedFixer(): void
{
$this->prefix = 'tabs-';
$this->assertSnifferCanFixErrors(new EmptyEnclosingLineSniff());
$this->prefix = null;
}
}
15 changes: 15 additions & 0 deletions tests/_data/EmptyEnclosingLine/tabs-after.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php declare(strict_types = 1);

namespace PhpCollective;

class TabsTest {
/**
* @param string $foo The foo.
*
* @return void
*/
public function one(string $foo): void
{
echo $foo;
}
}
16 changes: 16 additions & 0 deletions tests/_data/EmptyEnclosingLine/tabs-before.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php declare(strict_types = 1);

namespace PhpCollective;

class TabsTest {

/**
* @param string $foo The foo.
*
* @return void
*/
public function one(string $foo): void
{
echo $foo;
}
}
Loading