house9

random code and what not

rubocop script for your modified files

| Comments

Our CI server is setup to run rubocop (ruby linter) after every checkin. On my local development machine I prefer to lint files that have recently changed and not the entire code base.

Add this code to a shell script and it will lint all files that have been staged. Note it uses the autofix rubocop option, optionally you could run it on non-staged files without the autofix flag.

1
git diff --name-only --cached | grep '\.rb' | xargs rubocop -a

Don’t forget to git add . after rubocop finds/fixes any code style violations in your staged files.

Comments