Skip to content

Commit

Permalink
Fix crash when useless default comment and statement indentation coll…
Browse files Browse the repository at this point in the history
…ide (#37)
  • Loading branch information
rvanvelzen committed Jan 3, 2024
1 parent 199f1e5 commit 35232b3
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/Fixer/Commenting/RemoveUselessDefaultCommentFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public function fix(SplFileInfo $fileInfo, Tokens $tokens): void

// remove token
$tokens->clearAt($index);
$tokens->removeTrailingWhitespace($index, "\n");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ namespace Symplify\CodingStandard\Tests\Fixer\Commenting\RemovePHPStormTodoComme

namespace Symplify\CodingStandard\Tests\Fixer\Commenting\RemovePHPStormTodoCommentFixer\Fixture;


// TODO some other notes
?>
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,22 @@ class SomeClass5

namespace Symplify\CodingStandard\Tests\Fixer\Commenting\RemoveUselessClassCommentFixer\Fixture;


class SomeClass1
{
}


class SomeClass2
{
}


class SomeClass3
{
}


class SomeClass4
{
}


class SomeClass5
{
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

function foo(): void
{
// TODO: Implement foo() method.
}
-----
<?php

function foo(): void
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Symplify\CodingStandard\Tests\Issues;

use Iterator;
use PHPUnit\Framework\Attributes\DataProvider;
use Symplify\EasyCodingStandard\Testing\PHPUnit\AbstractCheckerTestCase;

final class RemoveUselessDefaultCommentAndStatementIndentationFixerTest extends AbstractCheckerTestCase
{
#[DataProvider('provideData')]
public function test(string $filePath): void
{
$this->doTestFile($filePath);
}

public static function provideData(): Iterator
{
yield [__DIR__ . '/Fixture/remove_useless_default_comment_and_statement_indentation.php.inc'];
}

public function provideConfig(): string
{
return __DIR__ . '/config/config_remove_useless_default_comment_and_statement_indentation.php';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Fixer\Whitespace\StatementIndentationFixer;
use Symplify\CodingStandard\Fixer\Commenting\RemoveUselessDefaultCommentFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return static function (ECSConfig $ecsConfig): void {
$ecsConfig->rule(RemoveUselessDefaultCommentFixer::class);
$ecsConfig->rule(StatementIndentationFixer::class);
};

0 comments on commit 35232b3

Please sign in to comment.