erblint-github 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e7ce2b605ec0f31cb56b3e74e9f2eb4e10a11a8ab07d960596209b7d9674427
4
- data.tar.gz: 0a74bf6def4d4c0b34c3f8bba3af39f7b3207fb87a72e08cf9143f3d42a1f577
3
+ metadata.gz: 4866db453698b16cc11db6797374c4e60a125aa020fabe51966928d19e0578c0
4
+ data.tar.gz: ba36e29a32956fe98e545059f803b3113404f206015f963b1215452241f43427
5
5
  SHA512:
6
- metadata.gz: 04e924e98c1fe68f5b3d56d8f0cf9a4c0083d70d55192661a1c93dcb457b870df4ab5841c8376c2afc8c7b3c86be87266df513e22cecfe5f33b230d450d4f5a4
7
- data.tar.gz: f266202201dc8de5a3bd6089ed7b5562962b130ec5643775c3a910a242086a13280e4e449ccf26f3c0f9e5c1874693c8ce3971dff965117079ecd568c3c11e33
6
+ metadata.gz: b7becf4d23e09a131db0d379a3b28c47ad548034eb4e387a38ae6fb1f1d47ab6dba33173a0b5dfd39bfc6c999ffe02ea1f8278b42ae5ea82ec6c503bcaf0ffbd
7
+ data.tar.gz: 98ce947b2b9a76cbe3310b6a4187bce8cadad184f33044aee0761bd4d55f5bb82d8329fe683e26549f2c2144aedfeaa2ebcb39f32a7e20b13d5be044ce92da4f
data/README.md CHANGED
@@ -23,15 +23,15 @@ require "erblint-github/linters"
23
23
  ```yaml
24
24
  ---
25
25
  linters:
26
- GitHub::Accessibility::AvoidBothDisabledAndAriaDisabled:
26
+ GitHub::Accessibility::AvoidBothDisabledAndAriaDisabledCounter:
27
27
  enabled: true
28
28
  GitHub::Accessibility::AvoidGenericLinkTextCounter:
29
29
  enabled: true
30
30
  GitHub::Accessibility::DisabledAttributeCounter:
31
31
  enabled: true
32
- GitHub::Accessibility::IframeHasTitle:
32
+ GitHub::Accessibility::IframeHasTitleCounter:
33
33
  enabled: true
34
- GitHub::Accessibility::ImageHasAlt:
34
+ GitHub::Accessibility::ImageHasAltCounter:
35
35
  enabled: true
36
36
  GitHub::Accessibility::LandmarkHasLabelCounter:
37
37
  enabled: true
@@ -39,11 +39,13 @@ linters:
39
39
  enabled: true
40
40
  GitHub::Accessibility::NestedInteractiveElementsCounter:
41
41
  enabled: true
42
+ GitHub::Accessibility::NoAriaHiddenOnFocusableCounter:
43
+ enabled: true
42
44
  GitHub::Accessibility::NoAriaLabelMisuseCounter:
43
45
  enabled: true
44
- GitHub::Accessibility::NoPositiveTabIndex:
46
+ GitHub::Accessibility::NoPositiveTabIndexCounter:
45
47
  enabled: true
46
- GitHub::Accessibility::NoRedundantImageAlt:
48
+ GitHub::Accessibility::NoRedundantImageAltCounter:
47
49
  enabled: true
48
50
  GitHub::Accessibility::NoTitleAttributeCounter:
49
51
  enabled: true
@@ -53,20 +55,49 @@ linters:
53
55
 
54
56
  ## Rules
55
57
 
56
- - [GitHub::Accessibility::AvoidBothDisabledAndAriaDisabled](./docs/rules/accessibility/avoid-both-disabled-and-aria-disabled.md)
58
+ - [GitHub::Accessibility::AvoidBothDisabledAndAriaDisabledCounter](./docs/rules/accessibility/avoid-both-disabled-and-aria-disabled-counter.md)
57
59
  - [GitHub::Accessibility::AvoidGenericLinkTextCounter](./docs/rules/accessibility/avoid-generic-link-text-counter.md)
58
- - [GitHub::Accessibility::DisabledAttributeCounter](./docs/rules/accessibility/disabled-attribute-counter-test)
59
- - [GitHub::Accessibility::IframeHasTitle](./docs/rules/accessibility/iframe-has-title.md)
60
+ - [GitHub::Accessibility::DisabledAttributeCounter](./docs/rules/accessibility/disabled-attribute-counter.md)
60
61
  - [GitHub::Accessibility::LandmarkHasLabelCounter](./docs/rules/accessibility/landmark-has-label-counter.md)
61
- - [GitHub::Accessibility::ImageHasAlt](./docs/rules/accessibility/image-has-alt.md)
62
62
  - [GitHub::Accessibility::LinkHasHrefCounter](./docs/rules/accessibility/link-has-href-counter.md)
63
63
  - [GitHub::Accessibility::NestedInteractiveElementsCounter](./docs/rules/accessibility/nested-interactive-elements-counter.md)
64
+ - [GitHub::Accessibility::IframeHasTitleCounter](./docs/rules/accessibility/iframe-has-title-counter.md)
65
+ - [GitHub::Accessibility::ImageHasAltCounter](./docs/rules/accessibility/image-has-alt-counter.md)
66
+ - [GitHub::Accessibility::NoAriaHiddenOnFocusableCounter](./docs/rules/accessibility/no-aria-hidden-on-focusable-counter.md)
64
67
  - [GitHub::Accessibility::NoAriaLabelMisuseCounter](./docs/rules/accessibility/no-aria-label-misuse-counter.md)
65
- - [GitHub::Accessibility::NoPositiveTabIndex](./docs/rules/accessibility/no-positive-tab-index.md)
66
- - [GitHub::Accessibility::NoRedundantImageAlt](./docs/rules/accessibility/no-redundant-image-alt.md)
68
+ - [GitHub::Accessibility::NoPositiveTabIndexCounter](./docs/rules/accessibility/no-positive-tab-index-counter.md)
69
+ - [GitHub::Accessibility::NoRedundantImageAltCounter](./docs/rules/accessibility/no-redundant-image-alt-counter.md)
67
70
  - [GitHub::Accessibility::NoTitleAttributeCounter](./docs/rules/accessibility/no-title-attribute-counter.md)
68
71
  - [GitHub::Accessibility::SvgHasAccessibleTextCounter](./docs/rules/accessibility/svg-has-accessible-text-counter.md)
69
72
 
73
+ ## Disabling a rule (experimental)
74
+
75
+ _This is an experimental feature which should ideally be upstreamed to erblint_
76
+
77
+ `erblint` does not natively support rule disables. At GitHub, we've implemented these rules in a way to allow rules to be disabled at an offense-level via counters or disabled at a file-level because often times, we want to enable a rule but aren't able to address all offenses at once. We achieve this in one of two ways.
78
+
79
+ Rules that are marked as `Counter` can be disabled by adding a comment with the offense count that matches the number of offenses within the file like:
80
+
81
+ ```.html.erb
82
+ <%# erblint:counter GitHub::Accessibility::LinkHasHrefCounter 1 %>
83
+ ```
84
+
85
+ In this comment example, when a new `LinkHasHrefCounter` offense has been added, the counter will need to be bumped up to 2. More recent rules use a `Counter` format.
86
+
87
+ If you are enabling a rule for the first time and your codebase has a lot of offenses, you can use the `-a` command to automatically add these counter comments in the appropriate places.
88
+
89
+ ```
90
+ bundle exec erblint app/views app/components -a
91
+ ```
92
+
93
+ Rules that are not marked as `Counter` like `NoRedundantImageAlt` are considered to be legacy format. We are in the process of migrating these to counters. These rules can still be disabled at the file-level by adding this comment at the top of the file:
94
+
95
+ ```.html.erb
96
+ <%# erblint:disable GitHub::Accessibility::NoRedundantImageAlt %>
97
+ ```
98
+
99
+ However, unlike a counter, any subsequent offenses introduced to the file will not raise.
100
+
70
101
  ## Testing
71
102
 
72
103
  ```
@@ -81,4 +112,4 @@ If you use VS Code, we highly encourage [ERB Linter extension](https://marketpla
81
112
  ## Note
82
113
 
83
114
  This repo contains several accessibility-related linting rules to help surface accessibility issues that would otherwise go undetected until a later stage. Please note that due to the limitations of static code analysis,
84
- these ERB accessibility checks are NOT enough for ensuring the accessibility of your app. This shouldn't be the only tool you use to catch accessibility issues and should be supplemented with other tools that can check the runtime browser DOM output, as well as processes like accessibility design reviews, manual audits, user testing, etc.
115
+ these ERB accessibility checks are NOT enough for ensuring the accessibility of your app. This shouldn't be the only tool you use to catch accessibility issues and should be supplemented with other tools that can check the runtime browser DOM output, as well as processes like accessibility design reviews, manual audits, user testing, etc.
@@ -6,6 +6,8 @@ require "openssl"
6
6
  module ERBLint
7
7
  module Linters
8
8
  module CustomHelpers
9
+ INTERACTIVE_ELEMENTS = %w[button summary input select textarea a].freeze
10
+
9
11
  def rule_disabled?(processed_source)
10
12
  processed_source.parser.ast.descendants(:erb).each do |node|
11
13
  indicator_node, _, code_node, = *node
@@ -89,6 +91,15 @@ module ERBLint
89
91
  def simple_class_name
90
92
  self.class.name.gsub("ERBLint::Linters::", "")
91
93
  end
94
+
95
+ def focusable?(tag)
96
+ tabindex = possible_attribute_values(tag, "tabindex")
97
+ if INTERACTIVE_ELEMENTS.include?(tag.name)
98
+ tabindex.empty? || tabindex.first.to_i >= 0
99
+ else
100
+ tabindex.any? && tabindex.first.to_i >= 0
101
+ end
102
+ end
92
103
  end
93
104
  end
94
105
  end
@@ -6,7 +6,7 @@ module ERBLint
6
6
  module Linters
7
7
  module GitHub
8
8
  module Accessibility
9
- class AvoidBothDisabledAndAriaDisabled < Linter
9
+ class AvoidBothDisabledAndAriaDisabledCounter < Linter
10
10
  include ERBLint::Linters::CustomHelpers
11
11
  include LinterRegistry
12
12
 
@@ -22,7 +22,21 @@ module ERBLint
22
22
  generate_offense(self.class, processed_source, tag)
23
23
  end
24
24
 
25
- rule_disabled?(processed_source)
25
+ counter_correct?(processed_source)
26
+ end
27
+
28
+ def autocorrect(processed_source, offense)
29
+ return unless offense.context
30
+
31
+ lambda do |corrector|
32
+ if processed_source.file_content.include?("erblint:counter #{simple_class_name}")
33
+ # update the counter if exists
34
+ corrector.replace(offense.source_range, offense.context)
35
+ else
36
+ # add comment with counter if none
37
+ corrector.insert_before(processed_source.source_buffer.source_range, "#{offense.context}\n")
38
+ end
39
+ end
26
40
  end
27
41
  end
28
42
  end
@@ -6,7 +6,7 @@ module ERBLint
6
6
  module Linters
7
7
  module GitHub
8
8
  module Accessibility
9
- class IframeHasTitle < Linter
9
+ class IframeHasTitleCounter < Linter
10
10
  include ERBLint::Linters::CustomHelpers
11
11
  include LinterRegistry
12
12
 
@@ -23,7 +23,21 @@ module ERBLint
23
23
  generate_offense(self.class, processed_source, tag) if title.empty? && !aria_hidden?(tag)
24
24
  end
25
25
 
26
- rule_disabled?(processed_source)
26
+ counter_correct?(processed_source)
27
+ end
28
+
29
+ def autocorrect(processed_source, offense)
30
+ return unless offense.context
31
+
32
+ lambda do |corrector|
33
+ if processed_source.file_content.include?("erblint:counter #{simple_class_name}")
34
+ # update the counter if exists
35
+ corrector.replace(offense.source_range, offense.context)
36
+ else
37
+ # add comment with counter if none
38
+ corrector.insert_before(processed_source.source_buffer.source_range, "#{offense.context}\n")
39
+ end
40
+ end
27
41
  end
28
42
 
29
43
  private
@@ -6,7 +6,7 @@ module ERBLint
6
6
  module Linters
7
7
  module GitHub
8
8
  module Accessibility
9
- class ImageHasAlt < Linter
9
+ class ImageHasAltCounter < Linter
10
10
  include ERBLint::Linters::CustomHelpers
11
11
  include LinterRegistry
12
12
 
@@ -22,7 +22,21 @@ module ERBLint
22
22
  generate_offense(self.class, processed_source, tag) if alt.empty?
23
23
  end
24
24
 
25
- rule_disabled?(processed_source)
25
+ counter_correct?(processed_source)
26
+ end
27
+
28
+ def autocorrect(processed_source, offense)
29
+ return unless offense.context
30
+
31
+ lambda do |corrector|
32
+ if processed_source.file_content.include?("erblint:counter #{simple_class_name}")
33
+ # update the counter if exists
34
+ corrector.replace(offense.source_range, offense.context)
35
+ else
36
+ # add comment with counter if none
37
+ corrector.insert_before(processed_source.source_buffer.source_range, "#{offense.context}\n")
38
+ end
39
+ end
26
40
  end
27
41
  end
28
42
  end
@@ -10,7 +10,6 @@ module ERBLint
10
10
  include ERBLint::Linters::CustomHelpers
11
11
  include LinterRegistry
12
12
 
13
- INTERACTIVE_ELEMENTS = %w[button summary input select textarea a].freeze
14
13
  MESSAGE = "Nesting interactive elements produces invalid HTML, and ssistive technologies, such as screen readers, might ignore or respond unexpectedly to such nested controls."
15
14
 
16
15
  def run(processed_source)
@@ -0,0 +1,41 @@
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 NoAriaHiddenOnFocusableCounter < Linter
10
+ include ERBLint::Linters::CustomHelpers
11
+ include LinterRegistry
12
+
13
+ MESSAGE = "Elements that are focusable should not have `aria-hidden='true' because it will cause confusion for assistive technology users."
14
+
15
+ def run(processed_source)
16
+ tags(processed_source).each do |tag|
17
+ aria_hidden = possible_attribute_values(tag, "aria-hidden")
18
+ generate_offense(self.class, processed_source, tag) if aria_hidden.include?("true") && focusable?(tag)
19
+ end
20
+
21
+ counter_correct?(processed_source)
22
+ end
23
+
24
+ def autocorrect(processed_source, offense)
25
+ return unless offense.context
26
+
27
+ lambda do |corrector|
28
+ if processed_source.file_content.include?("erblint:counter #{simple_class_name}")
29
+ # update the counter if exists
30
+ corrector.replace(offense.source_range, offense.context)
31
+ else
32
+ # add comment with counter if none
33
+ corrector.insert_before(processed_source.source_buffer.source_range, "#{offense.context}\n")
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -6,7 +6,7 @@ module ERBLint
6
6
  module Linters
7
7
  module GitHub
8
8
  module Accessibility
9
- class NoPositiveTabIndex < Linter
9
+ class NoPositiveTabIndexCounter < Linter
10
10
  include ERBLint::Linters::CustomHelpers
11
11
  include LinterRegistry
12
12
 
@@ -20,7 +20,21 @@ module ERBLint
20
20
  generate_offense(self.class, processed_source, tag)
21
21
  end
22
22
 
23
- rule_disabled?(processed_source)
23
+ counter_correct?(processed_source)
24
+ end
25
+
26
+ def autocorrect(processed_source, offense)
27
+ return unless offense.context
28
+
29
+ lambda do |corrector|
30
+ if processed_source.file_content.include?("erblint:counter #{simple_class_name}")
31
+ # update the counter if exists
32
+ corrector.replace(offense.source_range, offense.context)
33
+ else
34
+ # add comment with counter if none
35
+ corrector.insert_before(processed_source.source_buffer.source_range, "#{offense.context}\n")
36
+ end
37
+ end
24
38
  end
25
39
  end
26
40
  end
@@ -6,7 +6,7 @@ module ERBLint
6
6
  module Linters
7
7
  module GitHub
8
8
  module Accessibility
9
- class NoRedundantImageAlt < Linter
9
+ class NoRedundantImageAltCounter < Linter
10
10
  include ERBLint::Linters::CustomHelpers
11
11
  include LinterRegistry
12
12
 
@@ -24,7 +24,21 @@ module ERBLint
24
24
  generate_offense(self.class, processed_source, tag) if (alt.downcase.split & REDUNDANT_ALT_WORDS).any?
25
25
  end
26
26
 
27
- rule_disabled?(processed_source)
27
+ counter_correct?(processed_source)
28
+ end
29
+
30
+ def autocorrect(processed_source, offense)
31
+ return unless offense.context
32
+
33
+ lambda do |corrector|
34
+ if processed_source.file_content.include?("erblint:counter #{simple_class_name}")
35
+ # update the counter if exists
36
+ corrector.replace(offense.source_range, offense.context)
37
+ else
38
+ # add comment with counter if none
39
+ corrector.insert_before(processed_source.source_buffer.source_range, "#{offense.context}\n")
40
+ end
41
+ end
28
42
  end
29
43
  end
30
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erblint-github
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub Open Source
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-27 00:00:00.000000000 Z
11
+ date: 2023-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erb_lint
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.1
19
+ version: 0.3.0
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.1
26
+ version: 0.3.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '5.15'
33
+ version: 5.17.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '5.15'
40
+ version: 5.17.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: mocha
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.14'
47
+ version: 2.0.2
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.14'
54
+ version: 2.0.2
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -72,28 +72,28 @@ dependencies:
72
72
  requirements:
73
73
  - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: 1.30.0
75
+ version: 1.44.1
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - '='
81
81
  - !ruby/object:Gem::Version
82
- version: 1.30.0
82
+ version: 1.44.1
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rubocop-github
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.17.0
89
+ version: 0.20.0
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.17.0
96
+ version: 0.20.0
97
97
  description: Template style checking for GitHub Ruby repositories
98
98
  email:
99
99
  - opensource+erblint-github@github.com
@@ -105,17 +105,18 @@ files:
105
105
  - README.md
106
106
  - lib/erblint-github/linters.rb
107
107
  - lib/erblint-github/linters/custom_helpers.rb
108
- - lib/erblint-github/linters/github/accessibility/avoid_both_disabled_and_aria_disabled.rb
108
+ - lib/erblint-github/linters/github/accessibility/avoid_both_disabled_and_aria_disabled_counter.rb
109
109
  - lib/erblint-github/linters/github/accessibility/avoid_generic_link_text_counter.rb
110
110
  - lib/erblint-github/linters/github/accessibility/disabled_attribute_counter.rb
111
- - lib/erblint-github/linters/github/accessibility/iframe_has_title.rb
112
- - lib/erblint-github/linters/github/accessibility/image_has_alt.rb
111
+ - lib/erblint-github/linters/github/accessibility/iframe_has_title_counter.rb
112
+ - lib/erblint-github/linters/github/accessibility/image_has_alt_counter.rb
113
113
  - lib/erblint-github/linters/github/accessibility/landmark_has_label_counter.rb
114
114
  - lib/erblint-github/linters/github/accessibility/link_has_href_counter.rb
115
115
  - lib/erblint-github/linters/github/accessibility/nested_interactive_elements_counter.rb
116
+ - lib/erblint-github/linters/github/accessibility/no_aria_hidden_on_focusable_counter.rb
116
117
  - lib/erblint-github/linters/github/accessibility/no_aria_label_misuse_counter.rb
117
- - lib/erblint-github/linters/github/accessibility/no_positive_tab_index.rb
118
- - lib/erblint-github/linters/github/accessibility/no_redundant_image_alt.rb
118
+ - lib/erblint-github/linters/github/accessibility/no_positive_tab_index_counter.rb
119
+ - lib/erblint-github/linters/github/accessibility/no_redundant_image_alt_counter.rb
119
120
  - lib/erblint-github/linters/github/accessibility/no_title_attribute_counter.rb
120
121
  - lib/erblint-github/linters/github/accessibility/svg_has_accessible_text_counter.rb
121
122
  - lib/tasks/docs.rake
@@ -125,7 +126,7 @@ licenses:
125
126
  - MIT
126
127
  metadata:
127
128
  rubygems_mfa_required: 'true'
128
- post_install_message:
129
+ post_install_message:
129
130
  rdoc_options: []
130
131
  require_paths:
131
132
  - lib
@@ -133,15 +134,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
133
134
  requirements:
134
135
  - - ">="
135
136
  - !ruby/object:Gem::Version
136
- version: 2.6.0
137
+ version: 2.7.0
137
138
  required_rubygems_version: !ruby/object:Gem::Requirement
138
139
  requirements:
139
140
  - - ">="
140
141
  - !ruby/object:Gem::Version
141
142
  version: '0'
142
143
  requirements: []
143
- rubygems_version: 3.2.9
144
- signing_key:
144
+ rubygems_version: 3.2.15
145
+ signing_key:
145
146
  specification_version: 4
146
147
  summary: erblint GitHub
147
148
  test_files: []