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, Check::SEVERITY_VALUES
Instance Attribute Summary
Attributes inherited from Check
#ignored_patterns, #offenses, #options, #theme
Instance Method Summary collapse
- #after_document(node) ⇒ Object
-
#initialize(max_length: 600, exclude_schema: true, exclude_stylesheet: true, exclude_javascript: true) ⇒ TemplateLength
constructor
A new instance of TemplateLength.
- #on_document(_node) ⇒ Object
- #on_javascript(node) ⇒ Object
- #on_schema(node) ⇒ Object
- #on_stylesheet(node) ⇒ Object
Methods included from ChecksTracking
Methods included from ParsingHelpers
Methods inherited from Check
#==, #add_offense, all, can_disable, #can_disable?, categories, #categories, category, #code_name, doc, #doc, docs_url, #ignore!, #ignored?, #severity, severity, #severity=, #severity_value, severity_value, single_file, #single_file?, #to_s, #whole_theme?
Methods included from JsonHelpers
#format_json_parse_error, #pretty_json
Constructor Details
#initialize(max_length: 600, exclude_schema: true, exclude_stylesheet: true, exclude_javascript: true) ⇒ TemplateLength
Returns a new instance of TemplateLength.
8 9 10 11 12 13 |
# File 'lib/theme_check/checks/template_length.rb', line 8 def initialize(max_length: 600, exclude_schema: true, exclude_stylesheet: true, exclude_javascript: true) @max_length = max_length @exclude_schema = exclude_schema @exclude_stylesheet = exclude_stylesheet @exclude_javascript = exclude_javascript end |
Instance Method Details
#after_document(node) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/theme_check/checks/template_length.rb', line 31 def after_document(node) lines = node.theme_file.source.count("\n") - @excluded_lines if lines > @max_length add_offense("Template has too many lines [#{lines}/#{@max_length}]", theme_file: node.theme_file) end end |
#on_document(_node) ⇒ Object
15 16 17 |
# File 'lib/theme_check/checks/template_length.rb', line 15 def on_document(_node) @excluded_lines = 0 end |
#on_javascript(node) ⇒ Object
27 28 29 |
# File 'lib/theme_check/checks/template_length.rb', line 27 def on_javascript(node) exclude_node_lines(node) if @exclude_javascript end |
#on_schema(node) ⇒ Object
19 20 21 |
# File 'lib/theme_check/checks/template_length.rb', line 19 def on_schema(node) exclude_node_lines(node) if @exclude_schema end |
#on_stylesheet(node) ⇒ Object
23 24 25 |
# File 'lib/theme_check/checks/template_length.rb', line 23 def on_stylesheet(node) exclude_node_lines(node) if @exclude_stylesheet end |