Skip to content

Commit 13c6840

Browse files
authored
Merge pull request #37 from github/kh-fix-bug
bug: Fixes AvoidGenericLinkText bug
2 parents ebdc5f5 + 2593ad5 commit 13c6840

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,17 @@ def autocorrect(processed_source, offense)
112112

113113
private
114114

115+
# Downcase and strip punctuation and extra whitespaces.
116+
def stripped_text(text)
117+
text.downcase.gsub(/\W+/, " ").strip
118+
end
119+
115120
def banned_text?(text)
116-
BANNED_GENERIC_TEXT.map(&:downcase).include?(text.downcase.gsub(/\W+/, " ").strip)
121+
BANNED_GENERIC_TEXT.map(&:downcase).include?(stripped_text(text))
117122
end
118123

119124
def valid_accessible_name?(aria_label, text)
120-
aria_label.downcase.include?(text.downcase)
125+
stripped_text(aria_label).include?(stripped_text(text))
121126
end
122127

123128
def extract_ruby_node(source)

test/linters/accessibility/avoid_generic_link_text_counter_test.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ def test_flags_when_aria_label_does_not_include_visible_link_text
8282

8383
def test_does_not_flag_when_aria_label_includes_visible_link_text
8484
@file = <<~ERB
85-
<a aria-label="Learn more about GitHub Sponsors">Learn more</a>
85+
<a aria-label="Learn more about GitHub Sponsors.">Learn more.</a>
86+
<a aria-label="Learn more about GitHub Sponsors.">Learn more </a>
8687
ERB
8788
@linter.run(processed_source)
8889

0 commit comments

Comments
 (0)