15
16
17
18
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
58
59
60
|
# File 'lib/primer/view_components/linters/migrate_deprecated_flash_arguments.rb', line 15
def run(processed_source)
processed_source.ast.descendants(:erb).each do |erb_node|
indicator_node, _, code_node = *erb_node
code = code_node.children.first
ast = erb_ast(maybe_close_block(code))
next unless ast
constructor_arg_hashes = find_new_flash_instances(ast)
next if constructor_arg_hashes.empty?
indicator, = *indicator_node
indicator ||= ""
code_start_pos = erb_node.location.begin_pos + indicator.size + 2
constructor_arg_hashes.each do |constructor_arg_hash|
spacious_arg = constructor_arg_hash.include?(:spacious)
next unless spacious_arg
orig_loc = code_node.location
key_node, value_node = constructor_arg_hash[:spacious]
new_loc = orig_loc.with(
begin_pos: key_node.location.expression.begin_pos + code_start_pos,
end_pos: value_node.location.expression.end_pos + code_start_pos
)
if value_node.source == "true"
add_offense(
new_loc,
"The :spacious argument is deprecated. Use `mb: 4` instead.",
"mb: 4"
)
else
new_loc = adjust_to_preceding_comma(new_loc)
add_offense(
new_loc,
"The :spacious argument is deprecated; `spacious: false` can be removed.",
""
)
end
end
end
end
|