Skip to content

Commit af0ab51

Browse files
committed
Add test case to ignore only if label attributes and not description
1 parent 6ee53c2 commit af0ab51

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/erblint-github/linters/github/accessibility/avoid_generic_link_text_counter.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ def run(processed_source)
6868

6969
send_node.child_nodes.each do |child_node|
7070
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?
7172

72-
next unless banned_text.present? && child_node.methods.include?(:type) && child_node.type == :hash
73+
next unless child_node.methods.include?(:type) && child_node.type == :hash
7374

7475
child_node.descendants(:pair).each do |pair_node|
7576
next unless pair_node.children.first.type?(:sym)
@@ -82,7 +83,7 @@ def run(processed_source)
8283

8384
# Skip if `link_to` has `aria-labelledby` or `aria-label` which we cannot be evaluated accurately with ERB lint alone.
8485
# ERB lint removes Ruby string interpolation so the `aria-label` for "<%= link_to 'Learn more', "aria-label": "Learn #{@some_variable}" %>" will
85-
# be `Learn` which is unreliable so we have to skip entirely unlike with HTML :(
86+
# only be `Learn` which is unreliable so we can't do checks :(
8687
banned_text = nil if pair_node.children.first.children.join == "aria-labelledby" || pair_node.children.first.children.join == "aria-label"
8788
end
8889
end

test/linters/accessibility/avoid_generic_link_text_counter_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ def test_warns_when_link_rails_helper_text_is_banned_text
9090
refute_empty @linter.offenses
9191
end
9292

93+
def test_warns_when_link_rails_helper_text_is_banned_text_with_aria_description
94+
@file = <<~ERB
95+
<%= link_to('click here', 'aria-describedby': 'element123', id: 'redirect') %>
96+
ERB
97+
@linter.run(processed_source)
98+
99+
refute_empty @linter.offenses
100+
end
101+
93102
def test_ignores_when_link_rails_helper_text_is_banned_text_with_aria_labelled_by
94103
@file = "<%= link_to('learn more', 'aria-labelledby': 'element1234', id: 'redirect') %>"
95104
@linter.run(processed_source)

0 commit comments

Comments
 (0)