Skip to content

Instantly share code, notes, and snippets.

@clrockwell
Last active April 9, 2019 18:32
Show Gist options
  • Save clrockwell/6356d2bf4137469b8be448f733b86849 to your computer and use it in GitHub Desktop.
Save clrockwell/6356d2bf4137469b8be448f733b86849 to your computer and use it in GitHub Desktop.
Use PHP CodeSniffer on only changed files
  • Follow instructions at https://www.drupal.org/node/1419988 to install PHPCS using composer (do it globally)
  • Save git-cs to a location in your current path (echo $PATH); I used /usr/local/sbin
  • Update permissions: chmod u+x /usr/local/sbin/git-cs
  • From your project directory, run git-cs to test changed files against Drupal coding standard

@todo - It would be nice to have this in a pre-commit hook so it's automatically run before a commit is made.

#!/bin/bash
files=$(git ls-files -om --exclude-standard)
phpcs --standard=DrupalPractice $files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment