Sha256: c29aeedcc79a83d966fba57a779f2a0145dea9dfc0646905733304e0fb8f9129
Contents?: true
Size: 1.12 KB
Versions: 18
Compression:
Stored size: 1.12 KB
Contents
# frozen_string_literal: true module ThemeCheck class TemplateLength < LiquidCheck severity :suggestion category :liquid doc docs_url(__FILE__) def initialize(max_length: 600, exclude_schema: true, exclude_stylesheet: true, exclude_javascript: true) @max_length = max_length @exclude_schema = exclude_schema @exclude_stylesheet = exclude_stylesheet @exclude_javascript = exclude_javascript end def on_document(_node) @excluded_lines = 0 end def on_schema(node) exclude_node_lines(node) if @exclude_schema end def on_stylesheet(node) exclude_node_lines(node) if @exclude_stylesheet end def on_javascript(node) exclude_node_lines(node) if @exclude_javascript end def after_document(node) lines = node.theme_file.source.count("\n") - @excluded_lines if lines > @max_length add_offense("Template has too many lines [#{lines}/#{@max_length}]", theme_file: node.theme_file) end end private def exclude_node_lines(node) @excluded_lines += node.value.nodelist.join.count("\n") end end end
Version data entries
18 entries across 18 versions & 1 rubygems