File tree Expand file tree Collapse file tree 4 files changed +88
-1
lines changed
lib/rubocop/cop/github/accessibility Expand file tree Collapse file tree 4 files changed +88
-1
lines changed Original file line number Diff line number Diff line change 4
4
GitHub/Accessibility/ImageHasAlt :
5
5
Enabled : true
6
6
StyleGuide : https://github.com/github/rubocop-github/blob/master/guides/image-has-alt.md
7
+ GitHub/Accessibility/NoPositiveTabindex :
8
+ Enabled : true
9
+ StyleGuide : https://github.com/github/rubocop-github/blob/master/guides/no-positive-tabindex.md
7
10
GitHub/Accessibility/NoRedundantImageAlt :
8
11
Enabled : true
9
- StyleGuide : https://github.com/github/rubocop-github/blob/master/guides/no-redundant-image-alt.md
12
+ StyleGuide : https://github.com/github/rubocop-github/blob/master/guides/no-redundant-image-alt.md
Original file line number Diff line number Diff line change
1
+ # GitHub/Accessibility/NoPositiveTabindex
2
+
3
+ ## Rule Details
4
+
5
+ Positive tabindex is error-prone and often inaccessible.
6
+
7
+ ## Resources
8
+
9
+ - [ F44: Failure of Success Criterion 2.4.3 due to using tabindex to create a tab order that does not preserve meaning and operability] ( https://www.w3.org/TR/WCAG20-TECHS/F44.html )
10
+ - [ Deque University: Avoid Using Tabindex with Positive Numbers] ( https://dequeuniversity.com/tips/tabindex-positive-numbers )
11
+
12
+ ## Examples
13
+ ### ** Incorrect** code for this rule 👎
14
+
15
+ ``` erb
16
+ <%= button_tag "Continue", :tabindex => 3 %>
17
+ ```
18
+
19
+ ### ** Correct** code for this rule 👍
20
+
21
+ ``` erb
22
+ <!-- good -->
23
+ <%= button_tag "Continue", :tabindex => -1 %>
24
+ ```
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require "rubocop"
4
+
5
+ module RuboCop
6
+ module Cop
7
+ module GitHub
8
+ module Accessibility
9
+ class NoPositiveTabindex < Base
10
+ MSG = "Positive tabindex is error-prone and often inaccessible."
11
+
12
+ def on_send ( node )
13
+ receiver , method_name , *args = *node
14
+ if receiver . nil?
15
+ args . select do |arg |
16
+ arg . type == :hash
17
+ end . each do |hash |
18
+ hash . each_pair do |key , value |
19
+ next if key . type == :dsym
20
+ next unless key . respond_to? ( :value )
21
+ if key . value == :tabindex && value . source . to_i > 0
22
+ add_offense ( hash )
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./cop_test"
4
+ require "minitest/autorun"
5
+ require "rubocop/cop/github/accessibility/no_positive_tabindex"
6
+
7
+ class NoPositiveTabindex < CopTest
8
+ def cop_class
9
+ RuboCop ::Cop ::GitHub ::Accessibility ::NoPositiveTabindex
10
+ end
11
+
12
+ def test_no_positive_tabindex_alt_offense
13
+ offenses = erb_investigate cop , <<-ERB , "app/views/products/index.html.erb"
14
+ <%= button_tag "Continue" , :tabindex => 3 %>
15
+ ERB
16
+
17
+ assert_equal 1 , offenses . count
18
+ assert_equal "Positive tabindex is error-prone and often inaccessible." , offenses [ 0 ] . message
19
+ end
20
+
21
+ def test_no_positive_tabindex_alt_no_offense
22
+ offenses = erb_investigate cop , <<-ERB , "app/views/products/index.html.erb"
23
+ <%= button_tag "Continue" , :tabindex => -1 %>
24
+ ERB
25
+
26
+ assert_equal 0 , offenses . count
27
+ end
28
+ end
You can’t perform that action at this time.
0 commit comments