Class: RuboCop::Cop::ViewComponent::ComponentSuffix

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

Overview

Enforces that ViewComponent classes end with the ‘Component` suffix.

Examples:

# bad
class FooBar < ViewComponent::Base
end

# good
class FooBarComponent < ViewComponent::Base
end

Constant Summary collapse

MSG =
"ViewComponent class names should end with `Component`."

Instance Method Summary collapse

Methods included from Base

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

Instance Method Details

#on_class(node) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/rubocop/cop/view_component/component_suffix.rb', line 22

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

  class_name = node.identifier.source
  return if class_name.end_with?("Component")

  add_offense(node.identifier)
end