Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dx] Allow external rules without getRuleDefinition() to make them easier to write #6438

Merged
merged 2 commits into from
Nov 15, 2024

Conversation

TomasVotruba
Copy link
Member

@TomasVotruba TomasVotruba commented Nov 15, 2024

We use getRuleDefinition() internally to allow easy search in 400+ rules - https://getrector.com/find-rule

But for the community/private projects, it's been only burden that is filled with lorem ipsun.
This patch requires docs for us and our packages, but drops the requirements for community to make writing custom rules easier 👍

@TomasVotruba TomasVotruba changed the title tv no definition custom rules [dx] Allow external rules without getRuleDefinition() to make them easier to write Nov 15, 2024
@TomasVotruba TomasVotruba merged commit 418423d into main Nov 15, 2024
36 checks passed
@TomasVotruba TomasVotruba deleted the tv-no-definition-custom-rules branch November 15, 2024 10:53
@samsonasik
Copy link
Member

Ref patch on website rectorphp/getrector-com@e9dbf78

@TomasVotruba
Copy link
Member Author

Thanks 👍

}

// comment out
return str_replace('public function getRuleDefinition', '// public function getRuleDefinition', $content);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TomasVotruba instead of commenting out, I think it is better to have default empty getRuleDefinition in AbstractRector, eg:

abstract class AbstractRector extends NodeVisitorAbstract implements RectorInterface
{
    public function getRuleDefinition(): RuleDefinition
    {
        return new RuleDefinition('', []);
    }
}

wdyt? It doesn't enforce user to create it, but can create if they want to :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants