Skip to content

[DX] Add version-based set loading based on installed package version#6428

Merged
TomasVotruba merged 3 commits intomainfrom
tv-try-it
Nov 13, 2024
Merged

[DX] Add version-based set loading based on installed package version#6428
TomasVotruba merged 3 commits intomainfrom
tv-try-it

Conversation

@TomasVotruba
Copy link
Copy Markdown
Member

@TomasVotruba TomasVotruba commented Nov 13, 2024

Follow up to #5976

Packages that ship lot of versions, can have lot of sets to apply. E.g. twig/twig has 6 sets in Rector, couple for v1 and couple for v2. At the moment, those sets have to be added manually to run.

return RectorConfig::configure()
    ->withSets([
        \Rector\Symfony\Set\TwigSetList::TWIG_112,
        \Rector\Symfony\Set\TwigSetList::TWIG_127,
        \Rector\Symfony\Set\TwigSetList::TWIG_134,
        \Rector\Symfony\Set\TwigSetList::TWIG_20,
        \Rector\Symfony\Set\TwigSetList::TWIG_24,
    ])

This is wrong for couple reasons

  • we have to always check if there is a new set we should add here
  • if we use Twig 2, there is no point in running Twig 1 sets - they also may cause error, as syntax evolves
  • if we use Twig 1.20, we don't want 1.40 sets to run as they might break the code

What should happen instead?

  • Rector should look into installed composer.json version of twig/twig
  • then check all Twig sets, find those that make sense to apply
  • run those

If we upgrade to Twig 3 later on, Rector should pick up sets for Twig 3 for us. We should not maintain the rector.php at all.

Introducing withComposerBased() 🎉

return RectorConfig::configure()
    ->withComposerBased(twig: true)

Rector will go through all Twig sets, check our installed version and apply only sets relevant to our specific version ✔️

@TomasVotruba TomasVotruba changed the title tv try it [config] Add version-based set loading, use composer semver Nov 13, 2024
@TomasVotruba TomasVotruba force-pushed the tv-try-it branch 3 times, most recently from faa3d27 to b87e654 Compare November 13, 2024 10:15
@TomasVotruba TomasVotruba marked this pull request as draft November 13, 2024 10:26
@TomasVotruba TomasVotruba changed the title [config] Add version-based set loading, use composer semver [DX] Add version-based set loading based on installed package version Nov 13, 2024
@TomasVotruba TomasVotruba merged commit 006f215 into main Nov 13, 2024
@TomasVotruba TomasVotruba deleted the tv-try-it branch November 13, 2024 13:15
@TomasVotruba TomasVotruba mentioned this pull request Nov 13, 2024
@staabm
Copy link
Copy Markdown
Contributor

staabm commented Nov 13, 2024

nice 👍

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