Skip to content

Commit 90c53ea

Browse files
authored
Merge pull request #36 from github/kh-make-more-strict
Make linter not count punctuation against match
2 parents ebdfc9d + b0cadce commit 90c53ea

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def autocorrect(processed_source, offense)
113113
private
114114

115115
def banned_text?(text)
116-
BANNED_GENERIC_TEXT.map(&:downcase).include?(text.downcase)
116+
BANNED_GENERIC_TEXT.map(&:downcase).include?(text.downcase.gsub(/\W+/, " ").strip)
117117
end
118118

119119
def valid_accessible_name?(aria_label, text)

test/linters/accessibility/avoid_generic_link_text_counter_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ def test_warns_when_link_text_is_link
4242
refute_empty @linter.offenses
4343
end
4444

45+
def test_warns_when_link_text_is_banned_text_with_punctuation_and_space
46+
@file = <<~ERB
47+
<a>Learn more!</a>
48+
<a> read more.</a>
49+
<a>click here.</a>
50+
ERB
51+
@linter.run(processed_source)
52+
53+
refute_empty @linter.offenses
54+
# 3 offenses, 1 related to matching counter comment not present despite violations
55+
assert_equal 4, @linter.offenses.count
56+
end
57+
4558
def test_does_not_warn_when_banned_text_is_part_of_more_text
4659
@file = "<a>Learn more about GitHub Stars</a>"
4760
@linter.run(processed_source)

0 commit comments

Comments
 (0)