erblint-github 0.4.1 → 0.5.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: dcbe592387330f5ba0247660e9ed42074c9efbf0a0b2fa2ac02b9a846ecd2173
4
- data.tar.gz: 51111580933382545db7a1603b897026cb5566febc494f83aaf4a57e2b02c525
3
+ metadata.gz: 9f1a4a94379042a57da340419014484f8395304da4ba9e60427b1314208b65ce
4
+ data.tar.gz: a2412a3fcc727db9d01441c2fdd4c24e7f3d472e0b55f73bb1c79a6839275ad6
5
5
  SHA512:
6
- metadata.gz: 6bec2b9610ad690d506abc4b4e3e450cf492ccd36ee4784ef95902bc322d229b3435f3a19e9e06a434b7dc3c2d502872f1767c8301dfc3182625c7b5a4d1efa8
7
- data.tar.gz: 3796bc95ceebd37e04f711a40363eefe4681f91837d4936dee34d78b815a1cb50b8186cfce295a815147c010c56fed596a824e08d74596a028c0582b9ffda5c9
6
+ metadata.gz: 4fde78f77bdbeda8d2c8831b629eb2b45d81a1a48c535d1ae962c2c3c5b01a1aa36ba8880ff912d38e6332331d2dfffa2128fb51820a2c041e746b9ae3af6501
7
+ data.tar.gz: a30c11c3dad20f668f334f67b9278057b06b72cce181ec32d37b2aedb3916826ef71a6c518db62c29a0d54e97e2d76c0870dee956157f8ff370d834eb1a7380f
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "json"
5
+
6
+ # Accepts comma-separated args with simple rule name
7
+ # e.g. script/erblint-disable SomeRule1,SomeRule2
8
+ # e.g. script/erblint-disable GitHub::Accessibility::Rule1,SomeRule2
9
+ rules = ARGV[0]
10
+
11
+ rules_array = rules.split(",")
12
+ rules_map = {}
13
+ rules_array.each do |rule|
14
+ rule_underscored = rule.to_s.gsub("::", "/").
15
+ gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
16
+ gsub(/([a-z\d])([A-Z])/, '\1_\2').
17
+ tr("-", "_").
18
+ downcase.
19
+ gsub("git_hub", "github") # corrects rule names with `GitHub` name to align with erb-lint expectations
20
+ rules_map[rule] = rule_underscored
21
+ end
22
+
23
+ rules_map.each do |disable_comment_name, command_line_name|
24
+ output = `bin/erblint --format json --enable-linters #{command_line_name} app/views app/components packages/**/app/components app/forms/**/`
25
+ hashed_output = JSON.parse(output)
26
+ hashed_output["files"].each do |file|
27
+ path = file["path"]
28
+ offenses = file["offenses"]
29
+ line_numbers = offenses.map do |offense|
30
+ offense["location"]["last_line"]
31
+ end
32
+ File.open(path, "r+") do |file|
33
+ lines = file.each_line.to_a
34
+ line_numbers.each do |line_number|
35
+ line = lines[line_number - 1]
36
+ unless line.match?(/erblint:disable (?<rules>.*#{disable_comment_name}).*/)
37
+ existing_disable = line.match(/(?<=# erblint:disable)(.*) (?=%>)/)
38
+ if existing_disable
39
+ existing_disable_string = existing_disable.captures[0]
40
+ add_new_disable = "#{existing_disable_string}, #{disable_comment_name}"
41
+ lines[line_number - 1] = lines[line_number - 1].gsub(existing_disable_string, add_new_disable)
42
+ else
43
+ lines[line_number - 1] = lines[line_number - 1].gsub("\n", "") + "<%# erblint:disable #{disable_comment_name} %>\n"
44
+ end
45
+ end
46
+ end
47
+ file.rewind
48
+ file.write(lines.join)
49
+ end
50
+ end
51
+ end
52
+
53
+ exit 0
@@ -1,5 +1,7 @@
1
1
  ---
2
2
  linters:
3
+ NoUnusedDisable:
4
+ enabled: true
3
5
  GitHub::Accessibility::AriaLabelIsWellFormatted:
4
6
  enabled: true
5
7
  GitHub::Accessibility::AvoidBothDisabledAndAriaDisabled:
@@ -30,3 +32,5 @@ linters:
30
32
  enabled: true
31
33
  GitHub::Accessibility::SvgHasAccessibleText:
32
34
  enabled: true
35
+ GitHub::Accessibility::NoVisuallyHiddenInteractiveElements:
36
+ enabled: true
@@ -47,7 +47,7 @@ module ERBLint
47
47
  if offenses_count.zero?
48
48
  # have to adjust to get `\n` so we delete the whole line
49
49
  add_offense(processed_source.to_source_range(comment_node.loc.adjust(end_pos: 1)), "Unused erblint:counter comment for #{rule_name}", "") if comment_node
50
- return
50
+ return false
51
51
  end
52
52
 
53
53
  first_offense = @offenses[0]
@@ -10,11 +10,11 @@ module ERBLint
10
10
  include ERBLint::Linters::CustomHelpers
11
11
  include LinterRegistry
12
12
 
13
- MESSAGE = "The title attribute should never be used unless for an `<iframe>` as it is inaccessible for several groups of users."
13
+ MESSAGE = "The title attribute should never be used as it is inaccessible for several groups of users. Exceptions are provided for <iframe> and <link>."
14
14
 
15
15
  def run(processed_source)
16
16
  tags(processed_source).each do |tag|
17
- next if tag.name == "iframe"
17
+ next if tag.name == "iframe" || tag.name == "link"
18
18
  next if tag.closing?
19
19
 
20
20
  title = possible_attribute_values(tag, "title")
@@ -0,0 +1,33 @@
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 NoVisuallyHiddenInteractiveElements < Linter
10
+ include ERBLint::Linters::CustomHelpers
11
+ include LinterRegistry
12
+ INTERACTIVE_ELEMENTS = %w[a button summary select option textarea].freeze
13
+
14
+ MESSAGE = "Avoid visually hidding interactive elements. Visually hiding interactive elements can be confusing to sighted keyboard users as it appears their focus has been lost when they navigate to the hidden element"
15
+
16
+ def run(processed_source)
17
+ visually_hidden = false
18
+
19
+ tags(processed_source).each do |tag|
20
+ next if tag.closing?
21
+ classes = possible_attribute_values(tag, "class")
22
+ visually_hidden = true if classes.include?("sr-only")
23
+ next unless classes.include?("sr-only") || visually_hidden
24
+ if INTERACTIVE_ELEMENTS.include?(tag.name)
25
+ generate_offense(self.class, processed_source, tag)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ 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.4.1
4
+ version: 0.5.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: 2023-06-13 00:00:00.000000000 Z
11
+ date: 2023-10-05 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.4.0
19
+ version: 0.5.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.4.0
26
+ version: 0.5.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.18.0
33
+ version: 5.20.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.18.0
40
+ version: 5.20.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: 2.0.2
47
+ version: 2.1.0
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: 2.0.2
54
+ version: 2.1.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: 1.52.0
75
+ version: 1.56.4
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.52.0
82
+ version: 1.56.4
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rubocop-github
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -97,12 +97,14 @@ dependencies:
97
97
  description: Template style checking for GitHub Ruby repositories
98
98
  email:
99
99
  - opensource+erblint-github@github.com
100
- executables: []
100
+ executables:
101
+ - erblint-disable
101
102
  extensions: []
102
103
  extra_rdoc_files: []
103
104
  files:
104
105
  - LICENSE
105
106
  - README.md
107
+ - bin/erblint-disable
106
108
  - config/accessibility.yml
107
109
  - lib/erblint-github/linters.rb
108
110
  - lib/erblint-github/linters/custom_helpers.rb
@@ -120,6 +122,7 @@ files:
120
122
  - lib/erblint-github/linters/github/accessibility/no_positive_tab_index.rb
121
123
  - lib/erblint-github/linters/github/accessibility/no_redundant_image_alt.rb
122
124
  - lib/erblint-github/linters/github/accessibility/no_title_attribute.rb
125
+ - lib/erblint-github/linters/github/accessibility/no_visually_hidden_interactive_elements.rb
123
126
  - lib/erblint-github/linters/github/accessibility/svg_has_accessible_text.rb
124
127
  - lib/tasks/docs.rake
125
128
  - lib/tasks/tests.rake