rubocop-erb 0.5.2 → 0.5.4

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: 227bb09e4901cb5d84bec63ed5c65f60d2955ddd4e16768ada9044845466fd16
4
- data.tar.gz: 8245ac7615be745be61b612c99d455eaa86b987d8328b4765e6b35efbbb62cba
3
+ metadata.gz: 877390d14fe06387c7cfd3bd589030e34f2b8734467e9ee291c0733d1f5a2eef
4
+ data.tar.gz: 3a5aec17cb87b8f386dac6aa954bee5065e2f3dad0b90aad10e0b9288892c7ac
5
5
  SHA512:
6
- metadata.gz: 5a479746047e28f98ca518824bfeb1ea2469e50faa2830eba0db2b76339e9fb2ab69c5de6abeb63c7e844180fd5198f6919a51de88d48e7455affc3b75db0165
7
- data.tar.gz: 70aa186e9d2e09011081e228f897a92ae65df19ec252839851b0a41ba404605f77847b942ca58c4dba78a9f222c49c830c039d3da714595a7bcad7f5cb42c728
6
+ metadata.gz: b3f345e09bbb26bbb949e179aec06a5fdcf3a34e6bc1a60c33258d8f81ae3bbd08b014324dc082d40bdeb4c915ce25707c57a6d4a9215d17ab73a307c4442443
7
+ data.tar.gz: 355f7e581f3f9045dfd1f1dfe7f143836870ff1b9b14f22f9bb3e05e6af63693458ebc8023089763ea726ecd2c0b4dee9f5c91783e9af1e6830d1256a231334a
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.4)
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)
data/config/default.yml CHANGED
@@ -143,7 +143,7 @@ Lint/OutOfRangeRegexpRef:
143
143
  Exclude:
144
144
  - '**/*.erb'
145
145
 
146
- Lint/SyntaxError:
146
+ Lint/Syntax:
147
147
  Exclude:
148
148
  - '**/*.erb'
149
149
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- rubocop-erb (0.5.2)
4
+ rubocop-erb (0.5.4)
5
5
  better_html
6
6
  rubocop (~> 1.45)
7
7
 
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Erb
5
+ class ProcessedSourceBuilder
6
+ class << self
7
+ # Creates a new ProcessedSource, inheriting state from a donor.
8
+ #
9
+ # @param [String] code
10
+ # @param [RuboCop::ProcessedSource] processed_source
11
+ # @return [RuboCop::ProcessedSource]
12
+ def call(
13
+ code:,
14
+ processed_source:
15
+ )
16
+ new(
17
+ code: code,
18
+ processed_source: processed_source
19
+ ).call
20
+ end
21
+ end
22
+
23
+ def initialize(
24
+ code:,
25
+ processed_source:
26
+ )
27
+ @code = code
28
+ @processed_source = processed_source
29
+ end
30
+
31
+ def call
32
+ new_processed_source = ::RuboCop::ProcessedSource.new(
33
+ @code,
34
+ @processed_source.ruby_version,
35
+ @processed_source.path,
36
+ **keyword_arguments
37
+ )
38
+ new_processed_source.config = @processed_source.config
39
+ new_processed_source.registry = @processed_source.registry
40
+ new_processed_source
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
+ end
54
+ end
55
+ end
@@ -28,7 +28,10 @@ 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: ProcessedSourceBuilder.call(
32
+ code: ruby_clip.code,
33
+ processed_source: @processed_source
34
+ )
32
35
  }
33
36
  end
34
37
  end
@@ -59,35 +62,13 @@ module RuboCop
59
62
  def root
60
63
  ::BetterHtml::Parser.new(
61
64
  ::Parser::Source::Buffer.new(
62
- @file_path,
65
+ file_path,
63
66
  source: template_source
64
67
  ),
65
68
  template_language: :html
66
69
  ).ast
67
70
  end
68
71
 
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
72
  # @return [Array<RuboCop::Erb::RubyClip>]
92
73
  def ruby_clips
93
74
  nodes.map do |node|
@@ -96,7 +77,7 @@ module RuboCop
96
77
  offset: node.location.begin_pos
97
78
  )
98
79
  end.flat_map do |ruby_clip|
99
- WhenDecomposer.call(ruby_clip)
80
+ WhenDecomposer.call(@processed_source, ruby_clip)
100
81
  end.map do |ruby_clip|
101
82
  KeywordRemover.call(ruby_clip)
102
83
  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.4'
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,10 @@ 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
+ ProcessedSourceBuilder.call(
63
+ code: source,
64
+ processed_source: @processed_source
65
+ ).ast
64
66
  end
65
67
  end
66
68
  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 :ProcessedSourceBuilder, 'rubocop/erb/processed_source_builder'
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.4
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-10-01 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_builder.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