rubocop-erb 0.5.2 → 0.5.3

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: 227bb09e4901cb5d84bec63ed5c65f60d2955ddd4e16768ada9044845466fd16
4
- data.tar.gz: 8245ac7615be745be61b612c99d455eaa86b987d8328b4765e6b35efbbb62cba
3
+ metadata.gz: 1650bd31cfedf2d62fc05f8979e290bf33b04b8b42a6988fbab36ddef75a113f
4
+ data.tar.gz: 44de0adbdc72ac2abb1cb49778989bb6266f6c91a5cfeffd428c2c83df9ec764
5
5
  SHA512:
6
- metadata.gz: 5a479746047e28f98ca518824bfeb1ea2469e50faa2830eba0db2b76339e9fb2ab69c5de6abeb63c7e844180fd5198f6919a51de88d48e7455affc3b75db0165
7
- data.tar.gz: 70aa186e9d2e09011081e228f897a92ae65df19ec252839851b0a41ba404605f77847b942ca58c4dba78a9f222c49c830c039d3da714595a7bcad7f5cb42c728
6
+ metadata.gz: '059b029c8a15edf705991b6e0acf4e7b31dbae52afd4c109afc04902cb4e3db353b0dc3cc2c6fdc0118a361be190b755b73dfa54472a0d85097e70192e0f4203'
7
+ data.tar.gz: 1d69a7428f7caee5cbcfad7d987ac49f0f38b28b16cb11888fe1aa66a6a827bf8528b178f86e3b395b195f24dd588d67dbea48121448d2d23952a443e3f398f3
data/Gemfile.lock CHANGED
@@ -1,20 +1,20 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop-erb (0.5.2)
4
+ rubocop-erb (0.5.3)
5
5
  better_html
6
6
  rubocop (~> 1.45)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- actionview (7.1.3.2)
12
- activesupport (= 7.1.3.2)
11
+ actionview (7.1.3.4)
12
+ activesupport (= 7.1.3.4)
13
13
  builder (~> 3.1)
14
14
  erubi (~> 1.11)
15
15
  rails-dom-testing (~> 2.2)
16
16
  rails-html-sanitizer (~> 1.6)
17
- activesupport (7.1.3.2)
17
+ activesupport (7.1.3.4)
18
18
  base64
19
19
  bigdecimal
20
20
  concurrent-ruby (~> 1.0, >= 1.0.2)
@@ -33,31 +33,31 @@ GEM
33
33
  erubi (~> 1.4)
34
34
  parser (>= 2.4)
35
35
  smart_properties
36
- bigdecimal (3.1.6)
36
+ bigdecimal (3.1.8)
37
37
  builder (3.3.0)
38
- concurrent-ruby (1.2.3)
38
+ concurrent-ruby (1.3.3)
39
39
  connection_pool (2.4.1)
40
40
  crass (1.0.6)
41
41
  diff-lcs (1.5.1)
42
42
  drb (2.2.1)
43
43
  erubi (1.13.0)
44
- i18n (1.14.4)
44
+ i18n (1.14.5)
45
45
  concurrent-ruby (~> 1.0)
46
- json (2.7.1)
46
+ json (2.7.2)
47
47
  language_server-protocol (3.17.0.3)
48
48
  loofah (2.22.0)
49
49
  crass (~> 1.0.2)
50
50
  nokogiri (>= 1.12.0)
51
- minitest (5.22.2)
51
+ minitest (5.24.1)
52
52
  mutex_m (0.2.0)
53
53
  nokogiri (1.16.7-x86_64-linux)
54
54
  racc (~> 1.4)
55
- parallel (1.24.0)
56
- parser (3.3.0.5)
55
+ parallel (1.25.1)
56
+ parser (3.3.4.0)
57
57
  ast (~> 2.4.1)
58
58
  racc
59
- prism (0.24.0)
60
- racc (1.7.3)
59
+ prism (0.30.0)
60
+ racc (1.8.1)
61
61
  rails-dom-testing (2.2.0)
62
62
  activesupport (>= 5.0.0)
63
63
  minitest
@@ -66,50 +66,46 @@ GEM
66
66
  loofah (~> 2.21)
67
67
  nokogiri (~> 1.14)
68
68
  rainbow (3.1.1)
69
- rake (13.1.0)
70
- regexp_parser (2.9.0)
71
- rexml (3.2.6)
69
+ rake (13.2.1)
70
+ regexp_parser (2.9.2)
71
+ rexml (3.3.4)
72
+ strscan
72
73
  rspec (3.13.0)
73
74
  rspec-core (~> 3.13.0)
74
75
  rspec-expectations (~> 3.13.0)
75
76
  rspec-mocks (~> 3.13.0)
76
77
  rspec-core (3.13.0)
77
78
  rspec-support (~> 3.13.0)
78
- rspec-expectations (3.13.0)
79
+ rspec-expectations (3.13.1)
79
80
  diff-lcs (>= 1.2.0, < 2.0)
80
81
  rspec-support (~> 3.13.0)
81
- rspec-mocks (3.13.0)
82
+ rspec-mocks (3.13.1)
82
83
  diff-lcs (>= 1.2.0, < 2.0)
83
84
  rspec-support (~> 3.13.0)
84
85
  rspec-support (3.13.1)
85
- rubocop (1.62.0)
86
+ rubocop (1.65.1)
86
87
  json (~> 2.3)
87
88
  language_server-protocol (>= 3.17.0)
88
89
  parallel (~> 1.10)
89
90
  parser (>= 3.3.0.2)
90
91
  rainbow (>= 2.2.2, < 4.0)
91
- regexp_parser (>= 1.8, < 3.0)
92
+ regexp_parser (>= 2.4, < 3.0)
92
93
  rexml (>= 3.2.5, < 4.0)
93
94
  rubocop-ast (>= 1.31.1, < 2.0)
94
95
  ruby-progressbar (~> 1.7)
95
96
  unicode-display_width (>= 2.4.0, < 3.0)
96
- rubocop-ast (1.31.1)
97
- parser (>= 3.3.0.4)
98
- rubocop-capybara (2.20.0)
99
- rubocop (~> 1.41)
100
- rubocop-factory_bot (2.25.1)
101
- rubocop (~> 1.41)
97
+ rubocop-ast (1.32.0)
98
+ parser (>= 3.3.1.0)
102
99
  rubocop-rake (0.6.0)
103
100
  rubocop (~> 1.0)
104
- rubocop-rspec (2.27.1)
105
- rubocop (~> 1.40)
106
- rubocop-capybara (~> 2.17)
107
- rubocop-factory_bot (~> 2.22)
101
+ rubocop-rspec (3.0.4)
102
+ rubocop (~> 1.61)
108
103
  ruby-progressbar (1.13.0)
109
- sevencop (0.38.0)
104
+ sevencop (0.43.1)
110
105
  activesupport
111
106
  rubocop
112
107
  smart_properties (1.17.0)
108
+ strscan (3.1.0)
113
109
  tzinfo (2.0.6)
114
110
  concurrent-ruby (~> 1.0)
115
111
  unicode-display_width (2.5.0)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- rubocop-erb (0.5.2)
4
+ rubocop-erb (0.5.3)
5
5
  better_html
6
6
  rubocop (~> 1.45)
7
7
 
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Erb
5
+ module ProcessedSourceHelper
6
+ # Creates a new ProcessedSource, inheriting state from a donor
7
+ #
8
+ # @param [RuboCop::ProcessedSource] input_processed_source
9
+ # @param [String] code
10
+ # @return [RuboCop::ProcessedSource]
11
+ def self.code_to_processed_source(input_processed_source, path, code)
12
+ supports_prism = input_processed_source.respond_to?(:parser_engine)
13
+ processed_source = if supports_prism
14
+ ::RuboCop::ProcessedSource.new(
15
+ code,
16
+ input_processed_source.ruby_version,
17
+ path,
18
+ parser_engine: input_processed_source.parser_engine
19
+ )
20
+ else
21
+ ::RuboCop::ProcessedSource.new(
22
+ code,
23
+ input_processed_source.ruby_version,
24
+ path
25
+ )
26
+ end
27
+ processed_source.config = input_processed_source.config
28
+ processed_source.registry = input_processed_source.registry
29
+ processed_source
30
+ end
31
+ end
32
+ end
33
+ end
@@ -28,7 +28,11 @@ module RuboCop
28
28
  ruby_clips.map do |ruby_clip|
29
29
  {
30
30
  offset: ruby_clip.offset,
31
- processed_source: ruby_clip_to_processed_source(ruby_clip)
31
+ processed_source: ProcessedSourceHelper.code_to_processed_source(
32
+ @processed_source,
33
+ file_path,
34
+ ruby_clip.code
35
+ )
32
36
  }
33
37
  end
34
38
  end
@@ -66,28 +70,6 @@ module RuboCop
66
70
  ).ast
67
71
  end
68
72
 
69
- # @return [RuboCop::ProcessedSource]
70
- def ruby_clip_to_processed_source(ruby_clip)
71
- supports_prism = @processed_source.respond_to?(:parser_engine)
72
- processed_source = if supports_prism
73
- ::RuboCop::ProcessedSource.new(
74
- ruby_clip.code,
75
- @processed_source.ruby_version,
76
- file_path,
77
- parser_engine: @processed_source.parser_engine
78
- )
79
- else
80
- ::RuboCop::ProcessedSource.new(
81
- ruby_clip.code,
82
- @processed_source.ruby_version,
83
- file_path
84
- )
85
- end
86
- processed_source.config = @processed_source.config
87
- processed_source.registry = @processed_source.registry
88
- processed_source
89
- end
90
-
91
73
  # @return [Array<RuboCop::Erb::RubyClip>]
92
74
  def ruby_clips
93
75
  nodes.map do |node|
@@ -96,7 +78,7 @@ module RuboCop
96
78
  offset: node.location.begin_pos
97
79
  )
98
80
  end.flat_map do |ruby_clip|
99
- WhenDecomposer.call(ruby_clip)
81
+ WhenDecomposer.call(@processed_source, ruby_clip)
100
82
  end.map do |ruby_clip|
101
83
  KeywordRemover.call(ruby_clip)
102
84
  end.reject do |ruby_clip|
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Erb
5
- VERSION = '0.5.2'
5
+ VERSION = '0.5.3'
6
6
  end
7
7
  end
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'parser/current'
4
- require 'rubocop/ast/builder'
5
-
6
3
  module RuboCop
7
4
  module Erb
8
5
  class WhenDecomposer
@@ -13,15 +10,24 @@ module RuboCop
13
10
  /x.freeze
14
11
 
15
12
  class << self
13
+ # @param [RuboCop::ProcessedSource] processed_source
16
14
  # @param [RuboCop::Erb::RubyClip] ruby_clip
17
15
  # @return [Array<RuboCop::Erb::RubyClip>]
18
- def call(ruby_clip)
19
- new(ruby_clip).call
16
+ def call(
17
+ processed_source,
18
+ ruby_clip
19
+ )
20
+ new(processed_source, ruby_clip).call
20
21
  end
21
22
  end
22
23
 
24
+ # @param [RuboCop::ProcessedSource] processed_source
23
25
  # @param [RuboCop::Erb::RubyClip] ruby_clip
24
- def initialize(ruby_clip)
26
+ def initialize(
27
+ processed_source,
28
+ ruby_clip
29
+ )
30
+ @processed_source = processed_source
25
31
  @ruby_clip = ruby_clip
26
32
  end
27
33
 
@@ -53,14 +59,11 @@ module RuboCop
53
59
  # @param [String] source
54
60
  # @return [RuboCop::AST::Node]
55
61
  def parse(source)
56
- ::Parser::CurrentRuby.new(
57
- ::RuboCop::AST::Builder.new
58
- ).parse(
59
- ::Parser::Source::Buffer.new(
60
- '(string)',
61
- source: source
62
- )
63
- )
62
+ ProcessedSourceHelper.code_to_processed_source(
63
+ @processed_source,
64
+ '(string)',
65
+ source
66
+ ).ast
64
67
  end
65
68
  end
66
69
  end
data/lib/rubocop/erb.rb CHANGED
@@ -4,6 +4,7 @@ module RuboCop
4
4
  module Erb
5
5
  autoload :ConfigLoader, 'rubocop/erb/config_loader'
6
6
  autoload :KeywordRemover, 'rubocop/erb/keyword_remover'
7
+ autoload :ProcessedSourceHelper, 'rubocop/erb/processed_source_helper'
7
8
  autoload :RubyClip, 'rubocop/erb/ruby_clip'
8
9
  autoload :RubyExtractor, 'rubocop/erb/ruby_extractor'
9
10
  autoload :WhenDecomposer, 'rubocop/erb/when_decomposer'
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.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-28 00:00:00.000000000 Z
11
+ date: 2024-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: better_html
@@ -59,6 +59,7 @@ files:
59
59
  - lib/rubocop/erb.rb
60
60
  - lib/rubocop/erb/config_loader.rb
61
61
  - lib/rubocop/erb/keyword_remover.rb
62
+ - lib/rubocop/erb/processed_source_helper.rb
62
63
  - lib/rubocop/erb/rubocop_extension.rb
63
64
  - lib/rubocop/erb/ruby_clip.rb
64
65
  - lib/rubocop/erb/ruby_extractor.rb