File tree Expand file tree Collapse file tree 4 files changed +91
-0
lines changed
lib/erblint-github/linters/github/accessibility
test/linters/accessibility Expand file tree Collapse file tree 4 files changed +91
-0
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,8 @@ linters:
3131 enabled : true
3232 GitHub::Accessibility::NoAriaLabelMisuse :
3333 enabled : true
34+ GitHub::Accessibility::NoPositiveTabIndex :
35+ enabled : true
3436 GitHub::Accessibility::NoRedundantImageAlt :
3537 enabled : true
3638` ` `
@@ -41,6 +43,7 @@ linters:
4143- [GitHub::Accessibility::IframeHasTitle](./docs/rules/accessibility/iframe-has-title.md)
4244- [GitHub::Accessibility::ImageHasAlt](./docs/rules/accessibility/image-has-alt.md)
4345- [GitHub::Accessibility::NoAriaLabelMisuse](./docs/rules/accessibility/no-aria-label-misuse.md)
46+ - [GitHub::Accessibility::NoPositiveTabIndex](./docs/rules/accessibility/no-positive-tab-index.md)
4447- [GitHub::Accessibility::NoRedundantImageAlt](./docs/rules/accessibility/no-redundant-image-alt.md)
4548
4649## Testing
Original file line number Diff line number Diff line change 1+ # No positive tab index
2+
3+ ## Rule Details
4+
5+ Do not positive tabindex as it is error prone and can severely disrupt navigation experience for keyboard users.
6+
7+ Learn more at:
8+
9+ - [ A11yProject: Use the tabindex attribute] ( https://www.a11yproject.com/posts/how-to-use-the-tabindex-attribute/ )
10+ - [ Deque: Avoid using Tabindex with positive numbers] ( https://dequeuniversity.com/tips/tabindex-positive-numbers )
11+
12+ ### 👎 Examples of ** incorrect** code for this rule:
13+
14+ ``` erb
15+ <button tabindex="3"></button>
16+ <button tabindex="1"></button>
17+ ```
18+
19+ ### 👍 Examples of ** correct** code for this rule:
20+
21+ ``` erb
22+ <!-- good -->
23+ <button tabindex="0"></button>
24+ ```
25+
26+ ``` erb
27+ <!-- also good -->
28+ <button tabindex="-1"></button>
29+ ```
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ require_relative "../../custom_helpers"
4+
5+ module ERBLint
6+ module Linters
7+ module GitHub
8+ module Accessibility
9+ class NoPositiveTabIndex < Linter
10+ include ERBLint ::Linters ::CustomHelpers
11+ include LinterRegistry
12+
13+ MESSAGE = "Do not use positive tabindex as it is error prone and can severely disrupt navigation experience for keyboard users"
14+
15+ def run ( processed_source )
16+ tags ( processed_source ) . each do |tag |
17+ next if tag . closing?
18+ next unless tag . attributes [ "tabindex" ] &.value . to_i . positive?
19+
20+ generate_offense ( self . class , processed_source , tag )
21+ end
22+
23+ rule_disabled? ( processed_source )
24+ end
25+ end
26+ end
27+ end
28+ end
29+ end
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ require "test_helper"
4+
5+ class NoPositiveTabIndexTest < LinterTestCase
6+ def linter_class
7+ ERBLint ::Linters ::GitHub ::Accessibility ::NoPositiveTabIndex
8+ end
9+
10+ def test_warns_if_positive_tabindex_is_used
11+ @file = "<button tabindex='1'></button>"
12+ @linter . run ( processed_source )
13+
14+ refute_empty @linter . offenses
15+ end
16+
17+ def test_does_not_warn_if_negative_tabindex_is_used
18+ @file = "<button tabindex='-1'></button>"
19+ @linter . run ( processed_source )
20+
21+ assert_empty @linter . offenses
22+ end
23+
24+ def test_does_not_warn_if_zero_tabindex_is_used
25+ @file = "<button tabindex='0'></button>"
26+ @linter . run ( processed_source )
27+
28+ assert_empty @linter . offenses
29+ end
30+ end
You can’t perform that action at this time.
0 commit comments