19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/primer/view_components/linters/disallow_action_list.rb', line 19
def run(processed_source)
return if ignored?(processed_source.filename)
class_regex = /ActionList[\w-]*/
tags, * = build_tag_tree(processed_source)
tags.each do |tag|
next if tag.closing?
classes =
if (class_attrib = tag.attributes["class"])
loc = class_attrib.value_node.loc
loc.source_buffer.source[loc.begin_pos...loc.end_pos]
else
""
end
indices = [].tap do |results|
classes.scan(class_regex) do
results << Regexp.last_match.offset(0)
end
end
next if indices.empty?
indices.each do |(start_idx, end_idx)|
new_loc = class_attrib.value_node.loc.with(
begin_pos: class_attrib.value_node.loc.begin_pos + start_idx,
end_pos: class_attrib.value_node.loc.begin_pos + end_idx
)
add_offense(
new_loc,
"ActionList classes are only designed to be used by Primer View Components and " \
"should be considered private. Please reach out in the #primer-rails Slack channel."
)
end
end
end
|