Project

stylr

0.0
No commit activity in last 3 years
No release in over 3 years
An attempt at enforcing https://github.com/styleguide/ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
>= 0

Runtime

>= 5.2.0, ~> 5.2
 Project Readme

stylr

a Ruby styleguide enforcer

[![Build Status](https://travis-ci.org/yaaase/stylr.png?branch=master)](https://travis-ci.org/yaaase/stylr) [![Dependency Status](https://gemnasium.com/yaaase/stylr.png)](https://gemnasium.com/yaaase/stylr)

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 or or operators (&& and || are preferred)
  • Use of then on a multiline if/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 of is_a? or kind_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!