Class: ViewComponentCssDsl::Verifier
- Inherits:
-
Object
- Object
- ViewComponentCssDsl::Verifier
- Defined in:
- lib/view_component_css_dsl/verifier.rb
Overview
Static checks over a component’s DSL declarations. Catches the mistakes the DSL itself can’t surface until render time (or surfaces silently). Designed to be fast enough to run on every edit.
The six checks:
class_validity - every declared class exists in the compiled Tailwind output;
catches typos, hallucinated classes, and theme values that
don't exist (requires known_classes:)
self_conflicts - no declaration conflicts with itself; catches e.g.
css "block flex" silently dropping "block"
method_rules - every Symbol in css/data/aria/attribute rules resolves to a
method; catches render-time NoMethodErrors
axes_settable - every axis has an initialize param or @ivar assignment;
catches variant rules that can never fire
variant_matrix - #css builds cleanly for every axis-value combination;
smoke-catches anything the static checks miss, no rendering
template_splat - every template (sidecar, inline erb_template, or manual
#call) references html_attrs; catches components whose DSL
output never reaches the DOM
verifier = ViewComponentCssDsl::Verifier.new(known_classes: oracle)
findings = verifier.verify(ButtonComponent)
Verify every class in the component hierarchy: declaration-shape checks (class validity, self-conflicts) only inspect declarations the class itself added, so a parent’s declarations are checked on the parent, not re-reported on every child.
Defined Under Namespace
Classes: CompiledCssOracle, Finding
Constant Summary collapse
- TEMPLATE_EXTENSIONS =
%w[erb haml slim].freeze
- VARIANT_MATRIX_CAP =
Safety cap for pathological axis cartesian products.
256- DSL_SOURCE_FILE =
Source file of the DSL itself, for classifying smoke-test backtraces.
File.("../view_component_css_dsl.rb", __dir__)
Instance Method Summary collapse
-
#initialize(known_classes: nil) ⇒ Verifier
constructor
known_classes: anything responding to include?(String) — a Set, or a CompiledCssOracle built from your app’s compiled Tailwind output.
- #verify(component) ⇒ Object
Constructor Details
#initialize(known_classes: nil) ⇒ Verifier
known_classes: anything responding to include?(String) — a Set, or a CompiledCssOracle built from your app’s compiled Tailwind output. When nil, the class-validity check is skipped.
55 56 57 |
# File 'lib/view_component_css_dsl/verifier.rb', line 55 def initialize(known_classes: nil) @known_classes = known_classes end |
Instance Method Details
#verify(component) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/view_component_css_dsl/verifier.rb', line 59 def verify(component) check_class_validity(component) + check_self_conflicts(component) + check_method_rules(component) + check_axes_settable(component) + check_variant_matrix(component) + check_template_splat(component) end |