erblint-github 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +35 -0
- data/lib/erblint-github/linters/custom_helpers.rb +50 -0
- data/lib/erblint-github/linters/github/accessibility/no_redundant_image_alt.rb +33 -0
- data/lib/erblint-github/linters.rb +3 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 819c1bde423300648fdae7afee85bab8306b8ed234eaf04f1318d8a18abd380a
|
4
|
+
data.tar.gz: 16217f106609dde5113989809bd17fd6984ac170485222c8956460255cf514bb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 355ff2fc38afdf3f426c80da3cada076565f1b69e4ff0ca20f909bd0dacec0a7fb8b4f61c03a8701325cf5f96b95480877b4057d65d232f856a3f89325408a37
|
7
|
+
data.tar.gz: 955cda7b4f36d4c08755ed23718173bbe910a694de9763b806c15d35a312c01696d1d5c93ca61f4f415680b3cb787debf79464e452a3eb4dd5ede09462324080
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2021 GitHub
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# erblint-github
|
2
|
+
Template style checking for GitHub's Ruby projects
|
3
|
+
|
4
|
+
## Setup
|
5
|
+
|
6
|
+
1. Update your `Gemfile` and run `bundle install`
|
7
|
+
|
8
|
+
``` ruby
|
9
|
+
gem "erb_lint", require: false
|
10
|
+
gem "erblint-github"
|
11
|
+
```
|
12
|
+
|
13
|
+
2. Require the linters within the `.erb-linters` folder. This could be done by adding a file `.erb-linters/erblint-github.rb` with the following line.
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
require "erblint-github/linters"
|
17
|
+
```
|
18
|
+
|
19
|
+
3. Update the `erb-lint.yml` to configure the rule.
|
20
|
+
|
21
|
+
### .erb-lint.yml
|
22
|
+
|
23
|
+
```yaml
|
24
|
+
---
|
25
|
+
linters:
|
26
|
+
GitHub::Accessibility::NoRedundantImageAlt:
|
27
|
+
enabled: true
|
28
|
+
```
|
29
|
+
|
30
|
+
## Testing
|
31
|
+
|
32
|
+
```
|
33
|
+
bundle install
|
34
|
+
bundle exec rake test
|
35
|
+
```
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
require "openssl"
|
5
|
+
|
6
|
+
module ERBLint
|
7
|
+
module Linters
|
8
|
+
module CustomHelpers
|
9
|
+
def rule_disabled?(processed_source)
|
10
|
+
processed_source.parser.ast.descendants(:erb).each do |node|
|
11
|
+
indicator_node, _, code_node, = *node
|
12
|
+
indicator = indicator_node&.loc&.source
|
13
|
+
comment = code_node&.loc&.source&.strip
|
14
|
+
rule_name = self.class.name.match(/:?:?(\w+)\Z/)[1]
|
15
|
+
|
16
|
+
if indicator == "#" && comment.start_with?("erblint:disable") && comment.match(rule_name)
|
17
|
+
if @offenses.any?
|
18
|
+
clear_offenses
|
19
|
+
else
|
20
|
+
add_offense(processed_source.to_source_range(code_node.loc),
|
21
|
+
"Unused erblint:disable comment for #{rule_name}")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def generate_offense(klass, processed_source, tag, message = nil, replacement = nil)
|
28
|
+
message ||= klass::MESSAGE
|
29
|
+
klass_name = klass.name.demodulize
|
30
|
+
offense = ["#{klass_name}:#{message}", tag.node.loc.source].join("\n")
|
31
|
+
add_offense(processed_source.to_source_range(tag.loc), offense, replacement)
|
32
|
+
end
|
33
|
+
|
34
|
+
def possible_attribute_values(tag, attr_name)
|
35
|
+
value = tag.attributes[attr_name]&.value || nil
|
36
|
+
basic_conditional_code_check(value || "") || [value].compact
|
37
|
+
end
|
38
|
+
|
39
|
+
# Map possible values from condition
|
40
|
+
def basic_conditional_code_check(code)
|
41
|
+
conditional_match = code.match(/["'](.+)["']\sif|unless\s.+/) || code.match(/.+\s?\s["'](.+)["']\s:\s["'](.+)["']/)
|
42
|
+
[conditional_match[1], conditional_match[2]].compact if conditional_match
|
43
|
+
end
|
44
|
+
|
45
|
+
def tags(processed_source)
|
46
|
+
processed_source.parser.nodes_with_type(:tag).map { |tag_node| BetterHtml::Tree::Tag.from_node(tag_node) }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -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 NoRedundantImageAlt < Linter
|
10
|
+
include ERBLint::Linters::CustomHelpers
|
11
|
+
include LinterRegistry
|
12
|
+
|
13
|
+
MESSAGE = "<img> alt prop should not contain `image` or `picture` as screen readers already announce the element as an image"
|
14
|
+
REDUNDANT_ALT_WORDS = %w[image picture].freeze
|
15
|
+
|
16
|
+
def run(processed_source)
|
17
|
+
tags(processed_source).each do |tag|
|
18
|
+
next if tag.name != "img"
|
19
|
+
next if tag.closing?
|
20
|
+
|
21
|
+
alt = possible_attribute_values(tag, "alt").join
|
22
|
+
next if alt.empty?
|
23
|
+
|
24
|
+
generate_offense(self.class, processed_source, tag) if (alt.downcase.split & REDUNDANT_ALT_WORDS).any?
|
25
|
+
end
|
26
|
+
|
27
|
+
rule_disabled?(processed_source)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: erblint-github
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- GitHub Open Source
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-10-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: erb_lint
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.1'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.14'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.14'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mocha
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '12.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '12.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.13.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.13.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-github
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.16.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.16.0
|
97
|
+
description: Template style checking for GitHub Ruby repositories
|
98
|
+
email:
|
99
|
+
- opensource+erblint-github@github.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- LICENSE
|
105
|
+
- README.md
|
106
|
+
- lib/erblint-github/linters.rb
|
107
|
+
- lib/erblint-github/linters/custom_helpers.rb
|
108
|
+
- lib/erblint-github/linters/github/accessibility/no_redundant_image_alt.rb
|
109
|
+
homepage: https://github.com/github/erblint-github
|
110
|
+
licenses:
|
111
|
+
- MIT
|
112
|
+
metadata: {}
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: 2.5.0
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
requirements: []
|
128
|
+
rubygems_version: 3.0.3
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: erblint GitHub
|
132
|
+
test_files: []
|