erblint-github 0.0.9 → 0.1.0

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: cfd39a72bcefe35b0231242045b4aca7cfdf6468b795d2703528655039b9e7be
4
- data.tar.gz: 4331758cf201fe621f5510554766a6d300f46b43ef36d272e82f53d2ffaf420d
3
+ metadata.gz: 0e372a7e49311d6c270ff943ca1ec446c1f20ad06ac47fc784ce60c23f51b1d1
4
+ data.tar.gz: ac136d5460abc4d8fef0229036486b57565425bc4660ca252b6344378a6d1629
5
5
  SHA512:
6
- metadata.gz: ea54a4d64005d7be039a3f9ed620447ca673db7113e821f303cce4c35da74835c6f124afa84f3b7e8eb35e2adb278394aef1f6326a10f73ebfb3a9a342c956a1
7
- data.tar.gz: 942f3526203855f2a58c37f54b5d2775cc0de910a0adf057889dba2c4e60a1553276b640c7ba6c8fd6ed91d3b3af597ab86c0aa49e84f49ed47005feafcec59a
6
+ metadata.gz: 42290941d5f2d0b2643842e62a1e5f759d8387294f829a01b52c354103c42aade10fcf0d30571fd4b5a061b9a6cd968aaf6f5204189b0049971ac99f1baae71e
7
+ data.tar.gz: 557bbc994d0fb8a3e0a49a129f22c9a209be7219fa9b0812b77fbe4ba2ce66265cd36c42674572db33f7729d50dbc00c0388d06899a2ec0aadcd141e4a3e9a74
data/README.md CHANGED
@@ -27,10 +27,14 @@ linters:
27
27
  enabled: true
28
28
  GitHub::Accessibility::AvoidGenericLinkTextCounter:
29
29
  enabled: true
30
+ GitHub::Accessibility::DisabledAttributeCounter:
31
+ enabled: true
30
32
  GitHub::Accessibility::IframeHasTitle:
31
33
  enabled: true
32
34
  GitHub::Accessibility::ImageHasAlt:
33
35
  enabled: true
36
+ GitHub::Accessibility::LinkHasHrefCounter:
37
+ enabled: true
34
38
  GitHub::Accessibility::NoAriaLabelMisuseCounter:
35
39
  enabled: true
36
40
  GitHub::Accessibility::NoPositiveTabIndex:
@@ -39,18 +43,23 @@ linters:
39
43
  enabled: true
40
44
  GitHub::Accessibility::NoTitleAttributeCounter:
41
45
  enabled: true
46
+ GitHub::Accessibility::SvgHasAccessibleTextCounter:
47
+ enabled: true
42
48
  ```
43
49
 
44
50
  ## Rules
45
51
 
46
52
  - [GitHub::Accessibility::AvoidBothDisabledAndAriaDisabled](./docs/rules/accessibility/avoid-both-disabled-and-aria-disabled.md)
47
53
  - [GitHub::Accessibility::AvoidGenericLinkTextCounter](./docs/rules/accessibility/avoid-generic-link-text-counter.md)
54
+ - [GitHub::Accessibility::DisabledAttributeCounter](./docs/rules/accessibility/disabled-attribute-counter-test)
48
55
  - [GitHub::Accessibility::IframeHasTitle](./docs/rules/accessibility/iframe-has-title.md)
49
56
  - [GitHub::Accessibility::ImageHasAlt](./docs/rules/accessibility/image-has-alt.md)
57
+ - [GitHub::Accessibility::LinkHasHrefCounter](./docs/rules/accessibility/link_has_href-counter.md)
50
58
  - [GitHub::Accessibility::NoAriaLabelMisuseCounter](./docs/rules/accessibility/no-aria-label-misuse-counter.md)
51
59
  - [GitHub::Accessibility::NoPositiveTabIndex](./docs/rules/accessibility/no-positive-tab-index.md)
52
60
  - [GitHub::Accessibility::NoRedundantImageAlt](./docs/rules/accessibility/no-redundant-image-alt.md)
53
61
  - [GitHub::Accessibility::NoTitleAttributeCounter](./docs/rules/accessibility/no-title-attribute-counter.md)
62
+ - [GitHub::Accessibility::SvgHasAccessibleTextCounter](./docs/rules/accessibility/svg_has_accessible_text_counter.md)
54
63
 
55
64
  ## Testing
56
65
 
@@ -0,0 +1,45 @@
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 DisabledAttributeCounter < Linter
10
+ include ERBLint::Linters::CustomHelpers
11
+ include LinterRegistry
12
+
13
+ VALID_DISABLED_TAGS = %w[button input textarea option select fieldset optgroup task-lists].freeze
14
+ MESSAGE = "`disabled` is only valid on #{VALID_DISABLED_TAGS.join(', ')}."
15
+
16
+ def run(processed_source)
17
+ tags(processed_source).each do |tag|
18
+ next if tag.closing?
19
+ next if VALID_DISABLED_TAGS.include?(tag.name)
20
+ next if tag.attributes["disabled"].nil?
21
+
22
+ generate_offense(self.class, processed_source, tag)
23
+ end
24
+
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
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,45 @@
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 LinkHasHrefCounter < Linter
10
+ include ERBLint::Linters::CustomHelpers
11
+ include LinterRegistry
12
+
13
+ MESSAGE = "Links should go somewhere, you probably want to use a `<button>` instead."
14
+
15
+ def run(processed_source)
16
+ tags(processed_source).each do |tag|
17
+ next if tag.name != "a"
18
+ next if tag.closing?
19
+
20
+ href = possible_attribute_values(tag, "href")
21
+ name = tag.attributes["name"]
22
+ generate_offense(self.class, processed_source, tag) if (!name && href.empty?) || href.include?("#")
23
+ end
24
+
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
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,60 @@
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 SvgHasAccessibleTextCounter < Linter
10
+ include ERBLint::Linters::CustomHelpers
11
+ include LinterRegistry
12
+
13
+ MESSAGE = "`<svg>` must have accessible text. Set `aria-label`, or `aria-labelledby`, or nest a `<title>` element. However, if the `<svg>` is purely decorative, hide it with `aria-hidden='true'.\nFor more info, see https://css-tricks.com/accessible-svgs/."
14
+
15
+ def run(processed_source)
16
+ current_svg = nil
17
+ has_accessible_label = false
18
+
19
+ tags(processed_source).each do |tag|
20
+ # Checks whether tag is a <title> nested in an <svg>
21
+ has_accessible_label = true if current_svg && tag.name == "title" && !tag.closing?
22
+
23
+ next if tag.name != "svg"
24
+
25
+ if tag.closing?
26
+ generate_offense(self.class, processed_source, current_svg) unless has_accessible_label
27
+ current_svg = nil
28
+ elsif possible_attribute_values(tag, "aria-hidden").join == "true"
29
+ has_accessible_label = true
30
+ current_svg = tag
31
+ else
32
+ current_svg = tag
33
+ aria_label = possible_attribute_values(tag, "aria-label").join
34
+ aria_labelledby = possible_attribute_values(tag, "aria-labelledby").join
35
+
36
+ has_accessible_label = aria_label.present? || aria_labelledby.present?
37
+ end
38
+ end
39
+
40
+ counter_correct?(processed_source)
41
+ end
42
+
43
+ def autocorrect(processed_source, offense)
44
+ return unless offense.context
45
+
46
+ lambda do |corrector|
47
+ if processed_source.file_content.include?("erblint:counter #{simple_class_name}")
48
+ # update the counter if exists
49
+ corrector.replace(offense.source_range, offense.context)
50
+ else
51
+ # add comment with counter if none
52
+ corrector.insert_before(processed_source.source_buffer.source_range, "#{offense.context}\n")
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ 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.0.9
4
+ version: 0.1.0
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-12 00:00:00.000000000 Z
11
+ date: 2022-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erb_lint
@@ -107,12 +107,15 @@ files:
107
107
  - lib/erblint-github/linters/custom_helpers.rb
108
108
  - lib/erblint-github/linters/github/accessibility/avoid_both_disabled_and_aria_disabled.rb
109
109
  - lib/erblint-github/linters/github/accessibility/avoid_generic_link_text_counter.rb
110
+ - lib/erblint-github/linters/github/accessibility/disabled_attribute_counter.rb
110
111
  - lib/erblint-github/linters/github/accessibility/iframe_has_title.rb
111
112
  - lib/erblint-github/linters/github/accessibility/image_has_alt.rb
113
+ - lib/erblint-github/linters/github/accessibility/link_has_href_counter.rb
112
114
  - lib/erblint-github/linters/github/accessibility/no_aria_label_misuse_counter.rb
113
115
  - lib/erblint-github/linters/github/accessibility/no_positive_tab_index.rb
114
116
  - lib/erblint-github/linters/github/accessibility/no_redundant_image_alt.rb
115
117
  - lib/erblint-github/linters/github/accessibility/no_title_attribute_counter.rb
118
+ - lib/erblint-github/linters/github/accessibility/svg_has_accessible_text_counter.rb
116
119
  - lib/tasks/docs.rake
117
120
  - lib/tasks/tests.rake
118
121
  homepage: https://github.com/github/erblint-github
@@ -135,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
138
  - !ruby/object:Gem::Version
136
139
  version: '0'
137
140
  requirements: []
138
- rubygems_version: 3.2.32
141
+ rubygems_version: 3.2.9
139
142
  signing_key:
140
143
  specification_version: 4
141
144
  summary: erblint GitHub