Class: RuboCop::Cop::ViewComponent::PreferComposition
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::ViewComponent::PreferComposition
- Includes:
- Base
- Defined in:
- lib/rubocop/cop/view_component/prefer_composition.rb
Overview
Detects ViewComponent classes that inherit from another component instead of using composition. Inheriting one component from another causes confusion when each has its own template.
Constant Summary collapse
- MSG =
"Avoid inheriting from another ViewComponent."
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
25 26 27 28 29 30 31 32 |
# File 'lib/rubocop/cop/view_component/prefer_composition.rb', line 25 def on_class(node) parent_class = node.parent_class return unless parent_class return if view_component_parent?(parent_class) return unless component_like_parent?(parent_class) add_offense(parent_class) end |