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 1f353a5
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 30 deletions.
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
17 changes: 5 additions & 12 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
16 changes: 10 additions & 6 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,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");
}
}

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 1f353a5

Please sign in to comment.