A collection of modules for which every is designed to check syntax in files to be commited via git.
Checker works with rubies ree, 1.8.7, 1.9.2, 1.9.3 and 2.0.0 - all of those are tested on Travis. As for Rails with SASS - tested with RoR 3.2.x
Checker is available in rubygems (current stable version is 0.6.6), so you just need to do:
gem install checker
If you are using bundler, you can add it to your project via
Gemfile file (best to put it under
Since checker is a command-line utility, there is no need to load it up in the application:
group :development do gem 'checker', :require => false end
After installing the gem please follow Git hook section for further details.
All you need to do is type in
checker install and it will automatically install the prepare-commit-msg hook
to your current git project. It will look something like this:
#!/bin/bash #### Begin of checker script if [ -f /Users/user/.rvm/bin/rvm-shell ]; then /Users/user/.rvm/bin/rvm-shell 'ruby-1.9.3-p286' -c 'checker' else checker fi if [ $? = 1 ]; then exit 1 fi text=`echo -n ':ok: '; cat $1` echo "$text" > $1 #### End of checker script
If you don't want your commits be prepended by checkered flag you can remove two last lines from the prepare-commit-msg hook.
Now checker will halt the commit if it finds problem with source code. Couple examples:
[ PRY - 1 files ] Checking app/models/user.rb... [FAIL] 46:binding.pry
[ CONFLICT - 1 files ] Checking a.bad.scss... [FAIL] 4:<<<<<<< Updated upstream 30:>>>>>>> Stashed changes
[ SASS - 1 files ] Checking a.bad.scss... [FAIL] Syntax error: Invalid CSS after "qwe:": expected pseudoclass or pseudoelement, was "asd:" on line 1 of .checker-cache/3cc74408b797b92e79207a64d97ae429 Use --trace for backtrace.
You can specify checker behaviour for your project by changing the git config for checker. Available options are:
List of modules, seperated by comma, which checker will use. Defaults to all modules. Example:
git config checker.check 'ruby, haml, coffeescript'
Boolean value. If given false, checker will not commit when any module returns warning. Defaults to true. Example:
git config checker.commit-on-warning 'false'
Boolean value. Will use rails runner to check for sass syntax using sprockets. Works work rails >= 3.1. Defaults to true. Example:
git config checker.rails-for-sass 'true'
Checks for correct syntax in ruby (.rb) files
Checks for correct syntax in haml files
Checks for any occurence of
Checks for correct syntax in coffeescript (.coffee) files
Checks for correct syntax in sass and scss files
Checks for correct syntax in slim files
Checks for any occurence of git conflicts when merging (looks for
Checks for if code follows the style guides ( https://github.com/bbatsov/rubocop )
For various modules to work you may need to install additional dependencies:
- coffeescript -
npm install -g coffee-script- see https://github.com/jashkenas/coffee-script/
- haml & sass & slim -
gem install haml sass slim
- rubocop -
gem install rubocop
Copyright (c) 2015 Netguru. See LICENSE for further details.