I recently worked on a site with a tremendous amount of technical debt and wanted to set up code validation for the project. Fixing all of the code violations up front would have been prohibitively time consuming, so I decided that we should do it gradually. Each time that a developer made a change to a file, that particular file would be code sniffed. I wanted to enforce this rule with a check that would be run by our continuous integration server. Here is the command that I came up with:
git diff-tree --no-commit-id --name-only -r HEAD | xargs ./vendor/bin/phpcs -v --standard=./vendor/drupal/coder/coder_sniffer/Drupal/ruleset.xml --extensions='module,inc,install,profile,test,info'
If you'd like this to apply only to a specific directory, like
*/modules/custom, pipe the changed files through grep: