Skip to content

Commit

Permalink
[docs] getRuleDefinition() no longer required for custom rules (#6440)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba authored Nov 15, 2024
1 parent 4d3f35f commit 9cd6376
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
36 changes: 36 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,39 @@ final class SimpleRector extends AbstractRector
}
}
```


### 2. `AbstractRector` get focused on code, the `getRuleDefinition()` is no longer required

Core rules need documentation, so people can read their feature and [search through](https://getrector.com/find-rule) them. Yet for writing custom rules and local rules, its not necessary. People often filled it empty, just to make Rector happy.

This is no longer needed. Now The `getRuleDefinition()` method has been removed:

```diff
use Rector\Rector\AbstractRector;
-use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
-use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

final class SimpleRector extends AbstractRector
{
- public function getRuleDefinition(): RuleDefinition
- {
- return new RuleDefinition('// @todo fill the description', [
- new CodeSample(
- <<<'CODE_SAMPLE'
-// @todo fill code before
-CODE_SAMPLE
- ,
- <<<'CODE_SAMPLE'
-// @todo fill code after
-CODE_SAMPLE
- ),
- ]);
- }

// valuable code here
}
```

If you need description yourself to understand rule after many months, use the common place for documentation - docblock above class.

17 changes: 0 additions & 17 deletions templates/custom-rule/utils/rector/src/Rector/__Name__.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,12 @@

use PhpParser\Node;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

/**
* @see \Rector\Tests\TypeDeclaration\Rector\__Name__\__Name__Test
*/
final class __Name__ extends AbstractRector
{
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('// @todo fill the description', [
new CodeSample(
<<<'CODE_SAMPLE'
// @todo fill code before
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
// @todo fill code after
CODE_SAMPLE
),
]);
}

/**
* @return array<class-string<Node>>
*/
Expand Down

0 comments on commit 9cd6376

Please sign in to comment.