rubocop-erb 0.2.3 → 0.3.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: df7883aaaa8cb83f5661b9edfcf74f12b6dc84bb89d135c518e7f78c6dee9068
4
- data.tar.gz: 5f8686b18e1f199663fdf3b8efa455e765e2d5f6800a6e4d8366610212eb25a4
3
+ metadata.gz: 742cdbab5d75368c8a97e45b610809a11ee36a806b7a6eea84e85b9f5810cd9e
4
+ data.tar.gz: 10da21545ab9f73ada119f5cb2a54dda6e297bbc5660325fa098aa0e92c83787
5
5
  SHA512:
6
- metadata.gz: 915462fa70d43cf062f9970c8ad0fa85f2f4249f26a0618204f8e5ff472e63ac934732c40ab87ddf5a49ceebf1b70b91b55a7cacf1aed0413370cede971eedaa
7
- data.tar.gz: c669c6a2849482d58abe45de7012b324cfe8b68cefc7b551e64013d135013ac579017f40c4ef0d865c947b9f8cb91d96c04c63426bd1e83b500cf4bc942d8c91
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.2.3)
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.1)
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.19.1)
38
+ loofah (2.21.3)
39
39
  crass (~> 1.0.2)
40
- nokogiri (>= 1.5.9)
40
+ nokogiri (>= 1.12.0)
41
41
  minitest (5.17.0)
42
- nokogiri (1.14.2-x86_64-linux)
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.6.2)
48
- rails-dom-testing (2.0.3)
49
- activesupport (>= 4.2.0)
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.5.0)
52
- loofah (~> 2.19, >= 2.19.1)
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
- E
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:11: E: Lint/Syntax: unexpected token $end
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
- 1 file inspected, 4 offenses detected, 3 offenses autocorrectable
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
@@ -75,6 +75,10 @@ Layout/IndentationWidth:
75
75
  Exclude:
76
76
  - '**/*.erb'
77
77
 
78
+ Layout/LeadingEmptyLine:
79
+ Exclude:
80
+ - '**/*.erb'
81
+
78
82
  Layout/LineEndStringConcatenationIndentation:
79
83
  Exclude:
80
84
  - '**/*.erb'
@@ -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 |erb|
48
- erb.children.first&.type == :indicator && erb.children.first&.to_a&.first == '#'
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Erb
5
- VERSION = '0.2.3'
5
+ VERSION = '0.3.0'
6
6
  end
7
7
  end
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.2.3
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-02-16 00:00:00.000000000 Z
11
+ date: 2023-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: better_html