stylr
a Ruby styleguide enforcer
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:
- Line length (user-configurable)
- Missing parens around method definitions with parameters (ie, "def foo bar" is disallowed)
- Trailing whitespace of any kind
- Use of the
and
oror
operators (&& and || are preferred) - Use of
then
on a multilineif
/then
construct - Spacing around parens
- Spacing around brackets
- Spacing around curly braces
- Using the keyword
for
- Spacing around commas
- Using tab characters instead of soft tabs
- Spacing around math operators (
+
,*
, etc) - Use of
===
(instead ofis_a?
orkind_of?
) - Spacing after the negation (
!
) operator - Nesting of (one-line) ternary expressions
Optionally 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
Usage
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
Contributing
Please feel free to contribute! There are issues and unimplemented features. I'd love any help I can get. Thanks!