erblint-github 0.1.0 → 0.1.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e7ce2b605ec0f31cb56b3e74e9f2eb4e10a11a8ab07d960596209b7d9674427
|
4
|
+
data.tar.gz: 0a74bf6def4d4c0b34c3f8bba3af39f7b3207fb87a72e08cf9143f3d42a1f577
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04e924e98c1fe68f5b3d56d8f0cf9a4c0083d70d55192661a1c93dcb457b870df4ab5841c8376c2afc8c7b3c86be87266df513e22cecfe5f33b230d450d4f5a4
|
7
|
+
data.tar.gz: f266202201dc8de5a3bd6089ed7b5562962b130ec5643775c3a910a242086a13280e4e449ccf26f3c0f9e5c1874693c8ce3971dff965117079ecd568c3c11e33
|
data/README.md
CHANGED
@@ -33,8 +33,12 @@ linters:
|
|
33
33
|
enabled: true
|
34
34
|
GitHub::Accessibility::ImageHasAlt:
|
35
35
|
enabled: true
|
36
|
+
GitHub::Accessibility::LandmarkHasLabelCounter:
|
37
|
+
enabled: true
|
36
38
|
GitHub::Accessibility::LinkHasHrefCounter:
|
37
39
|
enabled: true
|
40
|
+
GitHub::Accessibility::NestedInteractiveElementsCounter:
|
41
|
+
enabled: true
|
38
42
|
GitHub::Accessibility::NoAriaLabelMisuseCounter:
|
39
43
|
enabled: true
|
40
44
|
GitHub::Accessibility::NoPositiveTabIndex:
|
@@ -53,13 +57,15 @@ linters:
|
|
53
57
|
- [GitHub::Accessibility::AvoidGenericLinkTextCounter](./docs/rules/accessibility/avoid-generic-link-text-counter.md)
|
54
58
|
- [GitHub::Accessibility::DisabledAttributeCounter](./docs/rules/accessibility/disabled-attribute-counter-test)
|
55
59
|
- [GitHub::Accessibility::IframeHasTitle](./docs/rules/accessibility/iframe-has-title.md)
|
60
|
+
- [GitHub::Accessibility::LandmarkHasLabelCounter](./docs/rules/accessibility/landmark-has-label-counter.md)
|
56
61
|
- [GitHub::Accessibility::ImageHasAlt](./docs/rules/accessibility/image-has-alt.md)
|
57
|
-
- [GitHub::Accessibility::LinkHasHrefCounter](./docs/rules/accessibility/
|
62
|
+
- [GitHub::Accessibility::LinkHasHrefCounter](./docs/rules/accessibility/link-has-href-counter.md)
|
63
|
+
- [GitHub::Accessibility::NestedInteractiveElementsCounter](./docs/rules/accessibility/nested-interactive-elements-counter.md)
|
58
64
|
- [GitHub::Accessibility::NoAriaLabelMisuseCounter](./docs/rules/accessibility/no-aria-label-misuse-counter.md)
|
59
65
|
- [GitHub::Accessibility::NoPositiveTabIndex](./docs/rules/accessibility/no-positive-tab-index.md)
|
60
66
|
- [GitHub::Accessibility::NoRedundantImageAlt](./docs/rules/accessibility/no-redundant-image-alt.md)
|
61
67
|
- [GitHub::Accessibility::NoTitleAttributeCounter](./docs/rules/accessibility/no-title-attribute-counter.md)
|
62
|
-
- [GitHub::Accessibility::SvgHasAccessibleTextCounter](./docs/rules/accessibility/
|
68
|
+
- [GitHub::Accessibility::SvgHasAccessibleTextCounter](./docs/rules/accessibility/svg-has-accessible-text-counter.md)
|
63
69
|
|
64
70
|
## Testing
|
65
71
|
|
@@ -75,4 +81,4 @@ If you use VS Code, we highly encourage [ERB Linter extension](https://marketpla
|
|
75
81
|
## Note
|
76
82
|
|
77
83
|
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,
|
78
|
-
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.
|
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.
|
@@ -0,0 +1,75 @@
|
|
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 LandmarkHasLabelCounter < Linter
|
10
|
+
include ERBLint::Linters::CustomHelpers
|
11
|
+
include LinterRegistry
|
12
|
+
|
13
|
+
LANDMARK_ROLES = %w[complementary navigation region search].freeze
|
14
|
+
LANDMARK_TAGS = %w[aside nav section].freeze
|
15
|
+
MESSAGE = "Landmark elements should have an aria-label attribute, or aria-labelledby if a heading elements exists in the landmark."
|
16
|
+
ROLE_TAG_MAPPING = { "complementary" => "aside", "navigation" => "nav", "region" => "section" }.freeze
|
17
|
+
|
18
|
+
def get_additional_message(tag, roles)
|
19
|
+
role_matched = (roles & ROLE_TAG_MAPPING.keys).first
|
20
|
+
if role_matched
|
21
|
+
tag_matched = ROLE_TAG_MAPPING[role_matched]
|
22
|
+
|
23
|
+
if tag.name == tag_matched
|
24
|
+
"The <#{tag_matched}> element will automatically communicate a role of '#{role_matched}'. You can safely drop the role attribute."
|
25
|
+
else
|
26
|
+
replace_message = if tag.name == "div"
|
27
|
+
"If possible replace this tag with a <#{tag_matched}>."
|
28
|
+
else
|
29
|
+
"Wrapping this element in a <#{tag_matched}> and setting a label on it is reccomended."
|
30
|
+
end
|
31
|
+
|
32
|
+
"The <#{tag_matched}> element will automatically communicate a role of '#{role_matched}'. #{replace_message}"
|
33
|
+
end
|
34
|
+
elsif roles.include?("search") && tag.name != "form"
|
35
|
+
"The 'search' role works best when applied to a <form> element. If possible replace this tag with a <form>."
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def run(processed_source)
|
40
|
+
tags(processed_source).each do |tag|
|
41
|
+
next if tag.closing?
|
42
|
+
|
43
|
+
possible_roles = possible_attribute_values(tag, "role")
|
44
|
+
next unless LANDMARK_TAGS.include?(tag.name) && (possible_roles & LANDMARK_ROLES).empty?
|
45
|
+
next if tag.attributes["aria-label"]&.value&.present? || tag.attributes["aria-labelledby"]&.value&.present?
|
46
|
+
|
47
|
+
message = get_additional_message(tag, possible_roles)
|
48
|
+
if message
|
49
|
+
generate_offense(self.class, processed_source, tag, "#{MESSAGE}\n#{message}")
|
50
|
+
else
|
51
|
+
generate_offense(self.class, processed_source, tag)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
counter_correct?(processed_source)
|
56
|
+
end
|
57
|
+
|
58
|
+
def autocorrect(processed_source, offense)
|
59
|
+
return unless offense.context
|
60
|
+
|
61
|
+
lambda do |corrector|
|
62
|
+
if processed_source.file_content.include?("erblint:counter #{simple_class_name}")
|
63
|
+
# update the counter if exists
|
64
|
+
corrector.replace(offense.source_range, offense.context)
|
65
|
+
else
|
66
|
+
# add comment with counter if none
|
67
|
+
corrector.insert_before(processed_source.source_buffer.source_range, "#{offense.context}\n")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,55 @@
|
|
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 NestedInteractiveElementsCounter < Linter
|
10
|
+
include ERBLint::Linters::CustomHelpers
|
11
|
+
include LinterRegistry
|
12
|
+
|
13
|
+
INTERACTIVE_ELEMENTS = %w[button summary input select textarea a].freeze
|
14
|
+
MESSAGE = "Nesting interactive elements produces invalid HTML, and ssistive technologies, such as screen readers, might ignore or respond unexpectedly to such nested controls."
|
15
|
+
|
16
|
+
def run(processed_source)
|
17
|
+
last_interactive_element = nil
|
18
|
+
tags(processed_source).each do |tag|
|
19
|
+
next unless INTERACTIVE_ELEMENTS.include?(tag.name)
|
20
|
+
|
21
|
+
last_interactive_element = nil if last_interactive_element && tag.name == last_interactive_element.name && tag.closing?
|
22
|
+
next if tag.closing?
|
23
|
+
|
24
|
+
if last_interactive_element
|
25
|
+
next if last_interactive_element.name == "summary" && tag.name == "a"
|
26
|
+
next if tag.name == "input" && tag.attributes["type"]&.value == "hidden"
|
27
|
+
|
28
|
+
message = "Found <#{tag.name}> nested inside of <#{last_interactive_element.name}>.\n" + MESSAGE
|
29
|
+
generate_offense(self.class, processed_source, tag, message)
|
30
|
+
end
|
31
|
+
|
32
|
+
last_interactive_element = tag unless tag&.name == "input"
|
33
|
+
end
|
34
|
+
|
35
|
+
counter_correct?(processed_source)
|
36
|
+
end
|
37
|
+
|
38
|
+
def autocorrect(processed_source, offense)
|
39
|
+
return unless offense.context
|
40
|
+
|
41
|
+
lambda do |corrector|
|
42
|
+
if processed_source.file_content.include?("erblint:counter #{simple_class_name}")
|
43
|
+
# update the counter if exists
|
44
|
+
corrector.replace(offense.source_range, offense.context)
|
45
|
+
else
|
46
|
+
# add comment with counter if none
|
47
|
+
corrector.insert_before(processed_source.source_buffer.source_range, "#{offense.context}\n")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
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.
|
4
|
+
version: 0.1.1
|
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-
|
11
|
+
date: 2022-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: erb_lint
|
@@ -110,7 +110,9 @@ files:
|
|
110
110
|
- lib/erblint-github/linters/github/accessibility/disabled_attribute_counter.rb
|
111
111
|
- lib/erblint-github/linters/github/accessibility/iframe_has_title.rb
|
112
112
|
- lib/erblint-github/linters/github/accessibility/image_has_alt.rb
|
113
|
+
- lib/erblint-github/linters/github/accessibility/landmark_has_label_counter.rb
|
113
114
|
- lib/erblint-github/linters/github/accessibility/link_has_href_counter.rb
|
115
|
+
- lib/erblint-github/linters/github/accessibility/nested_interactive_elements_counter.rb
|
114
116
|
- lib/erblint-github/linters/github/accessibility/no_aria_label_misuse_counter.rb
|
115
117
|
- lib/erblint-github/linters/github/accessibility/no_positive_tab_index.rb
|
116
118
|
- lib/erblint-github/linters/github/accessibility/no_redundant_image_alt.rb
|