Skip to content

Commit

Permalink
Fix to use new docblock clearing token api in RemoveUselessDefaultCom…
Browse files Browse the repository at this point in the history
…mentFixer (#40)

* Fix to use new docblock clearing token api easy-coding-standard/easy-coding-standard#174

* cs
  • Loading branch information
TomasVotruba committed Feb 14, 2024
1 parent c40feb1 commit 3f38152
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 62 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);
34 changes: 6 additions & 28 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,13 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_82,
SetList::CODE_QUALITY,
SetList::DEAD_CODE,
SetList::CODING_STYLE,
SetList::TYPE_DECLARATION,
SetList::NAMING,
SetList::PRIVATIZATION,
SetList::EARLY_RETURN,
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
PHPUnitSetList::PHPUNIT_100,
]);

$rectorConfig->paths([
__DIR__ . '/config',
__DIR__ . '/src',
__DIR__ . '/tests',
]);

$rectorConfig->importNames();

$rectorConfig->skip([
'*/scoper.php',
return RectorConfig::configure()
->withPaths([__DIR__ . '/config', __DIR__ . '/src', __DIR__ . '/tests'])
->withPhpSets()
->withPreparedSets(codeQuality: true, codingStyle: true, naming: true, earlyReturn: true, privatization: true)
->withImportNames(removeUnusedImports: true)
->withSkip([
'*/Source/*',
'*/Fixture/*',
]);
};
15 changes: 9 additions & 6 deletions src/Fixer/Commenting/RemoveUselessDefaultCommentFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public function isCandidate(Tokens $tokens): bool
return $tokens->isAnyTokenKindsFound([T_DOC_COMMENT, T_COMMENT]);
}

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

/**
* @param Tokens<Token> $tokens
*/
Expand All @@ -63,13 +69,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
3 changes: 1 addition & 2 deletions src/Fixer/Spacing/StandaloneLineConstructorParamFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Symplify\CodingStandard\Fixer\Spacing;

use PhpCsFixer\Fixer\Basic\BracesFixer;
use PhpCsFixer\FixerDefinition\FixerDefinition;
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
use PhpCsFixer\Tokenizer\Token;
Expand Down Expand Up @@ -36,7 +35,7 @@ public function __construct(
/**
* Must run before
*
* @see BracesFixer::getPriority()
* @see \PhpCsFixer\Fixer\Basic\BracesFixer::getPriority()
*/
public function getPriority(): int
{
Expand Down
3 changes: 1 addition & 2 deletions src/Fixer/Spacing/StandaloneLinePromotedPropertyFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Symplify\CodingStandard\Fixer\Spacing;

use PhpCsFixer\Fixer\Basic\BracesFixer;
use PhpCsFixer\FixerDefinition\FixerDefinition;
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
use PhpCsFixer\Tokenizer\CT;
Expand Down Expand Up @@ -37,7 +36,7 @@ public function __construct(
/**
* Must run before
*
* @see BracesFixer::getPriority()
* @see \PhpCsFixer\Fixer\Basic\BracesFixer::getPriority()
*/
public function getPriority(): int
{
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 3f38152

Please sign in to comment.