rubocop-erb 0.2.3 → 0.3.0
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 +4 -4
- data/Gemfile.lock +12 -10
- data/README.md +17 -4
- data/config/default.yml +4 -0
- data/lib/rubocop/erb/ruby_extractor.rb +34 -2
- data/lib/rubocop/erb/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 742cdbab5d75368c8a97e45b610809a11ee36a806b7a6eea84e85b9f5810cd9e
|
4
|
+
data.tar.gz: 10da21545ab9f73ada119f5cb2a54dda6e297bbc5660325fa098aa0e92c83787
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 585098a85e2b0d6c4b3cd286014a2f2e1578e6744241f3cc3f098f2533f6346268c3e207937f359385b882db3ec4e189d8d680b787d28839c98c72881dbb617d
|
7
|
+
data.tar.gz: 21cdb3c2918b0d01eee173e24dafbedde1340459e7c884ca7e62e3688e85b53faf576ac883753774738b9b9f7cc62c2901c21150af092b02a1e44492e0a90ab5
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rubocop-erb (0.
|
4
|
+
rubocop-erb (0.3.0)
|
5
5
|
better_html
|
6
6
|
rubocop (~> 1.45)
|
7
7
|
|
@@ -20,7 +20,7 @@ GEM
|
|
20
20
|
minitest (>= 5.1)
|
21
21
|
tzinfo (~> 2.0)
|
22
22
|
ast (2.4.2)
|
23
|
-
better_html (2.0.
|
23
|
+
better_html (2.0.2)
|
24
24
|
actionview (>= 6.0)
|
25
25
|
activesupport (>= 6.0)
|
26
26
|
ast (~> 2.0)
|
@@ -35,21 +35,23 @@ GEM
|
|
35
35
|
i18n (1.12.0)
|
36
36
|
concurrent-ruby (~> 1.0)
|
37
37
|
json (2.6.3)
|
38
|
-
loofah (2.
|
38
|
+
loofah (2.21.3)
|
39
39
|
crass (~> 1.0.2)
|
40
|
-
nokogiri (>= 1.
|
40
|
+
nokogiri (>= 1.12.0)
|
41
41
|
minitest (5.17.0)
|
42
|
-
nokogiri (1.
|
42
|
+
nokogiri (1.15.3-x86_64-linux)
|
43
43
|
racc (~> 1.4)
|
44
44
|
parallel (1.22.1)
|
45
45
|
parser (3.2.0.0)
|
46
46
|
ast (~> 2.4.1)
|
47
|
-
racc (1.
|
48
|
-
rails-dom-testing (2.
|
49
|
-
activesupport (>=
|
47
|
+
racc (1.7.1)
|
48
|
+
rails-dom-testing (2.1.1)
|
49
|
+
activesupport (>= 5.0.0)
|
50
|
+
minitest
|
50
51
|
nokogiri (>= 1.6)
|
51
|
-
rails-html-sanitizer (1.
|
52
|
-
loofah (~> 2.
|
52
|
+
rails-html-sanitizer (1.6.0)
|
53
|
+
loofah (~> 2.21)
|
54
|
+
nokogiri (~> 1.14)
|
53
55
|
rainbow (3.1.1)
|
54
56
|
rake (13.0.6)
|
55
57
|
regexp_parser (2.6.2)
|
data/README.md
CHANGED
@@ -33,7 +33,7 @@ Now you can use RuboCop also for ERB templates.
|
|
33
33
|
```
|
34
34
|
$ bundle exec rubocop spec/fixtures/dummy.erb
|
35
35
|
Inspecting 1 file
|
36
|
-
|
36
|
+
C
|
37
37
|
|
38
38
|
Offenses:
|
39
39
|
|
@@ -46,14 +46,27 @@ spec/fixtures/dummy.erb:4:9: C: [Correctable] Style/ZeroLengthPredicate: Use !em
|
|
46
46
|
spec/fixtures/dummy.erb:5:4: C: [Correctable] Style/NegatedIf: Favor unless over if for negative conditions.
|
47
47
|
<% a if !b %>
|
48
48
|
^^^^^^^
|
49
|
-
spec/fixtures/dummy.erb:7:
|
50
|
-
(Using Ruby 2.6 parser; configure using TargetRubyVersion parameter, under AllCops)
|
49
|
+
spec/fixtures/dummy.erb:7:7: C: [Correctable] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
|
51
50
|
<% if "a" %>
|
51
|
+
^^^
|
52
52
|
|
53
|
+
1 file inspected, 4 offenses detected, 4 offenses autocorrectable
|
54
|
+
```
|
55
|
+
|
56
|
+
## Workaround
|
57
|
+
|
58
|
+
As a known issue, there seems to be a problem with .rubocop_todo.yml overriding config/default.yml provided by rubocop-erb, so we recommend adding a workaround to your .rubocop.yml as shown below:
|
53
59
|
|
54
|
-
|
60
|
+
```yaml
|
61
|
+
inherit_from: .rubocop_todo.yml
|
62
|
+
|
63
|
+
inherit_mode:
|
64
|
+
merge:
|
65
|
+
- Exclude
|
55
66
|
```
|
56
67
|
|
68
|
+
See [#15](https://github.com/r7kamura/rubocop-erb/issues/15) for more details.
|
69
|
+
|
57
70
|
## Related projects
|
58
71
|
|
59
72
|
- https://github.com/r7kamura/rubocop-haml
|
data/config/default.yml
CHANGED
@@ -44,8 +44,9 @@ module RuboCop
|
|
44
44
|
|
45
45
|
# @return [Array<BetterHtml::AST::Node>]
|
46
46
|
def erbs
|
47
|
-
root.descendants(:erb).reject do |
|
48
|
-
|
47
|
+
root.descendants(:erb).reject do |node|
|
48
|
+
erb_node = ErbNode.new(node)
|
49
|
+
erb_node.comment? || erb_node.escape?
|
49
50
|
end
|
50
51
|
end
|
51
52
|
|
@@ -97,6 +98,37 @@ module RuboCop
|
|
97
98
|
def template_source
|
98
99
|
@processed_source.raw_source
|
99
100
|
end
|
101
|
+
|
102
|
+
class ErbNode
|
103
|
+
# @param [BetterHtml::AST::Node] node
|
104
|
+
def initialize(node)
|
105
|
+
@node = node
|
106
|
+
end
|
107
|
+
|
108
|
+
# @return [Boolean]
|
109
|
+
def comment?
|
110
|
+
indicator == '#'
|
111
|
+
end
|
112
|
+
|
113
|
+
# @return [Boolean]
|
114
|
+
def escape?
|
115
|
+
indicator == '%'
|
116
|
+
end
|
117
|
+
|
118
|
+
private
|
119
|
+
|
120
|
+
# @return [BetterHtml::AST::Node, nil]
|
121
|
+
def first_child
|
122
|
+
@node.children.first
|
123
|
+
end
|
124
|
+
|
125
|
+
# @return [String, nil]
|
126
|
+
def indicator
|
127
|
+
return unless first_child&.type == :indicator
|
128
|
+
|
129
|
+
first_child&.to_a&.first
|
130
|
+
end
|
131
|
+
end
|
100
132
|
end
|
101
133
|
end
|
102
134
|
end
|
data/lib/rubocop/erb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-erb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: better_html
|