-
Notifications
You must be signed in to change notification settings - Fork 277
How to write your own check list
For example, if we want to add our own check “Use try”.
1. add rails_best_practices to your Gemfile, it would be better to put it into test group.
https://github.com/railsbp/rails-bestpractices.com/blob/master/Gemfile
2. add a rspec for the check first at spec/rails_best_practices/plugins/reviews/use_try_review_spec.rb
https://github.com/railsbp/rails-bestpractices.com/blob/master/spec/rails_best_practices/plugins/reviews/use_try_review_spec.rb
for your tests, you should at least write two cases, one is violation case, the other is correct one.
3. add a check file at lib/rails_best_practices/plugins/reviews/use_try_review.rb
https://github.com/railsbp/rails-bestpractices.com/blob/master/lib/rails_best_practices/plugins/reviews/use_try_review.rb
interesting_nodes
indicates what sexp node types this check file is interested.
interesting_files
indicates what files the check file is interested, default is all files.
start_xxx(node)
will be executed at the beginning of parsing xxx node type.
end_xxx(node)
will be executed at the end of parsing xxx node type.
4. run rspec spec/rails_best_practices/plugins/reviews/use_try_review_spec.rb
again, you will see the tests passed.
5. finally run rails_best_practices
, you will see the “Use try” check takes effect. Cool!