Shell script wrapper around PHP_CodeSniffer and JSCS
Installs: 12 914
Dependents: 1
Suggesters: 0
Security: 0
Stars: 32
Watchers: 2
Forks: 5
Open Issues: 10
Language:Shell
Requires
- php: >=5.3.9
- drupal/coder: ~8.2
- mouf/nodejs-installer: ~1.0
This package is not auto-updated.
Last update: 2022-02-01 12:57:10 UTC
README
Bring all your code review dependencies with one command!
Installation
There are 3 options:
1. Global installation
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):
2. Local per-project installation
composer require alexdesignworks/dcr
vendor/bin/dcr install && source ~/.profile
Local build status (https://github.com/alexdesignworks/dcr-demo):
3. Install as composer dependency for specific project:
In composer.json
:
{ "minimum-stability": "dev", "require-dev": { "alexdesignworks/dcr": "0.1.*" }, "scripts": { "post-update-cmd": [ "bash vendor/bin/dcr install" ] } }
Usage
From previously initialised directory:
dcr
For custom code linting (provided that DCR was installed globally):
dcr file_or_directory
FAQ
What is it?
DCR (Drupal Code Review) is a command-line utility to check that produced code follows Drupal coding standards and best practices.
More specifically
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.
Why should I use it?
Simply put - convenience. Run code review by only one command dcr
.
Why does it exist?
- 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.
Why is it a separate tool?
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.
Can it automatically review code on commit?
Yes. Use it in git pre-commit hook.
Can it be used as a part of automated build?
Yes. In fact, there is a dcr-demo and dcr-global-demo projects were setup to test dcr
integration.
Does it automatically fix code?
Yes! If you run dcr fix
it will try to fix code in all files using phpcbf
with your current sniffs configuration.
So, what about PHP_CodeSniffer and Drupal Coder module?
DCR is just a wrapper around PHP_CodeSniffer and Drupal Coder. It does not add more constrains on the code standards.
Roadmap
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.