@@ -55,41 +55,41 @@ def run(processed_source)
5555 end
5656
5757 # Checks Rails link helpers like `link_to`
58- erb_node = node . type == :erb ? node : node . descendants ( :erb ) . first
59- next unless erb_node
58+ node . descendants ( :erb ) . each do |erb_node |
59+ _ , _ , code_node = *erb_node
60+ source = code_node . loc . source
61+ ruby_node = extract_ruby_node ( source )
62+ send_node = ruby_node &.descendants ( :send ) &.first
63+ next unless send_node . methods . include? ( :method_name ) && send_node . method_name == :link_to
6064
61- _ , _ , code_node = *erb_node
62- source = code_node . loc . source
63- ruby_node = extract_ruby_node ( source )
64- send_node = ruby_node &.descendants ( :send ) &.first
65- next unless send_node . methods . include? ( :method_name ) && send_node . method_name == :link_to
65+ banned_text = nil
6666
67- banned_text = nil
67+ send_node . child_nodes . each do |child_node |
68+ banned_text = child_node . children . join if child_node . methods . include? ( :type ) && child_node . type == :str && banned_text? ( child_node . children . join )
69+ next if banned_text . blank?
6870
69- send_node . child_nodes . each do |child_node |
70- banned_text = child_node . children . join if child_node . methods . include? ( :type ) && child_node . type == :str && banned_text? ( child_node . children . join )
71- next if banned_text . blank?
71+ next unless child_node . methods . include? ( :type ) && child_node . type == :hash
7272
73- next unless child_node . methods . include? ( :type ) && child_node . type == :hash
73+ child_node . descendants ( :pair ) . each do |pair_node |
74+ next unless pair_node . children . first . type? ( :sym )
7475
75- child_node . descendants ( :pair ) . each do |pair_node |
76- next unless pair_node . children . first . type? ( :sym )
77-
78- if pair_node . children . first . children . join == "aria"
79- pair_node . children [ 1 ] . descendants ( :sym ) . each do |sym_node |
80- banned_text = nil if sym_node . children . join == "label" || sym_node . children . join == "labelledby"
76+ if pair_node . children . first . children . join == "aria"
77+ pair_node . children [ 1 ] . descendants ( :sym ) . each do |sym_node |
78+ banned_text = nil if sym_node . children . join == "label" || sym_node . children . join == "labelledby"
79+ end
8180 end
82- end
8381
84- # Skips if `link_to` has `aria-labelledby` or `aria-label` which we cannot be evaluated accurately with ERB lint alone.
85- # ERB lint removes Ruby string interpolation so the `aria-label` for "<%= link_to 'Learn more', "aria-label": "Learn #{@some_variable}" %>" will
86- # only be `Learn` which is unreliable so we can't do checks :(
87- banned_text = nil if pair_node . children . first . children . join == "aria-labelledby" || pair_node . children . first . children . join == "aria-label"
82+ # Skips if `link_to` has `aria-labelledby` or `aria-label` which we cannot be evaluated accurately with ERB lint alone.
83+ # ERB lint removes Ruby string interpolation so the `aria-label` for "<%= link_to 'Learn more', "aria-label": "Learn #{@some_variable}" %>" will
84+ # only be `Learn` which is unreliable so we can't do checks :(
85+ banned_text = nil if pair_node . children . first . children . join == "aria-labelledby" || pair_node . children . first . children . join == "aria-label"
86+ end
8887 end
89- end
90- if banned_text . present?
91- tag = BetterHtml ::Tree ::Tag . from_node ( code_node )
92- generate_offense ( self . class , processed_source , tag )
88+ if banned_text . present?
89+ tag = BetterHtml ::Tree ::Tag . from_node ( code_node )
90+ generate_offense ( self . class , processed_source , tag )
91+ end
92+ banned_text = nil
9393 end
9494 end
9595 counter_correct? ( processed_source )
0 commit comments