-
-
Notifications
You must be signed in to change notification settings - Fork 699
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
Can I still add my own, project-specific rules easily? #6404
Comments
There are few namespaces that are not prefixed - typically Rector, PHPParser and PHPStan: If you need some extra classes, they have to be required in your custom package The goal of prefixing is to avoid conflict with Symfony, Nette, Doctrine etc. conflicts of Rector and your project. |
@mpdude I would say, this should be possible most of the time, not only theoretically ;-) |
The rule of thumb is the same with your project. If you need e.g. YAML component in your code, you should not hope some of existing dependencies already requires it :) You should require it in your |
Take a look at the namespace imports in the example/documentation: use Nette\Utils\Strings;
use PhpParser\Node;
use PhpParser\Node\Identifier;
use PhpParser\Node\Expr\MethodCall;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; Strictly speaking, when I write a rule like in the example, I'd need to declare all packages as ( So... should I require all the relevant packages? For example, Conversely, Oh, and regarding which classes Rector brings along and/or prefixes: Is that part of the API of Rector, i. e. can I rely on that list not to change on minor version updates? |
For |
For This one is handled by |
Maybe, i don´t get it right now, but why do we need a changing prefix? Why not have a fixed prefixed so a 3rd party consumer can rely on prefixed classes? |
For me it is quite hard to benefit from the prefixed version right now. I have to require a lot of packages which are already part of rector itself and some things don´t went smoothly. I.e. if i am requiring the rector/rector-generator package the function service from the symfony/dependency-injection container cannot be found / autoloaded anymore. |
To be honest, it's mostly a convention. Another reason might be composer internals, that autoload might not get triggered propperly... but that's just my rought assumption. Saying that, we can give it a try :) |
This should be working. That's a bug |
Closing as answered. tl;dr; If you write your own rules with packages that used to be in Rector but now are scoped, there packages have to be required in your project explicitly. Same way you need to require packages in your app to make sure the class is there. |
rectorphp/rector-src@d246d27 [CodeQuality] Skip multiple lines on JoinStringConcatRector (#6404)
rectorphp/rector-src@d246d27 [CodeQuality] Skip multiple lines on JoinStringConcatRector (#6404)
Now that Rector comes prefixed by default, I wonder if I can still add new rules easily as described in https://github.com/rectorphp/rector/blob/main/docs/create_own_rule.md.
I mean – when my project just declares
rector/rector
as adev
dependency, all the classes that are imported in the example code given are prefixed/namespaced, right?How can this even work, am I missing something?
The text was updated successfully, but these errors were encountered: