Class: ThemeCheck::TemplateLength
- Inherits:
-
LiquidCheck
- Object
- Check
- LiquidCheck
- ThemeCheck::TemplateLength
- 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
Instance Method Summary collapse
- #after_document(node) ⇒ Object
-
#initialize(max_length: 200, exclude_schema: true) ⇒ TemplateLength
constructor
A new instance of TemplateLength.
- #on_schema(node) ⇒ Object
Methods inherited from LiquidCheck
Methods included from ChecksTracking
Methods included from ParsingHelpers
Methods inherited from Check
all, can_disable, #can_disable?, category, #category, #code_name, doc, #doc, #ignore!, #ignored?, #severity, severity, #to_s, #unignore!
Methods included from JsonHelpers
Constructor Details
#initialize(max_length: 200, exclude_schema: true) ⇒ TemplateLength
Returns a new instance of TemplateLength.
7 8 9 10 11 |
# File 'lib/theme_check/checks/template_length.rb', line 7 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
19 20 21 22 23 24 |
# File 'lib/theme_check/checks/template_length.rb', line 19 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
13 14 15 16 17 |
# File 'lib/theme_check/checks/template_length.rb', line 13 def on_schema(node) if @exclude_schema @excluded_lines += node.value.nodelist.join.count("\n") end end |