Skip to content

Commit

Permalink
Detect and remove empty comment (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
asispts committed Nov 3, 2023
1 parent e9ce7c5 commit 9f0c019
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 6 deletions.
1 change: 1 addition & 0 deletions ptscs/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
<rule ref="SlevomatCodingStandard.Variables.UnusedVariable" />
<rule ref="SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure" />
<rule ref="SlevomatCodingStandard.Commenting.DisallowOneLinePropertyDocComment" />
<rule ref="SlevomatCodingStandard.Commenting.EmptyComment" />

<!-- Useless typehint -->
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint.UselessAnnotation" />
Expand Down
27 changes: 27 additions & 0 deletions tests/Sniffs/Slevomat/Commenting/EmptyCommentTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php declare(strict_types=1);

namespace Ptscs\Tests\Sniffs\Slevomat\Commenting;

use Iterator;
use Ptscs\Tests\SniffTestCase;
use Ptscs\Tests\Utils\ErrorData;

final class EmptyCommentTest extends SniffTestCase
{
protected function setUp(): void
{
parent::setUp();
$this->appendExclude('Squiz.Classes.ClassFileName.NoMatch');
}

public static function provideTestData(): Iterator
{
yield[
[
new ErrorData(7, 'SlevomatCodingStandard.Commenting.EmptyComment.EmptyComment'),
new ErrorData(11, 'SlevomatCodingStandard.Commenting.EmptyComment.EmptyComment'),
new ErrorData(14, 'SlevomatCodingStandard.Commenting.EmptyComment.EmptyComment'),
],
];
}
}
12 changes: 12 additions & 0 deletions tests/Sniffs/Slevomat/Commenting/_data/EmptyComment.php.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php declare(strict_types=1);

namespace App;

final class Foobar
{
private $var1;

private $var2;

private $var3;
}
16 changes: 16 additions & 0 deletions tests/Sniffs/Slevomat/Commenting/_data/EmptyComment.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php declare(strict_types=1);

namespace App;

final class Foobar
{
/**
*/
private $var1;

/***/
private $var2;

//
private $var3;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ namespace App;

final class Foobar
{
/**
*/
public function check(string $useless, array $list, $missing): void
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ namespace App;

final class Foobar
{
/**
*/
public function useless(): string
{
return $this->value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ final class Foobar
$this->value = $value;
}

/**
*/
public function getValue(): string
{
return $this->value;
Expand Down

0 comments on commit 9f0c019

Please sign in to comment.