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] "generate" command should generate files in specific set #4875

Closed
simivar opened this issue Dec 13, 2020 · 8 comments · Fixed by #4882
Closed

[DX] "generate" command should generate files in specific set #4875

simivar opened this issue Dec 13, 2020 · 8 comments · Fixed by #4882
Labels

Comments

@simivar
Copy link
Contributor

simivar commented Dec 13, 2020

Feature Request

When you run generate command it only asks a question about composer.json and generates all files in the default set:

 * rules/utils/src/Rector/MethodCall/RenameMethodCallRector.php
 * rules/utils/tests/Rector/MethodCall/RenameMethodCallRector/Fixture/fixture.php.inc
 * rules/utils/tests/Rector/MethodCall/RenameMethodCallRector/RenameMethodCallRectorTest.php

What I would like as a person working on a new Rectors is to get more questions about, for example, "bundle" for which the Rector should be created as well the name. As well we could check if the "bundle" (here: symfony5) exists and if not add it to composer.json by default without asking question.

Expected result

* rules/symfony5/src/Rector/New_/PropertyAccessorCreationBooleanToFlagsRector.php
* rules/symfony5/tests/Rector/New_/PropertyAccessorCreationBooleanToFlagsRector.php
* rules/symfony5/tests/Rector/New_/Fixture/fixture.php

@TomasVotruba
Copy link
Member

TomasVotruba commented Dec 13, 2020

If you're using Rector as dependency, then it's correct.

If you're contributing our repository, that would be a bug. But that's weird, because it worked for last 450 rules correctly.

In the latter case, please provide GitHub Actions job, that shows this problem.

@simivar
Copy link
Contributor Author

simivar commented Dec 13, 2020

I work as a contributor on our repository and I run:

  1. bin/rector init-recipe
  2. bin/rector generate

Doing that the second command only asks one question and generates rules in utils.

@TomasVotruba
Copy link
Member

I see. That's because the "package" has to be changed to "Symfony5" first.

I'll move the category up, so it's harder to miss.

@simivar
Copy link
Contributor Author

simivar commented Dec 14, 2020

What do you think about moving away from rector-recipe.php configuration file to just asking questions after running generate command? If you work on multiple rules from different "packages" it would be easier.

What I mean is that you run generate command and get questions:

  1. Package of the recipe:
  2. Name of the recipe:
  3. Description:
  4. Nodes for which recipe should be run (multiple possible):
  5. Set:

Something similar to running bin/console make:entity from Maker Bundle

@TomasVotruba
Copy link
Member

TomasVotruba commented Dec 14, 2020

Sounde doable. How would it include code samples that are used for RuleDefinition and test fixture?

To avoid mixing 2 behavior, there should be option to invoke Q&A behavior:

generate -i
generate --interactive

In that case we can accept it. Are you willing to contribute it?

@simivar
Copy link
Contributor Author

simivar commented Dec 14, 2020

Sure. Could you point me to the place where the current generate command source code is located?

I would generate then some dummy CodeSamples that would have to be changed by hand, unfortunately. I don't see any other solution.

@TomasVotruba
Copy link
Member

We respect simple command naming convention, so "generate + comand" will find the class:

I would generate then some dummy CodeSamples that would have to be changed by hand, unfortunately. I don't see any other solution.

👍 If it's documented here https://github.com/rectorphp/rector/blob/master/docs/rector_recipe.md, it should be ok

@TomasVotruba
Copy link
Member

Hi, I'm thinking about way how to make Rector simpler and less ambiguous. We've got a feedback about its complexity and try to drop everything that is not neccessary, so 95 % of users can learn it faster and with less know-how.

I've just realized we have this feature that I never used and I wanted to ask about your experience with it. How is usage of this feature?

TomasVotruba added a commit that referenced this issue Aug 28, 2023
rectorphp/rector-src@c03fd2a [Performance] Avoid spl_object_hash() when has origNode attribute on AbstractRector::leaveNode() (#4875)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants