Class: ThemeCheck::TemplateLength

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

Constant Summary

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, category, #category, #code_name, doc, #doc, #ignore!, #ignored?, severity, #severity, #to_s, #unignore!

Methods included from JsonHelpers

#format_json_parse_error

Constructor Details

#initialize(max_length: 200) ⇒ TemplateLength

Returns a new instance of TemplateLength.



7
8
9
# File 'lib/theme_check/checks/template_length.rb', line 7

def initialize(max_length: 200)
  @max_length = max_length
end

Instance Method Details

#on_document(node) ⇒ Object



11
12
13
14
15
16
# File 'lib/theme_check/checks/template_length.rb', line 11

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