erblint-github 0.1.1 → 0.1.2

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: c3e42bd7e46e4628deda31d1657890c3ccc9e683d85943f2540629d36962b114
4
+ data.tar.gz: '099d8957fbc44e9739296d60c6f4436d7cf96ad0731bf69aca6edd5663acf98f'
5
5
  SHA512:
6
- metadata.gz: 04e924e98c1fe68f5b3d56d8f0cf9a4c0083d70d55192661a1c93dcb457b870df4ab5841c8376c2afc8c7b3c86be87266df513e22cecfe5f33b230d450d4f5a4
7
- data.tar.gz: f266202201dc8de5a3bd6089ed7b5562962b130ec5643775c3a910a242086a13280e4e449ccf26f3c0f9e5c1874693c8ce3971dff965117079ecd568c3c11e33
6
+ metadata.gz: e41f3c103e9b0c57cd9706706605d26e25aafdae1359d0d123d6dd05b32904a91e0609fcf42d0551bf871d904610c2e38b65e47b2cb10637424426714902394c
7
+ data.tar.gz: 6969aff49edec2d4f9d6768eb94d20c5ffc24b01495ea9ad68d134900a1351b7c7a5afcb5896c6b14da3212e36c1bf29c1a308c8fd5215a4bb055e9d303cdcc2
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
@@ -41,9 +41,9 @@ linters:
41
41
  enabled: true
42
42
  GitHub::Accessibility::NoAriaLabelMisuseCounter:
43
43
  enabled: true
44
- GitHub::Accessibility::NoPositiveTabIndex:
44
+ GitHub::Accessibility::NoPositiveTabIndexCounter:
45
45
  enabled: true
46
- GitHub::Accessibility::NoRedundantImageAlt:
46
+ GitHub::Accessibility::NoRedundantImageAltCounter:
47
47
  enabled: true
48
48
  GitHub::Accessibility::NoTitleAttributeCounter:
49
49
  enabled: true
@@ -53,20 +53,48 @@ linters:
53
53
 
54
54
  ## Rules
55
55
 
56
- - [GitHub::Accessibility::AvoidBothDisabledAndAriaDisabled](./docs/rules/accessibility/avoid-both-disabled-and-aria-disabled.md)
56
+ - [GitHub::Accessibility::AvoidBothDisabledAndAriaDisabledCounter](./docs/rules/accessibility/avoid-both-disabled-and-aria-disabled-counter.md)
57
57
  - [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)
58
+ - [GitHub::Accessibility::DisabledAttributeCounter](./docs/rules/accessibility/disabled-attribute-counter.md)
60
59
  - [GitHub::Accessibility::LandmarkHasLabelCounter](./docs/rules/accessibility/landmark-has-label-counter.md)
61
- - [GitHub::Accessibility::ImageHasAlt](./docs/rules/accessibility/image-has-alt.md)
62
60
  - [GitHub::Accessibility::LinkHasHrefCounter](./docs/rules/accessibility/link-has-href-counter.md)
63
61
  - [GitHub::Accessibility::NestedInteractiveElementsCounter](./docs/rules/accessibility/nested-interactive-elements-counter.md)
62
+ - [GitHub::Accessibility::IframeHasTitleCounter](./docs/rules/accessibility/iframe-has-title-counter.md)
63
+ - [GitHub::Accessibility::ImageHasAltCounter](./docs/rules/accessibility/image-has-alt-counter.md)
64
64
  - [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)
65
+ - [GitHub::Accessibility::NoPositiveTabIndexCounter](./docs/rules/accessibility/no-positive-tab-index-counter.md)
66
+ - [GitHub::Accessibility::NoRedundantImageAltCounter](./docs/rules/accessibility/no-redundant-image-alt-counter.md)
67
67
  - [GitHub::Accessibility::NoTitleAttributeCounter](./docs/rules/accessibility/no-title-attribute-counter.md)
68
68
  - [GitHub::Accessibility::SvgHasAccessibleTextCounter](./docs/rules/accessibility/svg-has-accessible-text-counter.md)
69
69
 
70
+ ## Disabling a rule (experimental)
71
+
72
+ _This is an experimental feature which should ideally be upstreamed to erblint_
73
+
74
+ `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.
75
+
76
+ 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:
77
+
78
+ ```.html.erb
79
+ <%# erblint:counter GitHub::Accessibility::LinkHasHrefCounter 1 %>
80
+ ```
81
+
82
+ 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.
83
+
84
+ 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.
85
+
86
+ ```
87
+ bundle exec erblint app/views app/components -a
88
+ ```
89
+
90
+ 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:
91
+
92
+ ```.html.erb
93
+ <%# erblint:disable GitHub::Accessibility::NoRedundantImageAlt %>
94
+ ```
95
+
96
+ However, unlike a counter, any subsequent offenses introduced to the file will not raise.
97
+
70
98
  ## Testing
71
99
 
72
100
  ```
@@ -81,4 +109,4 @@ If you use VS Code, we highly encourage [ERB Linter extension](https://marketpla
81
109
  ## Note
82
110
 
83
111
  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.
112
+ 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,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
@@ -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.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub Open Source
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-27 00:00:00.000000000 Z
11
+ date: 2022-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erb_lint
@@ -105,17 +105,17 @@ 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
116
  - 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
117
+ - lib/erblint-github/linters/github/accessibility/no_positive_tab_index_counter.rb
118
+ - lib/erblint-github/linters/github/accessibility/no_redundant_image_alt_counter.rb
119
119
  - lib/erblint-github/linters/github/accessibility/no_title_attribute_counter.rb
120
120
  - lib/erblint-github/linters/github/accessibility/svg_has_accessible_text_counter.rb
121
121
  - lib/tasks/docs.rake
@@ -140,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  - !ruby/object:Gem::Version
141
141
  version: '0'
142
142
  requirements: []
143
- rubygems_version: 3.2.9
143
+ rubygems_version: 3.3.10
144
144
  signing_key:
145
145
  specification_version: 4
146
146
  summary: erblint GitHub