Skip to content

Commit b4ba76b

Browse files
authored
Merge pull request #110 from github/kh-except-link-tag
Don't flag `title` on link tag
2 parents 4941ebc + 84cfbfb commit b4ba76b

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

docs/rules/accessibility/no-title-attribute.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Rule Details
44

5-
The `title` attribute is strongly discouraged. The only exception is on an `<iframe>` element. It is hardly useful and cannot be accessed by multiple groups of users including keyboard-only users and mobile users.
5+
The `title` attribute is strongly discouraged. The only exceptions are for `<link>` and `<iframe>` element. It is hardly useful and cannot be accessed by multiple groups of users including keyboard-only users and mobile users.
66

77
The `title` attribute is commonly seen set on links, matching the link text. This is redundant and unnecessary so it can be simply be removed.
88

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ class NoTitleAttribute < Linter
1010
include ERBLint::Linters::CustomHelpers
1111
include LinterRegistry
1212

13-
MESSAGE = "The title attribute should never be used unless for an `<iframe>` as it is inaccessible for several groups of users."
13+
MESSAGE = "The title attribute should never be used as it is inaccessible for several groups of users. Exceptions are provided for <iframe> and <link>."
1414

1515
def run(processed_source)
1616
tags(processed_source).each do |tag|
17-
next if tag.name == "iframe"
17+
next if tag.name == "iframe" || tag.name == "link"
1818
next if tag.closing?
1919

2020
title = possible_attribute_values(tag, "title")

test/linters/accessibility/no_title_attribute_test.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_warns_if_element_sets_title
1313

1414
assert_equal(1, @linter.offenses.count)
1515
error_messages = @linter.offenses.map(&:message).sort
16-
assert_match(/The title attribute should never be used unless for an `<iframe>` as it is inaccessible for several groups of users./, error_messages.last)
16+
assert_match(/The title attribute should never be used as it is inaccessible for several groups of users./, error_messages.last)
1717
end
1818

1919
def test_does_not_warn_if_iframe_sets_title
@@ -22,4 +22,11 @@ def test_does_not_warn_if_iframe_sets_title
2222

2323
assert_empty @linter.offenses
2424
end
25+
26+
def test_does_not_warn_if_link_sets_title
27+
@file = "<link rel='unapi-server' type='application/xml' title='unAPI' href='/unapi'/></link>"
28+
@linter.run(processed_source)
29+
30+
assert_empty @linter.offenses
31+
end
2532
end

0 commit comments

Comments
 (0)