Using coder.module to auto-format your code with drush
Last updated on
20 October 2018
Coder.module comes with a couple of drush plugins that let you repair things directly from the commandline - a great thing to try before committing new code!
- First install coder and its required libraries onto your system
- It's still not possible to run drush:coder commands stand-alone, so you should also install coder.module directly on your target site and enable it (this can be temporary).
cd path/to/your/site/folder drush dl coder drush en -y coder
-
It's a good start to RTFM.
drush help | grep coder
coder-format Re-format and rewrite code according Drupal coding standards. coder-review (coder, Run code reviews
- Before letting an automated tool lose on your code the first time, you may like to back up or (better) commit the current version of your code to source control before proceeding!
- Run it and see what happens
drush coder-format sites/all/modules/custom/{$modulename}
... It should have just done it for you. Your code is magically better!
- If you had source control, you can now check out what it did.
cd ../all/modules/custom/{$modulename} git diff
It's usually just whitespace, but to a visual review each time.
Bravo, your code is now up-to-standard.
For Drupal 8.x see the new Drupal Console for some similar functions.
Help improve this page
Page status: No known problems
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion