There are 3 options:
Install once, init for each project or run "as-is" to scan custom files.
composer global require alexdesignworks/dcr
dcr install && source ~/.profile
cd your_project_dir
dcr init
Global build status (https://github.com/alexdesignworks/dcr-global-demo):
composer require alexdesignworks/dcr
vendor/bin/dcr install && source ~/.profile
Local build status (https://github.com/alexdesignworks/dcr-demo):
In composer.json
:
{
"minimum-stability": "dev",
"require-dev": {
"alexdesignworks/dcr": "0.1.*"
},
"scripts": {
"post-update-cmd": [
"bash vendor/bin/dcr install"
]
}
}
From previously initialised directory:
dcr
For custom code linting (provided that DCR was installed globally):
dcr file_or_directory
DCR (Drupal Code Review) is a command-line utility to check that produced code follows Drupal coding standards and best practices.
It is a shell script wrapper around PHP_CodeSniffer and JSCS with Drupal-related code sniffs. It uses native and custom 3rd party phpcs
sniffs.
Simply put - convenience. Run code review by only one command dcr
.
- Ease of install:
composer require alexdesignworks/dcr
- Less false-positives: Drupal-specific exceptions allow to have clean DCR output.
- Simple call: no need to call phpcs with tones of confusing parameters. Just use
dcr
. - JS Linting: no need to install standalone JS linter.
- Project-based configuration: use
.dcr.yml
file to configuredcr
for each project and make sure that your teammates are using exactly the same standards.
There was a need in a dead-simple solution to review code using a single command, but also be flexible enough to handle project-based sniff rule customisations and pluggable into a CI pipeline.
DCR installs as a single composer dev dependency either into your project or globally.
DCR contains the following:
- PHP_CodeSniffer with Drupal, Drupal Practice sniffs.
- Additional DCR sniff with more specific Drupal rules that.
- Custom project-related sniff - very handy for any custom inclusions.
- JavaScript code review using JSCS.
- Colour CLI output - easy to spot issues.
Yes. Use it in git pre-commit hook.
Yes. In fact, there is a dcr-demo and dcr-global-demo projects were setup to test dcr
integration.
Yes! If you run dcr fix
it will try to fix code in all files using phpcbf
with your current sniffs configuration.
DCR is just a wrapper around PHP_CodeSniffer and Drupal Coder. It does not add more constrains on the code standards.
Show success and fail status messagesDONEAllow DCR sniffsDONEAllow custom sniffsDONEAutomated fixDONEdcr fix
Allow running only from project root dir or any subdirsDONEAdd JS lintingDONE Using JSCS- Limit files scan to N failed files
- Scan only files changed in current branch comparing to a
main
branch.