Class: RuboCop::Cop::Sequra::NoHelpers

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/sequra/no_helpers.rb

Overview

Flags any module or class defined under an app/helpers/ directory.

Rails helpers are globally mixed into every view, so they have no owner, no boundary and nothing to unit test. Display logic belongs to presenters (view context), formatters (pure data transformation) and calculators (derived values).

The check is path-based, not name-based: a class named RoutingHelper outside app/helpers/ is fine, and anything inside it is not. Any nesting depth is covered, so pack and nested-pack helper directories are caught too.

Examples:

# bad - app/helpers/foo_helper.rb, packs/my_pack/app/helpers/foo_helper.rb
module FooHelper
  def label(order) = order.reference
end

# good - app/presenters/foo_presenter.rb
class FooPresenter
  def label = order.reference
end

Constant Summary collapse

MSG =
"Do not create helpers. Use presenters, formatters, or calculators instead."
HELPER_PATH =
%r{(^|/)app/helpers/}

Instance Method Summary collapse

Instance Method Details

#on_class(node) ⇒ Object



35
36
37
# File 'lib/rubocop/cop/sequra/no_helpers.rb', line 35

def on_class(node)
  add_offense(declaration_range(node)) if helper_file?
end

#on_module(node) ⇒ Object



31
32
33
# File 'lib/rubocop/cop/sequra/no_helpers.rb', line 31

def on_module(node)
  add_offense(declaration_range(node)) if helper_file?
end