Sha256: 2cd4b3277d0cfe733641ef66d4d498cd60d93441a2e686f0d2eb83a7939a59d8

Contents?: true

Size: 743 Bytes

Versions: 5

Compression:

Stored size: 743 Bytes

Contents

# frozen_string_literal: true
module ThemeCheck
  class TemplateLength < LiquidCheck
    severity :suggestion
    category :liquid
    doc docs_url(__FILE__)

    def initialize(max_length: 200, exclude_schema: true)
      @max_length = max_length
      @exclude_schema = exclude_schema
    end

    def on_document(_node)
      @excluded_lines = 0
    end

    def on_schema(node)
      if @exclude_schema
        @excluded_lines += node.value.nodelist.join.count("\n")
      end
    end

    def after_document(node)
      lines = node.template.source.count("\n") - @excluded_lines
      if lines > @max_length
        add_offense("Template has too many lines [#{lines}/#{@max_length}]", template: node.template)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
theme-check-0.10.2 lib/theme_check/checks/template_length.rb
theme-check-0.10.1 lib/theme_check/checks/template_length.rb
theme-check-0.10.0 lib/theme_check/checks/template_length.rb
theme-check-0.9.1 lib/theme_check/checks/template_length.rb
theme-check-0.9.0 lib/theme_check/checks/template_length.rb