Reek configuration and pre-commit hook
Reek is a popular code smell detector for Ruby, which have simple configuration file .reek
.
Git already give as a native configuration .git/hooks/ to do any action after or before git commands like pre-commit
.
My solution to make everything automatic as possible (cause we forget to do lots of stuff if it is become too complicated):
- add reek gem to Gemfile (and do simple bundle install)
- add
.reek
file with reek configurations from example or your own - add
/lib/tasks/pre_commit_hook.rake
and copy code. This is rake task file to create pre-commit hook file in .git/hooks dir. Enough to run 1st time you clone the project you want to configure.
4.git/hooks/pre-commit
file should exist then you run the task mentioned before or you already have it.
How it works?
When you copy all the files just run rake task:
pre_commit_hook:init
- for the first time and follow the instruction if you see any errors.
Easy?!
Now every time you run git commit -m "message"
you will run pre-commit hook script to check code quality.
Some “-“ about this script:
[-]Need to copy files and run rake task (not fully automatic)
[-]if the project already exist and have lots of offences - which files you modify could have the offences from old commits. This means you can fix the offences (yours and existing in the files you changed) or do ignore as mentioned in script.
Some “+” about the script:
[+]One time initialise the script with rake task
[+]Guarantee code quality
[+]Easy to modify reek config and don’t need to change anything else for pre-commit hook
Author: Asta B. (C) 2016
License: Open Source