Class: PlatformosCheck::UndefinedObject
Defined Under Namespace
Classes: TemplateInfo
Constant Summary
Constants inherited
from Check
Check::CATEGORIES, Check::SEVERITIES, Check::SEVERITY_VALUES
Instance Attribute Summary
Attributes inherited from Check
#ignored_patterns, #offenses, #options, #platformos_app
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, #single_file?, #to_s, #whole_platformos_app?
#format_json_parse_error, #pretty_json
Constructor Details
#initialize(config_type: :default, exclude_partials: true) ⇒ UndefinedObject
Returns a new instance of UndefinedObject.
61
62
63
64
65
|
# File 'lib/platformos_check/checks/undefined_object.rb', line 61
def initialize(config_type: :default, exclude_partials: true)
@config_type = config_type
@exclude_partials = exclude_partials
@files = {}
end
|
Instance Method Details
#on_assign(node) ⇒ Object
73
74
75
76
77
|
# File 'lib/platformos_check/checks/undefined_object.rb', line 73
def on_assign(node)
return if ignore?(node)
@files[node.app_file.name].all_assigns[node.value.to] = node
end
|
#on_background(node) ⇒ Object
130
131
132
133
134
135
136
137
138
139
140
141
|
# File 'lib/platformos_check/checks/undefined_object.rb', line 130
def on_background(node)
return if ignore?(node)
return unless node.value.partial_syntax
return unless node.value.partial_name.is_a?(String)
@files[node.app_file.name].add_render(
name: node.value.partial_name,
node:
)
@files[node.app_file.name].all_assigns[node.value.to] = node
end
|
#on_capture(node) ⇒ Object
79
80
81
82
83
|
# File 'lib/platformos_check/checks/undefined_object.rb', line 79
def on_capture(node)
return if ignore?(node)
@files[node.app_file.name].all_captures[node.value.instance_variable_get(:@to)] = node
end
|
#on_document(node) ⇒ Object
67
68
69
70
71
|
# File 'lib/platformos_check/checks/undefined_object.rb', line 67
def on_document(node)
return if ignore?(node)
@files[node.app_file.name] = TemplateInfo.new(app_file: node.app_file)
end
|
#on_end ⇒ Object
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
# File 'lib/platformos_check/checks/undefined_object.rb', line 152
def on_end
all_global_objects = PlatformosCheck::PlatformosLiquid::Object.labels
all_global_objects.freeze
each_template do |(_name, info)|
if info.app_file.notification?
check_object(info, all_global_objects + %w[data response form])
elsif info.app_file.form?
check_object(info, all_global_objects + %w[form form_builder])
else
check_object(info, all_global_objects)
end
end
end
|
#on_for(node) ⇒ Object
91
92
93
94
95
|
# File 'lib/platformos_check/checks/undefined_object.rb', line 91
def on_for(node)
return if ignore?(node)
@files[node.app_file.name].all_forloops[node.value.variable_name] = node
end
|
#on_function(node) ⇒ Object
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/platformos_check/checks/undefined_object.rb', line 112
def on_function(node)
return if ignore?(node)
name = node.value.from.is_a?(String) ? node.value.from : node.value.from.name
@files[node.app_file.name].add_render(
name:,
node:
)
@files[node.app_file.name].all_assigns[node.value.to] = node
end
|
#on_graphql(node) ⇒ Object
124
125
126
127
128
|
# File 'lib/platformos_check/checks/undefined_object.rb', line 124
def on_graphql(node)
return if ignore?(node)
@files[node.app_file.name].all_assigns[node.value.to] = node
end
|
#on_include(_node) ⇒ Object
97
98
99
|
# File 'lib/platformos_check/checks/undefined_object.rb', line 97
def on_include(_node)
end
|
#on_parse_json(node) ⇒ Object
85
86
87
88
89
|
# File 'lib/platformos_check/checks/undefined_object.rb', line 85
def on_parse_json(node)
return if ignore?(node)
@files[node.app_file.name].all_captures[node.value.to] = node
end
|
#on_render(node) ⇒ Object
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/platformos_check/checks/undefined_object.rb', line 101
def on_render(node)
return if ignore?(node)
return unless node.value.template_name_expr.is_a?(String)
partial_name = node.value.template_name_expr
@files[node.app_file.name].add_render(
name: partial_name,
node:
)
end
|
#on_variable_lookup(node) ⇒ Object
143
144
145
146
147
148
149
150
|
# File 'lib/platformos_check/checks/undefined_object.rb', line 143
def on_variable_lookup(node)
return if ignore?(node)
@files[node.app_file.name].add_variable_lookup(
name: node.value.name,
node:
)
end
|