rubocop-erb 0.6.0 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 81ef07f416359d5d003f64954122910aba25e3c46061a745c7b1d3e7bca5ad13
4
- data.tar.gz: 30b40434d770978c488224dc8acc6f6df3c6149ce74dd38ecdbbc131d6c54c64
3
+ metadata.gz: 543291fcf8f7203bc704dd84084df69318f1f596c4ad5ba26d4a904c06472b74
4
+ data.tar.gz: 490f8db2895f273c1818e70dcb656deee3287b3d16a3e7f60a02307619582634
5
5
  SHA512:
6
- metadata.gz: 4ffb0cb8881cf7d014b389071ab032e8f75e422bd5beabfd36532e3f78cb51f4c3e3cdfb11235242f342aa3f61b1434878d85e0986aa573c93ba120014ca0ce0
7
- data.tar.gz: 7a781ecb1c6b1041859b417ffed5030e517b261390c4b452a20ece26e0537e78cf2a67fb6a346597b111c8ae4e8204f329e509e67617eda4456724ef70eb0130
6
+ metadata.gz: c3abc86fed80b72f45ac335be071ffc50f90a5160ae8bbc7e2a4e8ecfec9bd0e239ba481793f0f745439224dc10f45985c9d1d812a3262d240ab2ccb212698e7
7
+ data.tar.gz: ca7e099b8b8821c788d4e5ad3ea96e470eda7b13ff94f09e6b90cf498919d4ae7a972c8fcafba99d1e6e65fab280bd159bfc559ba9aff0d08f750e549b6a1137
data/.rubocop.yml CHANGED
@@ -14,7 +14,7 @@ AllCops:
14
14
  Exclude:
15
15
  - spec/**/*.erb
16
16
  NewCops: enable
17
- TargetRubyVersion: 2.7
17
+ TargetRubyVersion: 3.0
18
18
 
19
19
  Gemspec/RequireMFA:
20
20
  Enabled: false
data/Gemfile.lock CHANGED
@@ -1,20 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop-erb (0.6.0)
5
- better_html
4
+ rubocop-erb (0.7.0)
5
+ herb (~> 0.7)
6
6
  lint_roller (~> 1.1)
7
7
  rubocop (~> 1.72, >= 1.72.1)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- actionview (7.1.5.1)
13
- activesupport (= 7.1.5.1)
14
- builder (~> 3.1)
15
- erubi (~> 1.11)
16
- rails-dom-testing (~> 2.2)
17
- rails-html-sanitizer (~> 1.6)
18
12
  activesupport (7.1.5.1)
19
13
  base64
20
14
  benchmark (>= 0.3)
@@ -31,51 +25,27 @@ GEM
31
25
  ast (2.4.2)
32
26
  base64 (0.2.0)
33
27
  benchmark (0.4.0)
34
- better_html (2.1.1)
35
- actionview (>= 6.0)
36
- activesupport (>= 6.0)
37
- ast (~> 2.0)
38
- erubi (~> 1.4)
39
- parser (>= 2.4)
40
- smart_properties
41
28
  bigdecimal (3.1.9)
42
- builder (3.3.0)
43
29
  concurrent-ruby (1.3.5)
44
30
  connection_pool (2.5.0)
45
- crass (1.0.6)
46
31
  diff-lcs (1.6.0)
47
32
  drb (2.2.1)
48
- erubi (1.13.1)
33
+ herb (0.7.1)
34
+ herb (0.7.1-x86_64-linux-gnu)
49
35
  i18n (1.14.7)
50
36
  concurrent-ruby (~> 1.0)
51
37
  json (2.10.1)
52
38
  language_server-protocol (3.17.0.4)
53
39
  lint_roller (1.1.0)
54
40
  logger (1.6.6)
55
- loofah (2.24.0)
56
- crass (~> 1.0.2)
57
- nokogiri (>= 1.12.0)
58
- mini_portile2 (2.8.8)
59
41
  minitest (5.25.4)
60
42
  mutex_m (0.3.0)
61
- nokogiri (1.18.7)
62
- mini_portile2 (~> 2.8.2)
63
- racc (~> 1.4)
64
- nokogiri (1.18.7-x86_64-linux-gnu)
65
- racc (~> 1.4)
66
43
  parallel (1.26.3)
67
44
  parser (3.3.7.1)
68
45
  ast (~> 2.4.1)
69
46
  racc
70
47
  prism (1.3.0)
71
48
  racc (1.8.1)
72
- rails-dom-testing (2.2.0)
73
- activesupport (>= 5.0.0)
74
- minitest
75
- nokogiri (>= 1.6)
76
- rails-html-sanitizer (1.6.2)
77
- loofah (~> 2.21)
78
- nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
79
49
  rainbow (3.1.1)
80
50
  rake (13.2.1)
81
51
  regexp_parser (2.10.0)
@@ -116,7 +86,6 @@ GEM
116
86
  sevencop (0.47.0)
117
87
  activesupport
118
88
  rubocop
119
- smart_properties (1.17.0)
120
89
  tzinfo (2.0.6)
121
90
  concurrent-ruby (~> 1.0)
122
91
  unicode-display_width (3.1.4)
@@ -137,4 +106,4 @@ DEPENDENCIES
137
106
  sevencop
138
107
 
139
108
  BUNDLED WITH
140
- 2.3.19
109
+ 2.5.23
@@ -87,7 +87,7 @@ module RuboCop
87
87
  | for[ \t]+\w+[ \t]+in
88
88
  )
89
89
  \b[ \t]*
90
- /x.freeze
90
+ /x
91
91
  end
92
92
 
93
93
  # Remove preceding `}`.
@@ -96,7 +96,7 @@ module RuboCop
96
96
  \A
97
97
  \s*
98
98
  }
99
- /x.freeze
99
+ /x
100
100
  end
101
101
 
102
102
  class TrailingSourceRemover
@@ -130,7 +130,7 @@ module RuboCop
130
130
  (?:\|[^|]*\|)?
131
131
  \s*
132
132
  \z
133
- /x.freeze
133
+ /x
134
134
  end
135
135
 
136
136
  # Remove trailing `then`.
@@ -140,7 +140,7 @@ module RuboCop
140
140
  then
141
141
  \s*
142
142
  \z
143
- /x.freeze
143
+ /x
144
144
  end
145
145
 
146
146
  # Remove trailing `do`.
@@ -153,7 +153,7 @@ module RuboCop
153
153
  \s*
154
154
  (\#.*)?
155
155
  \z
156
- /x.freeze
156
+ /x
157
157
  end
158
158
  end
159
159
  end
@@ -33,23 +33,12 @@ module RuboCop
33
33
  @code,
34
34
  @processed_source.ruby_version,
35
35
  @processed_source.path,
36
- **keyword_arguments
36
+ parser_engine: @processed_source.parser_engine
37
37
  )
38
38
  new_processed_source.config = @processed_source.config
39
39
  new_processed_source.registry = @processed_source.registry
40
40
  new_processed_source
41
41
  end
42
-
43
- private
44
-
45
- # @return [Hash]
46
- def keyword_arguments
47
- if @processed_source.respond_to?(:parser_engine)
48
- { parser_engine: @processed_source.parser_engine }
49
- else
50
- {}
51
- end
52
- end
53
42
  end
54
43
  end
55
44
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'better_html'
4
- require 'better_html/parser'
3
+ require 'herb'
5
4
  require 'rubocop'
6
5
 
7
6
  module RuboCop
@@ -38,43 +37,31 @@ module RuboCop
38
37
 
39
38
  private
40
39
 
41
- # @return [Array<BetterHtml::AST::Node>]
42
- def erbs
43
- root.descendants(:erb).reject do |node|
44
- erb_node = ErbNode.new(node)
45
- erb_node.comment? || erb_node.escape?
46
- end
47
- end
48
-
49
40
  # @return [String, nil]
50
41
  def file_path
51
42
  @processed_source.path
52
43
  end
53
44
 
54
- # @return [Enumerator<BetterHtml::AST::Node>]
45
+ # @return [Array<Herb::AST::Node>]
55
46
  def nodes
56
- erbs.flat_map do |erb|
57
- erb.descendants(:code).to_a
58
- end
47
+ visitor = ErbNodeVisitor.new
48
+ visitor.visit(root)
49
+ visitor.erb_nodes
59
50
  end
60
51
 
61
- # @return [BetterHtml::AST::Node]
52
+ # @return [Herb::AST::DocumentNode]
62
53
  def root
63
- ::BetterHtml::Parser.new(
64
- ::Parser::Source::Buffer.new(
65
- file_path,
66
- source: template_source
67
- ),
68
- template_language: :html
69
- ).ast
54
+ ::Herb.parse(template_source).value
70
55
  end
71
56
 
72
57
  # @return [Array<RuboCop::Erb::RubyClip>]
73
58
  def ruby_clips
74
59
  nodes.map do |node|
60
+ erb_start_location = node.content.location.start
61
+ line_range = @processed_source.buffer.line_range(erb_start_location.line)
75
62
  RubyClip.new(
76
- code: node.children.first,
77
- offset: node.location.begin_pos
63
+ code: node.content.value,
64
+ offset: line_range.begin.begin_pos + erb_start_location.column
78
65
  )
79
66
  end.flat_map do |ruby_clip|
80
67
  WhenDecomposer.call(@processed_source, ruby_clip)
@@ -95,34 +82,42 @@ module RuboCop
95
82
  @processed_source.raw_source
96
83
  end
97
84
 
98
- class ErbNode
99
- # @param [BetterHtml::AST::Node] node
100
- def initialize(node)
101
- @node = node
85
+ class ErbNodeVisitor < Herb::Visitor
86
+ # @return [Array<Symbol>]
87
+ def self.erb_visitor_methods
88
+ instance_methods.select { |method_name| method_name.to_s.start_with?('visit_erb_') }
102
89
  end
103
90
 
104
- # @return [Boolean]
105
- def comment?
106
- indicator == '#'
91
+ attr_reader :erb_nodes
92
+
93
+ def initialize
94
+ @erb_nodes = []
95
+ super
107
96
  end
108
97
 
109
98
  # @return [Boolean]
110
- def escape?
111
- indicator == '%'
99
+ def comment?(node)
100
+ node.tag_opening.value == '<%#'
112
101
  end
113
102
 
114
- private
103
+ # @return [Boolean]
104
+ def escape?(node)
105
+ node.tag_opening.value == '<%%'
106
+ end
115
107
 
116
- # @return [BetterHtml::AST::Node, nil]
117
- def first_child
118
- @node.children.first
108
+ erb_visitor_methods.each do |method_name|
109
+ class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
110
+ def #{method_name}(node) # def visit_erb_content_node(node)
111
+ record_node(node) # record_node(node)
112
+ super # super
113
+ end # end
114
+ RUBY
119
115
  end
120
116
 
121
- # @return [String, nil]
122
- def indicator
123
- return unless first_child&.type == :indicator
117
+ def record_node(node)
118
+ return if comment?(node) || escape?(node)
124
119
 
125
- first_child&.to_a&.first
120
+ @erb_nodes << node
126
121
  end
127
122
  end
128
123
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Erb
5
- VERSION = '0.6.0'
5
+ VERSION = '0.7.0'
6
6
  end
7
7
  end
@@ -7,7 +7,7 @@ module RuboCop
7
7
  \A
8
8
  \s*
9
9
  when[ \t]
10
- /x.freeze
10
+ /x
11
11
 
12
12
  class << self
13
13
  # @param [RuboCop::ProcessedSource] processed_source
data/rubocop-erb.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.summary = 'RuboCop plugin for ERB template.'
12
12
  spec.homepage = 'https://github.com/r7kamura/rubocop-erb'
13
13
  spec.license = 'MIT'
14
- spec.required_ruby_version = '>= 2.7'
14
+ spec.required_ruby_version = '>= 3.0'
15
15
 
16
16
  spec.metadata['homepage_uri'] = spec.homepage
17
17
  spec.metadata['source_code_uri'] = spec.homepage
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
30
  spec.require_paths = ['lib']
31
31
 
32
- spec.add_dependency 'better_html'
32
+ spec.add_dependency 'herb', '~> 0.7'
33
33
  spec.add_dependency 'lint_roller', '~> 1.1'
34
34
  spec.add_dependency 'rubocop', '~> 1.72', '>= 1.72.1'
35
35
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-erb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-04-09 00:00:00.000000000 Z
11
+ date: 2025-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: better_html
14
+ name: herb
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '0.7'
20
20
  type: :runtime
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'
26
+ version: '0.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: lint_roller
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -58,7 +58,7 @@ dependencies:
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
60
  version: 1.72.1
61
- description:
61
+ description:
62
62
  email:
63
63
  - r7kamura@gmail.com
64
64
  executables: []
@@ -74,8 +74,6 @@ files:
74
74
  - README.md
75
75
  - Rakefile
76
76
  - config/default.yml
77
- - gemfiles/ruby_2.7.gemfile
78
- - gemfiles/ruby_2.7.gemfile.lock
79
77
  - lib/rubocop/erb.rb
80
78
  - lib/rubocop/erb/keyword_remover.rb
81
79
  - lib/rubocop/erb/plugin.rb
@@ -93,7 +91,7 @@ metadata:
93
91
  source_code_uri: https://github.com/r7kamura/rubocop-erb
94
92
  changelog_uri: https://github.com/r7kamura/rubocop-erb/releases
95
93
  default_lint_roller_plugin: RuboCop::Erb::Plugin
96
- post_install_message:
94
+ post_install_message:
97
95
  rdoc_options: []
98
96
  require_paths:
99
97
  - lib
@@ -101,7 +99,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
101
99
  requirements:
102
100
  - - ">="
103
101
  - !ruby/object:Gem::Version
104
- version: '2.7'
102
+ version: '3.0'
105
103
  required_rubygems_version: !ruby/object:Gem::Requirement
106
104
  requirements:
107
105
  - - ">="
@@ -109,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
107
  version: '0'
110
108
  requirements: []
111
109
  rubygems_version: 3.3.27
112
- signing_key:
110
+ signing_key:
113
111
  specification_version: 4
114
112
  summary: RuboCop plugin for ERB template.
115
113
  test_files: []
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- gemspec path: '..'
6
-
7
- gem 'better_html', '< 2.1' # 2.1 dropped ruby 2.7 support.
8
- gem 'nokogiri', '~> 1.15.0'
9
- gem 'rake'
10
- gem 'rspec'
11
- gem 'rubocop-rake'
12
- gem 'rubocop-rspec'
13
- gem 'sevencop'
@@ -1,140 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- rubocop-erb (0.6.0)
5
- better_html
6
- lint_roller (~> 1.1)
7
- rubocop (~> 1.72, >= 1.72.1)
8
-
9
- GEM
10
- remote: https://rubygems.org/
11
- specs:
12
- actionview (7.1.5.1)
13
- activesupport (= 7.1.5.1)
14
- builder (~> 3.1)
15
- erubi (~> 1.11)
16
- rails-dom-testing (~> 2.2)
17
- rails-html-sanitizer (~> 1.6)
18
- activesupport (7.1.5.1)
19
- base64
20
- benchmark (>= 0.3)
21
- bigdecimal
22
- concurrent-ruby (~> 1.0, >= 1.0.2)
23
- connection_pool (>= 2.2.5)
24
- drb
25
- i18n (>= 1.6, < 2)
26
- logger (>= 1.4.2)
27
- minitest (>= 5.1)
28
- mutex_m
29
- securerandom (>= 0.3)
30
- tzinfo (~> 2.0)
31
- ast (2.4.2)
32
- base64 (0.2.0)
33
- benchmark (0.4.0)
34
- better_html (2.0.2)
35
- actionview (>= 6.0)
36
- activesupport (>= 6.0)
37
- ast (~> 2.0)
38
- erubi (~> 1.4)
39
- parser (>= 2.4)
40
- smart_properties
41
- bigdecimal (3.1.9)
42
- builder (3.3.0)
43
- concurrent-ruby (1.3.5)
44
- connection_pool (2.5.0)
45
- crass (1.0.6)
46
- diff-lcs (1.6.0)
47
- drb (2.2.1)
48
- erubi (1.13.1)
49
- i18n (1.14.7)
50
- concurrent-ruby (~> 1.0)
51
- json (2.10.1)
52
- language_server-protocol (3.17.0.4)
53
- lint_roller (1.1.0)
54
- logger (1.6.6)
55
- loofah (2.24.0)
56
- crass (~> 1.0.2)
57
- nokogiri (>= 1.12.0)
58
- mini_portile2 (2.8.8)
59
- minitest (5.25.4)
60
- mutex_m (0.3.0)
61
- nokogiri (1.15.7)
62
- mini_portile2 (~> 2.8.2)
63
- racc (~> 1.4)
64
- nokogiri (1.15.7-x86_64-linux)
65
- racc (~> 1.4)
66
- parallel (1.26.3)
67
- parser (3.3.7.1)
68
- ast (~> 2.4.1)
69
- racc
70
- racc (1.8.1)
71
- rails-dom-testing (2.2.0)
72
- activesupport (>= 5.0.0)
73
- minitest
74
- nokogiri (>= 1.6)
75
- rails-html-sanitizer (1.6.2)
76
- loofah (~> 2.21)
77
- nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
78
- rainbow (3.1.1)
79
- rake (13.2.1)
80
- regexp_parser (2.10.0)
81
- rspec (3.13.0)
82
- rspec-core (~> 3.13.0)
83
- rspec-expectations (~> 3.13.0)
84
- rspec-mocks (~> 3.13.0)
85
- rspec-core (3.13.3)
86
- rspec-support (~> 3.13.0)
87
- rspec-expectations (3.13.3)
88
- diff-lcs (>= 1.2.0, < 2.0)
89
- rspec-support (~> 3.13.0)
90
- rspec-mocks (3.13.2)
91
- diff-lcs (>= 1.2.0, < 2.0)
92
- rspec-support (~> 3.13.0)
93
- rspec-support (3.13.2)
94
- rubocop (1.72.2)
95
- json (~> 2.3)
96
- language_server-protocol (~> 3.17.0.2)
97
- lint_roller (~> 1.1.0)
98
- parallel (~> 1.10)
99
- parser (>= 3.3.0.2)
100
- rainbow (>= 2.2.2, < 4.0)
101
- regexp_parser (>= 2.9.3, < 3.0)
102
- rubocop-ast (>= 1.38.0, < 2.0)
103
- ruby-progressbar (~> 1.7)
104
- unicode-display_width (>= 2.4.0, < 4.0)
105
- rubocop-ast (1.38.0)
106
- parser (>= 3.3.1.0)
107
- rubocop-rake (0.7.1)
108
- lint_roller (~> 1.1)
109
- rubocop (>= 1.72.1)
110
- rubocop-rspec (3.5.0)
111
- lint_roller (~> 1.1)
112
- rubocop (~> 1.72, >= 1.72.1)
113
- ruby-progressbar (1.13.0)
114
- securerandom (0.3.2)
115
- sevencop (0.47.0)
116
- activesupport
117
- rubocop
118
- smart_properties (1.17.0)
119
- tzinfo (2.0.6)
120
- concurrent-ruby (~> 1.0)
121
- unicode-display_width (3.1.4)
122
- unicode-emoji (~> 4.0, >= 4.0.4)
123
- unicode-emoji (4.0.4)
124
-
125
- PLATFORMS
126
- ruby
127
- x86_64-linux
128
-
129
- DEPENDENCIES
130
- better_html (< 2.1)
131
- nokogiri (~> 1.15.0)
132
- rake
133
- rspec
134
- rubocop-erb!
135
- rubocop-rake
136
- rubocop-rspec
137
- sevencop
138
-
139
- BUNDLED WITH
140
- 2.3.19