Class: ThemeCheck::TemplateLength
- Inherits:
-
LiquidCheck
- Object
- Check
- LiquidCheck
- ThemeCheck::TemplateLength
- 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
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?, categories, #categories, category, #code_name, #doc, doc, docs_url, #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.
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 |