Class: GLRubocop::GLCops::ViewComponentInheritance
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- GLRubocop::GLCops::ViewComponentInheritance
- Defined in:
- lib/gl_rubocop/gl_cops/view_component_inheritance.rb
Overview
This cop checks that all ViewComponent classes inherit from an allowlisted base class.
Good:
class Components::HeroComponent < ApplicationViewComponent
end
class Components::CardComponent < ViewComponent::Base
end
Bad:
class Components::HeroComponent < ViewComponent
end
class Components::CardComponent
end
Constant Summary collapse
- INHERITANCE_MSG =
'ViewComponent must inherit from ApplicationViewComponent'.freeze
Instance Method Summary collapse
Instance Method Details
#on_class(node) ⇒ Object
21 22 23 24 25 |
# File 'lib/gl_rubocop/gl_cops/view_component_inheritance.rb', line 21 def on_class(node) return true if inherits_from_application_view_component(node) add_offense(node, message: INHERITANCE_MSG) end |