Class: RuboCop::Cop::ViewComponent::PreferPrivateMethods

Inherits:
Base
  • Object
show all
Includes:
Base, TemplateAnalyzer
Defined in:
lib/rubocop/cop/view_component/prefer_private_methods.rb

Overview

Suggests making helper methods private in ViewComponents.

Examples:

# bad
class CardComponent < ViewComponent::Base
  def formatted_title
    @title.upcase
  end
end

# good
class CardComponent < ViewComponent::Base
  private

  def formatted_title
    @title.upcase
  end
end

Constant Summary collapse

MSG =
"Consider making `%<method_name>s` private. " \
"Only ViewComponent interface methods should be public."

Instance Method Summary collapse

Methods included from TemplateAnalyzer

#extract_method_calls, #template_paths_for

Methods included from Base

#enclosing_class, #inside_view_component?, #view_component_class?, #view_component_parent?

Instance Method Details

#on_class(node) ⇒ Object



34
35
36
37
38
# File 'lib/rubocop/cop/view_component/prefer_private_methods.rb', line 34

def on_class(node)
  return unless view_component_class?(node)

  check_public_methods(node)
end