rubocop-greppable_rails
A collection of RuboCop cops that discourage Rails patterns which obscure where code comes from (helper inclusion, non-inline access modifiers, etc.) — so plain grep stays a useful tool when navigating your codebase.
Installation
Add this line to your application's Gemfile:
gem "rubocop-greppable_rails", require: falseAnd then execute:
bundle installUsage
Register the plugin in your .rubocop.yml:
plugins:
- rubocop-greppable_railsCops
GreppableRails/NoIncludeInHelper
Prohibits include inside helper modules. Including makes it hard to grep where a helper method actually lives, and broadens the constant-dependency surface.
Applies to: app/helpers/**/*.rb.
# bad
module TopHelper
include PostHelper
def some_link(posts)
some_post_link(posts.first)
end
end
# good
module PostLinkTag
module_function
def some_post_link(post)
# ...
end
end
module TopHelper
def some_link(posts)
PostLinkTag.some_post_link(posts.first)
end
endGreppableRails/NoHelperInController
Prohibits helper :name calls at class scope in controllers. Implicit helper inclusion makes the helper method's call site impossible to grep from the controller.
Applies to: app/controllers/**/*.rb.
# bad
class FoosController < ApplicationController
helper :bar
end
# good — call the helper module explicitly where you need it
class FoosController < ApplicationController
def show
@label = BarHelper.label_for(@foo)
end
endGreppableRails/UseInlineAccessModifier
Enforces inline-style access modifiers (private def foo) over group style (private then def foo) and symbol-arg style (private :foo). Inline form makes a method's visibility greppable on the same line as the definition.
# bad
class Foo
private
def bar; end
end
class Foo
def bar; end
private :bar
end
# good
class Foo
private def bar; end
endConfiguration
Each cop accepts the standard RuboCop options (Enabled, Exclude, Include, …). Default Include paths are set in config/default.yml and can be overridden in your project's .rubocop.yml.
Development
After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt.
bundle exec rspec # tests
bundle exec rake # rubocopContributing
Bug reports and pull requests are welcome on GitHub at https://github.com/riseshia/rubocop-greppable_rails.
License
The gem is available as open source under the terms of the MIT License.