class ViewComponent::Compiler
def template_errors
Experimental RBS support (using type sampling data from the type_fusion
project).
def template_errors: () -> untyped
This signature was generated using 1 sample from 1 application.
def template_errors @__vc_template_errors ||= begin errors = [] if (templates + inline_calls).empty? && !has_inline_template? errors << "Couldn't find a template file or inline render method for #{component_class}." end if templates.count { |template| template[:variant].nil? } > 1 errors << "More than one template found for #{component_class}. " \ "There can only be one default template file per component." end invalid_variants = templates .group_by { |template| template[:variant] } .map { |variant, grouped| variant if grouped.length > 1 } .compact .sort unless invalid_variants.empty? errors << "More than one template found for #{"variant".pluralize(invalid_variants.count)} " \ "#{invalid_variants.map { |v| "'#{v}'" }.to_sentence} in #{component_class}. " \ "There can only be one template file per variant." end if templates.find { |template| template[:variant].nil? } && inline_calls_defined_on_self.include?(:call) errors << "Template file and inline render method found for #{component_class}. " \ "There can only be a template file or inline render method per component." end duplicate_template_file_and_inline_variant_calls = templates.pluck(:variant) & variants_from_inline_calls(inline_calls_defined_on_self) unless duplicate_template_file_and_inline_variant_calls.empty? count = duplicate_template_file_and_inline_variant_calls.count errors << "Template #{"file".pluralize(count)} and inline render #{"method".pluralize(count)} " \ "found for #{"variant".pluralize(count)} " \ "#{duplicate_template_file_and_inline_variant_calls.map { |v| "'#{v}'" }.to_sentence} " \ "in #{component_class}. " \ "There can only be a template file or inline render method per variant." end uniq_variants = variants.compact.uniq normalized_variants = uniq_variants.map { |variant| normalized_variant_name(variant) } colliding_variants = uniq_variants.select do |variant| normalized_variants.count(normalized_variant_name(variant)) > 1 end unless colliding_variants.empty? errors << "Colliding templates #{colliding_variants.sort.map { |v| "'#{v}'" }.to_sentence} " \ "found in #{component_class}." end errors end end