Class: ThemeCheck::LiquidTag
Overview
Recommends using liquid … % if 3 or more consecutive … % are found.
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
#inherited
#outside_of_strings
Methods inherited from Check
all, can_disable, #can_disable?, category, #category, #code_name, doc, #doc, #ignore!, #ignored?, #severity, severity, #to_s, #unignore!
#format_json_parse_error
Constructor Details
#initialize(min_consecutive_statements: 10) ⇒ LiquidTag
Returns a new instance of LiquidTag.
9
10
11
12
13
|
# File 'lib/theme_check/checks/liquid_tag.rb', line 9
def initialize(min_consecutive_statements: 10)
@first_statement = nil
@consecutive_statements = 0
@min_consecutive_statements = min_consecutive_statements
end
|
Instance Method Details
#after_document(_node) ⇒ Object
31
32
33
|
# File 'lib/theme_check/checks/liquid_tag.rb', line 31
def after_document(_node)
reset_consecutive_statements
end
|
#increment_consecutive_statements(node) ⇒ Object
35
36
37
38
|
# File 'lib/theme_check/checks/liquid_tag.rb', line 35
def increment_consecutive_statements(node)
@first_statement ||= node
@consecutive_statements += 1
end
|
#on_string(node) ⇒ Object
24
25
26
27
28
29
|
# File 'lib/theme_check/checks/liquid_tag.rb', line 24
def on_string(node)
if node.parent.block? && !node.value.strip.empty?
reset_consecutive_statements
end
end
|
#on_tag(node) ⇒ Object
15
16
17
18
19
20
21
22
|
# File 'lib/theme_check/checks/liquid_tag.rb', line 15
def on_tag(node)
if !node.inside_liquid_tag?
reset_consecutive_statements
elsif !node.
increment_consecutive_statements(node)
end
end
|
#reset_consecutive_statements ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/theme_check/checks/liquid_tag.rb', line 40
def reset_consecutive_statements
if @consecutive_statements >= @min_consecutive_statements
add_offense("Use {% liquid ... %} to write multiple tags", node: @first_statement)
end
@first_statement = nil
@consecutive_statements = 0
end
|