Apply automatic fixes on your Drupal code.
https://www.palantir.net/blog/jumpstart-your-drupal-9-upgrade-drupal-rector
https://www.drupal.org/project/rector
Install the library inside a drupal project.
$ composer require --dev palantirnet/drupal-rector
Create a rector.yml file in the Drupal root.
imports:
- { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8-all-deprecations.yml" }
# includes:
# - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.5-deprecations.yml" }
# - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.6-deprecations.yml" }
# - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.7-deprecations.yml" }
parameters:
autoload_paths:
- 'web/core'
- 'web/core/modules'
- 'web/modules'
- 'web/profiles'
file_extensions:
- module
- theme
- install
- profile
- inc
- engine
services: ~
- Analyze your code with Rector and review suggested changes:
$ vendor/bin/rector process web/modules/contrib/[YOUR_MODULE] --dry-run
- Apply suggested changes:
$ vendor/bin/rector process web/modules/contrib/[YOUR_MODULE]
- Automatically correct code style violations with PHPCBF:
$ vendor/bin/phpcbf --standard=web/core/phpcs.xml.dist web/modules/contrib/[YOUR_MODULE] -s --colors
- Look for remaining code style violations with PHPCS:
$ vendor/bin/phpcs --standard=web/core/phpcs.xml.dist web/modules/contrib/[YOUR_MODULE] -s --colors
- Run automated tests to ensure the optimized code is still correct:
$ vendor/bin/phpunit -c web/core --printer="\Drupal\Tests\Listeners\HtmlOutputPrinter" -v --debug web/modules/contrib/[YOUR_MODULE]/tests
You can find more information about Rector here.
We recommend using our drupal-rector-sandbox
development environment https://github.com/palantirnet/drupal-rector-sandbox
Alternatively, you can use your existing Drupal project and follow the instructions in README
This is just a POC at this moment but it has a great potential to become an actual development tool for Drupal 8.
Do you have an idea about what else this tool could do? Please share it in the issue queue. Pull requests are also warmly welcomed!
Initial development is sponsored by Pronovix.
Additional development is sponsored by Palantir.net.