Class: ThemeCheck::TemplateLength

Inherits:
LiquidCheck show all
Defined in:
lib/theme_check/checks/template_length.rb

Constant Summary

Constants inherited from LiquidCheck

LiquidCheck::ATTR, LiquidCheck::HTML_ATTRIBUTE, LiquidCheck::HTML_ATTRIBUTES, LiquidCheck::QUOTED_LIQUID_ATTRIBUTE, LiquidCheck::START_OR_END_QUOTE, LiquidCheck::TAG, LiquidCheck::VARIABLE

Constants inherited from Check

Check::CATEGORIES, Check::SEVERITIES

Instance Attribute Summary

Attributes inherited from Check

#offenses, #options, #theme

Instance Method Summary collapse

Methods inherited from LiquidCheck

#add_offense

Methods included from ChecksTracking

#inherited

Methods included from ParsingHelpers

#outside_of_strings

Methods inherited from Check

all, can_disable, #can_disable?, categories, #categories, category, #code_name, #doc, doc, docs_url, #ignore!, #ignored?, #severity, severity, #to_s, #unignore!

Methods included from JsonHelpers

#format_json_parse_error

Constructor Details

#initialize(max_length: 200, exclude_schema: true) ⇒ TemplateLength

Returns a new instance of TemplateLength.



8
9
10
11
12
# File 'lib/theme_check/checks/template_length.rb', line 8

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

Instance Method Details

#after_document(node) ⇒ Object



20
21
22
23
24
25
# File 'lib/theme_check/checks/template_length.rb', line 20

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

#on_schema(node) ⇒ Object



14
15
16
17
18
# File 'lib/theme_check/checks/template_length.rb', line 14

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