Skip to content

Commit 29dc516

Browse files
committed
Update test code and comments
1 parent af0ab51 commit 29dc516

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ def run(processed_source)
4242

4343
# Checks if nested between two link tags.
4444
if link_tag?(prev_node_tag) && link_tag?(next_node_tag) && next_node_tag.closing?
45-
# We skip because we cannot reliably check accessible name given aria-labelledby, or an aria-label that is set to a variable
45+
# Skip because we cannot reliably check accessible name from aria-labelledby, or an aria-label that is set to a variable
4646
# with static code analysis.
4747
next if aria_labelledby.present? || (aria_label.present? && aria_label.join.include?("<%="))
48-
# We skip because aria-label contains visible text. Relates to Success Criterion 2.5.3: Label in Name
48+
# Skip because aria-label starts with visible text which we allow. Related to Success Criterion 2.5.3: Label in Name
4949
next if aria_label.present? && valid_accessible_name?(aria_label.join, text)
5050

5151
range = prev_node_tag.loc.begin_pos...text_node_tag.loc.end_pos
@@ -81,7 +81,7 @@ def run(processed_source)
8181
end
8282
end
8383

84-
# Skip if `link_to` has `aria-labelledby` or `aria-label` which we cannot be evaluated accurately with ERB lint alone.
84+
# Skips if `link_to` has `aria-labelledby` or `aria-label` which we cannot be evaluated accurately with ERB lint alone.
8585
# ERB lint removes Ruby string interpolation so the `aria-label` for "<%= link_to 'Learn more', "aria-label": "Learn #{@some_variable}" %>" will
8686
# only be `Learn` which is unreliable so we can't do checks :(
8787
banned_text = nil if pair_node.children.first.children.join == "aria-labelledby" || pair_node.children.first.children.join == "aria-label"

test/linters/accessibility/avoid_generic_link_text_counter_test.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,31 +84,31 @@ def test_ignores_when_aria_labelledby_is_set_on_link_tag
8484
end
8585

8686
def test_warns_when_link_rails_helper_text_is_banned_text
87-
@file = "<%= link_to('click here', redirect_url, id: 'redirect') %>"
87+
@file = "<%= link_to('click here', redirect_url) %>"
8888
@linter.run(processed_source)
8989

9090
refute_empty @linter.offenses
9191
end
9292

9393
def test_warns_when_link_rails_helper_text_is_banned_text_with_aria_description
9494
@file = <<~ERB
95-
<%= link_to('click here', 'aria-describedby': 'element123', id: 'redirect') %>
95+
<%= link_to('click here', redirect_url, 'aria-describedby': 'element123', id: 'redirect') %>
9696
ERB
9797
@linter.run(processed_source)
9898

9999
refute_empty @linter.offenses
100100
end
101101

102102
def test_ignores_when_link_rails_helper_text_is_banned_text_with_aria_labelled_by
103-
@file = "<%= link_to('learn more', 'aria-labelledby': 'element1234', id: 'redirect') %>"
103+
@file = "<%= link_to('learn more', redirect_url, 'aria-labelledby': 'element1234', id: 'redirect') %>"
104104
@linter.run(processed_source)
105105

106106
assert_empty @linter.offenses
107107
end
108108

109109
def test_ignores_when_link_rails_helper_text_is_banned_text_with_aria_label_that_cannot_be_parsed_by_linter
110110
@file = <<~ERB
111-
<%= link_to('learn more', 'aria-label': some_variable, id: 'redirect') %>
111+
<%= link_to('learn more', redirect_url, 'aria-label': some_variable, id: 'redirect') %>
112112
ERB
113113
@linter.run(processed_source)
114114

@@ -117,22 +117,22 @@ def test_ignores_when_link_rails_helper_text_is_banned_text_with_aria_label_that
117117

118118
def test_ignores_when_link_rails_helper_text_is_banned_text_with_aria_label_since_cannot_be_parsed_accurately_by_linter
119119
@file = <<~ERB
120-
<%= link_to('learn more', 'aria-label': "Learn #{@variable}", id: 'redirect') %>
120+
<%= link_to('learn more', redirect_url, 'aria-label': "Learn #{@variable}", id: 'redirect') %>
121121
ERB
122122
@linter.run(processed_source)
123123

124124
assert_empty @linter.offenses
125125
end
126126

127127
def test_ignores_when_link_rails_helper_text_is_banned_text_with_aria_label
128-
@file = "<%= link_to('learn more', 'aria-label': 'learn more about GitHub', id: 'redirect') %>"
128+
@file = "<%= link_to('learn more', redirect_url, 'aria-label': 'learn more about GitHub', id: 'redirect') %>"
129129
@linter.run(processed_source)
130130

131131
assert_empty @linter.offenses
132132
end
133133

134134
def test_ignores_when_link_rails_helper_text_is_banned_text_with_aria_label_hash
135-
@file = "<%= link_to('learn more', aria: { label: 'learn more about GitHub' }, id: 'redirect') %>"
135+
@file = "<%= link_to('learn more', redirect_url, aria: { label: 'learn more about GitHub' }, id: 'redirect') %>"
136136
@linter.run(processed_source)
137137

138138
assert_empty @linter.offenses

0 commit comments

Comments
 (0)