Class: PlatformosCheck::GraphqlInForLoop
Defined Under Namespace
Classes: PartialInfo
Constant Summary
collapse
- PARTIAL_TAG =
%i[render include]
- OFFENSE_MSG =
"Do not invoke GraphQL in a for loop"
Constants inherited
from Check
Check::CATEGORIES, Check::SEVERITIES, Check::SEVERITY_VALUES
Instance Attribute Summary
Attributes inherited from Check
#ignored_patterns, #offenses, #options, #platformos_app
Class Method Summary
collapse
Instance Method Summary
collapse
#inherited
#outside_of_strings
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?, #to_s, #whole_platformos_app?
#format_json_parse_error, #pretty_json
Constructor Details
Returns a new instance of GraphqlInForLoop.
25
26
27
28
|
# File 'lib/platformos_check/checks/graphql_in_for_loop.rb', line 25
def initialize
@partials = []
@all_partials = Set.new
end
|
Class Method Details
.single_file(**_args) ⇒ Object
21
22
23
|
# File 'lib/platformos_check/checks/graphql_in_for_loop.rb', line 21
def self.single_file(**_args)
true
end
|
Instance Method Details
#after_background(_node) ⇒ Object
46
47
48
|
# File 'lib/platformos_check/checks/graphql_in_for_loop.rb', line 46
def after_background(_node)
@in_background = false
end
|
#after_for(_node) ⇒ Object
38
39
40
|
# File 'lib/platformos_check/checks/graphql_in_for_loop.rb', line 38
def after_for(_node)
@in_for = false
end
|
#on_background(_node) ⇒ Object
42
43
44
|
# File 'lib/platformos_check/checks/graphql_in_for_loop.rb', line 42
def on_background(_node)
@in_background = true
end
|
#on_end ⇒ Object
68
69
70
71
72
|
# File 'lib/platformos_check/checks/graphql_in_for_loop.rb', line 68
def on_end
while (partial_info = @partials.shift)
report_offense_on_graphql(LiquidNode.new(partial_info.app_file.parse.root, nil, partial_info.app_file), offense_node: partial_info.node)
end
end
|
#on_for(_node) ⇒ Object
30
31
32
|
# File 'lib/platformos_check/checks/graphql_in_for_loop.rb', line 30
def on_for(_node)
@in_for = true
end
|
#on_function(node) ⇒ Object
62
63
64
65
66
|
# File 'lib/platformos_check/checks/graphql_in_for_loop.rb', line 62
def on_function(node)
return unless should_report?
add_partial(path: node.value.from, node:)
end
|
#on_graphql(node) ⇒ Object
34
35
36
|
# File 'lib/platformos_check/checks/graphql_in_for_loop.rb', line 34
def on_graphql(node)
add_graphql_offense(node:, graphql_node: node) if should_report?
end
|
#on_include(node) ⇒ Object
50
51
52
53
54
|
# File 'lib/platformos_check/checks/graphql_in_for_loop.rb', line 50
def on_include(node)
return unless should_report?
add_partial(path: node.value.template_name_expr, node:)
end
|
#on_render(node) ⇒ Object
56
57
58
59
60
|
# File 'lib/platformos_check/checks/graphql_in_for_loop.rb', line 56
def on_render(node)
return unless should_report?
add_partial(path: node.value.template_name_expr, node:)
end
|