erblint-github 0.0.1 → 0.0.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: 819c1bde423300648fdae7afee85bab8306b8ed234eaf04f1318d8a18abd380a
4
- data.tar.gz: 16217f106609dde5113989809bd17fd6984ac170485222c8956460255cf514bb
3
+ metadata.gz: e46c63a275b6e7d34b0aab81c0de051625bfbd7fc6c3fedb944a6d10a5ba3cff
4
+ data.tar.gz: 33984e9857ae9a998a3ae56a9fd29c0bf89557d41eee3698cb13731327da7988
5
5
  SHA512:
6
- metadata.gz: 355ff2fc38afdf3f426c80da3cada076565f1b69e4ff0ca20f909bd0dacec0a7fb8b4f61c03a8701325cf5f96b95480877b4057d65d232f856a3f89325408a37
7
- data.tar.gz: 955cda7b4f36d4c08755ed23718173bbe910a694de9763b806c15d35a312c01696d1d5c93ca61f4f415680b3cb787debf79464e452a3eb4dd5ede09462324080
6
+ metadata.gz: 0404a048ebd068503aa1f7521a9c1f116165e3d9c507bee6e0a04c28ec3871b12fb53dc1141ff57981d013ac0af8d2bb41b21faea545c7741ff28f1d4e4c3b95
7
+ data.tar.gz: c64a47d57b7bb87ed7f1437be1430f44f860f58e0d28a6acca5b530e442350e9d1e8f28d83fdf8230d731a0851e812f9ad82278bec964aefffdac16fc250a530
data/README.md CHANGED
@@ -23,13 +23,23 @@ require "erblint-github/linters"
23
23
  ```yaml
24
24
  ---
25
25
  linters:
26
+ GitHub::Accessibility::ImageHasAlt:
27
+ enabled: true
28
+ GitHub::Accessibility::NoAriaLabelMisuse:
29
+ enabled: true
26
30
  GitHub::Accessibility::NoRedundantImageAlt:
27
31
  enabled: true
28
32
  ```
29
33
 
34
+ ### Rules
35
+
36
+ - [GitHub::Accessibility::ImageHasAlt](./docs/rules/accessibility/no-aria-label-misuse.md)
37
+ - [GitHub::Accessibility::NoAriaLabelMisuse](./docs/rules/accessibility/image-has-alt.md)
38
+ - [GitHub::Accessibility::NoRedundantImageAlt](./docs/rules/accessibility/no-redundant-image-alt.md)
39
+
30
40
  ## Testing
31
41
 
32
42
  ```
33
43
  bundle install
34
- bundle exec rake test
44
+ bundle exec rake
35
45
  ```
@@ -11,7 +11,7 @@ module ERBLint
11
11
  indicator_node, _, code_node, = *node
12
12
  indicator = indicator_node&.loc&.source
13
13
  comment = code_node&.loc&.source&.strip
14
- rule_name = self.class.name.match(/:?:?(\w+)\Z/)[1]
14
+ rule_name = self.class.name.gsub("ERBLint::Linters::", "")
15
15
 
16
16
  if indicator == "#" && comment.start_with?("erblint:disable") && comment.match(rule_name)
17
17
  if @offenses.any?
@@ -0,0 +1,31 @@
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 ImageHasAlt < Linter
10
+ include ERBLint::Linters::CustomHelpers
11
+ include LinterRegistry
12
+
13
+ MESSAGE = "<img> should have an alt prop with meaningful text or an empty string for decorative images"
14
+
15
+ def run(processed_source)
16
+ tags(processed_source).each do |tag|
17
+ next if tag.name != "img"
18
+ next if tag.closing?
19
+
20
+ alt = possible_attribute_values(tag, "alt")
21
+
22
+ generate_offense(self.class, processed_source, tag) if alt.empty?
23
+ end
24
+
25
+ rule_disabled?(processed_source)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,43 @@
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 NoAriaLabelMisuse < Linter
10
+ include ERBLint::Linters::CustomHelpers
11
+ include LinterRegistry
12
+
13
+ GENERIC_ELEMENTS = %w[span div].freeze
14
+ NAME_RESTRICTED_ELEMENTS = %w[h1 h2 h3 h4 h5 h6 strong i p b code].freeze
15
+
16
+ # https://w3c.github.io/aria/#namefromprohibited
17
+ ROLES_WHICH_CANNOT_BE_NAMED = %w[caption code definition deletion emphasis insertion mark none paragraph presentation strong subscript suggestion superscript term time].freeze
18
+
19
+ MESSAGE = "[aria-label] and [aria-labelledby] usage are only reliably supported on interactive elements and a subset of ARIA roles"
20
+
21
+ def run(processed_source)
22
+ tags(processed_source).each do |tag|
23
+ next if tag.closing?
24
+ next unless possible_attribute_values(tag, "aria-label").present? || possible_attribute_values(tag, "aria-labelledby").present?
25
+
26
+ if NAME_RESTRICTED_ELEMENTS.include?(tag.name)
27
+ generate_offense(self.class, processed_source, tag)
28
+ elsif GENERIC_ELEMENTS.include?(tag.name)
29
+ role = possible_attribute_values(tag, "role")
30
+ if role.present?
31
+ generate_offense(self.class, processed_source, tag) if ROLES_WHICH_CANNOT_BE_NAMED.include?(role.join)
32
+ else
33
+ generate_offense(self.class, processed_source, tag)
34
+ end
35
+ end
36
+ end
37
+ rule_disabled?(processed_source)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ 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.1
4
+ version: 0.0.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: 2021-10-27 00:00:00.000000000 Z
11
+ date: 2021-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erb_lint
@@ -105,6 +105,8 @@ 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/image_has_alt.rb
109
+ - lib/erblint-github/linters/github/accessibility/no_aria_label_misuse.rb
108
110
  - lib/erblint-github/linters/github/accessibility/no_redundant_image_alt.rb
109
111
  homepage: https://github.com/github/erblint-github
110
112
  licenses: