Skip to content

Commit

Permalink
Fix to use new docblock clearing token api easy-coding-standard/easy-…
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Feb 14, 2024
1 parent c40feb1 commit ec8994a
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"require": {
"php": ">=8.2",
"nette/utils": "^3.2",
"friendsofphp/php-cs-fixer": "^3.45",
"friendsofphp/php-cs-fixer": "^3.49",
"symplify/rule-doc-generator-contracts": "^11.1"
},
"require-dev": {
Expand Down
19 changes: 15 additions & 4 deletions src/Fixer/Commenting/RemoveUselessDefaultCommentFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Symplify\CodingStandard\Fixer\Commenting;

use PhpCsFixer\Fixer\Basic\BracesFixer;
use PhpCsFixer\FixerDefinition\FixerDefinition;
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
use PhpCsFixer\Tokenizer\Token;
Expand Down Expand Up @@ -45,6 +46,12 @@ public function isCandidate(Tokens $tokens): bool
return $tokens->isAnyTokenKindsFound([T_DOC_COMMENT, T_COMMENT]);
}

public function getPriority(): int
{
/** must run before @see BracesFixer to cleanup spaces */
return 40;
}

/**
* @param Tokens<Token> $tokens
*/
Expand All @@ -63,13 +70,17 @@ public function fix(SplFileInfo $fileInfo, Tokens $tokens): void
$token
);

if ($cleanedDocContent !== '') {
continue;
if ($cleanedDocContent === '') {
// remove token
$tokens->clearTokenAndMergeSurroundingWhitespace($index);
}

// if ($cleanedDocContent !== '') {
// continue;
// }

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ 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
@@ -1,6 +1,6 @@
<?php

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

/**
* class SomeClass
Expand Down Expand Up @@ -36,24 +36,29 @@ class SomeClass5
-----
<?php

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


class SomeClass1
{
}


class SomeClass2
{
}


class SomeClass3
{
}


class SomeClass4
{
}


class SomeClass5
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

declare(strict_types=1);

use PhpCsFixer\Fixer\Basic\BracesFixer;
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);
$ecsConfig->rules([
BracesFixer::class,
RemoveUselessDefaultCommentFixer::class,
StatementIndentationFixer::class,
]);
};
2 changes: 0 additions & 2 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@
define('T_ENUM', 5015);
}


// required for PHP_CodeSniffer in packages/EasyCodingStandard/tests/*
if (! defined('PHP_CODESNIFFER_VERBOSITY')) {
define('PHP_CODESNIFFER_VERBOSITY', 0);
// initialize custom T_* token constants used by PHP_CodeSniffer parser
new Tokens();
}


// prefer local coding-standard over old, vendor one
exec('rm -rf vendor/symplify/easy-coding-standard/vendor/symplify/coding-standard/src');
exec('ln -s $PWD/src vendor/symplify/easy-coding-standard/vendor/symplify/coding-standard/');

0 comments on commit ec8994a

Please sign in to comment.