From 1f353a566d5ddd8f692bdb46a4fecc8c9006acc7 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Wed, 14 Feb 2024 10:49:29 +0100 Subject: [PATCH] Fix to use new docblock clearing token api https://github.com/easy-coding-standard/easy-coding-standard/issues/174 --- composer.json | 12 ++++++------ ecs.php | 17 +++++------------ .../RemoveUselessDefaultCommentFixer.php | 16 ++++++++++------ .../todo_change_autogenerated_comment.php.inc | 1 + .../Fixture/useless_class_comment.php.inc | 9 +++++++-- ...efault_comment_and_statement_indentation.php | 8 ++++++-- tests/bootstrap.php | 2 -- 7 files changed, 35 insertions(+), 30 deletions(-) diff --git a/composer.json b/composer.json index f574321c0..dee3ba20c 100644 --- a/composer.json +++ b/composer.json @@ -5,18 +5,18 @@ "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": { - "symplify/easy-coding-standard": "^12.0.11", - "squizlabs/php_codesniffer": "^3.8.0", + "symplify/easy-coding-standard": "^12.1", + "squizlabs/php_codesniffer": "^3.8.1", "phpunit/phpunit": "^10.5", "symplify/rule-doc-generator": "^12.0", "phpstan/extension-installer": "^1.3", - "phpstan/phpstan": "^1.10.50", - "rector/rector": "^0.18", - "symplify/phpstan-extensions": "^11.2", + "phpstan/phpstan": "^1.10.58", + "rector/rector": "^1.0", + "symplify/phpstan-extensions": "^11.4", "tomasvotruba/class-leak": "^0.2", "tracy/tracy": "^2.10" }, diff --git a/ecs.php b/ecs.php index a66f62e83..eb2b3132f 100644 --- a/ecs.php +++ b/ecs.php @@ -3,19 +3,12 @@ declare(strict_types=1); use Symplify\EasyCodingStandard\Config\ECSConfig; -use Symplify\EasyCodingStandard\ValueObject\Set\SetList; -return static function (ECSConfig $ecsConfig): void { - $ecsConfig->paths([ - __DIR__ . '/ecs.php', - __DIR__ . '/rector.php', +return ECSConfig::configure() + ->withPaths([ __DIR__ . '/config', __DIR__ . '/src', __DIR__ . '/tests', - ]); - - $ecsConfig->sets([ - SetList::COMMON, - SetList::PSR_12, - ]); -}; + ]) + ->withRootFiles() + ->withPreparedSets(psr12: true, common: true); diff --git a/src/Fixer/Commenting/RemoveUselessDefaultCommentFixer.php b/src/Fixer/Commenting/RemoveUselessDefaultCommentFixer.php index ef1f503e5..0a88fff23 100644 --- a/src/Fixer/Commenting/RemoveUselessDefaultCommentFixer.php +++ b/src/Fixer/Commenting/RemoveUselessDefaultCommentFixer.php @@ -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; @@ -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 $tokens */ @@ -63,13 +70,10 @@ public function fix(SplFileInfo $fileInfo, Tokens $tokens): void $token ); - if ($cleanedDocContent !== '') { - continue; + if ($cleanedDocContent === '') { + // remove token + $tokens->clearTokenAndMergeSurroundingWhitespace($index); } - - // remove token - $tokens->clearAt($index); - $tokens->removeTrailingWhitespace($index, "\n"); } } diff --git a/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/todo_change_autogenerated_comment.php.inc b/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/todo_change_autogenerated_comment.php.inc index 45bbfb3cf..84b83da35 100644 --- a/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/todo_change_autogenerated_comment.php.inc +++ b/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/todo_change_autogenerated_comment.php.inc @@ -10,5 +10,6 @@ namespace Symplify\CodingStandard\Tests\Fixer\Commenting\RemovePHPStormTodoComme namespace Symplify\CodingStandard\Tests\Fixer\Commenting\RemovePHPStormTodoCommentFixer\Fixture; + // TODO some other notes ?> diff --git a/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/useless_class_comment.php.inc b/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/useless_class_comment.php.inc index 87e95f09f..8679af82b 100644 --- a/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/useless_class_comment.php.inc +++ b/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/useless_class_comment.php.inc @@ -1,6 +1,6 @@ rule(RemoveUselessDefaultCommentFixer::class); - $ecsConfig->rule(StatementIndentationFixer::class); + $ecsConfig->rules([ + BracesFixer::class, + RemoveUselessDefaultCommentFixer::class, + StatementIndentationFixer::class, + ]); }; diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 855f0f8d5..a046756d5 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -21,7 +21,6 @@ define('T_ENUM', 5015); } - // required for PHP_CodeSniffer in packages/EasyCodingStandard/tests/* if (! defined('PHP_CODESNIFFER_VERBOSITY')) { define('PHP_CODESNIFFER_VERBOSITY', 0); @@ -29,7 +28,6 @@ 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/');