This gem will check if source code conforms to some elements of the Github Ruby Style Guidelines (https://github.com/styleguide/ruby) - currently supporting Ruby 2.1.0, but should support 1.9.3 and up (stylr uses the Ripper found in 1.9.3+; in 1.8.7, Ripper has been backported here). Obviously it does not check against the subjective elements of the styleguide.
Kind of raw still. Currently supports checking against the following:
and
or or
operators (&& and || are preferred)then
on a multiline if
/then
constructfor
+
, *
, etc)===
(instead of is_a?
or kind_of?
)!
) operatorOptionally checks for some metaprogramming, which you might not want in a large, enterprise codebase with varied levels of skill on your development team. This is not a condemnation of these practices - most of them are good, idiomatic Ruby. You might not, however, want your junior developers checking in lots of metaprogrammed code. Pass the '--meta' flag to enable these checks.
eval
class_eval
instance_eval
module_eval
define_method
send
def method_missing
def respond_to_missing?
All of these things are configurable via yml. See "stylr.yml" in the repo. Whatever directory you run stylr from will look for stylr.yml.
Checks all *.rb files in the specified directory and subdirectories, excluding _spec.rb and _test.rb
gem install stylr
stylr /path/to/directory
normal checks
stylr /path/to/directory --meta
also check for use of metaprogramming
stylr /path/to/directory --ignore=dir_to_ignore
optionally ignore a particular directory relative to the current directory
Here's what Rake uses to check against the stylr source itself with (launched from the stylr root dir):
stylr . --ignore=spec --ignore=vendor
Please feel free to contribute! There are issues and unimplemented features. I'd love any help I can get. Thanks!