Class: RuboCop::Cop::ViewComponent::MissingPreview
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::ViewComponent::MissingPreview
- Includes:
- Base
- Defined in:
- lib/rubocop/cop/view_component/missing_preview.rb
Overview
Ensures that every ViewComponent has a corresponding preview file.
Looks for previews in the configured PreviewPaths, supporting both
naming conventions: user_preview.rb and user_component_preview.rb.
Constant Summary collapse
- MSG =
"No preview found for %<component>s (looked in: %<paths>s)."
Constants included from Base
Instance Method Summary collapse
Methods included from Base
#component_namespaces, #enclosing_class, #fully_qualified_name, #inside_view_component?, #require_project_index!, #view_component_class?, #view_component_parent?, #view_component_parent_class?
Instance Method Details
#on_class(node) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/rubocop/cop/view_component/missing_preview.rb', line 18 def on_class(node) return unless view_component_class?(node) return if view_component_parent_class?(node) class_name = fully_qualified_name(node) return if preview_exists?(class_name) add_offense(node.identifier, message: format(MSG, component: class_name, paths: preview_paths.join(", "))) end |