rubocop-erb 0.3.0 → 0.4.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: 742cdbab5d75368c8a97e45b610809a11ee36a806b7a6eea84e85b9f5810cd9e
4
- data.tar.gz: 10da21545ab9f73ada119f5cb2a54dda6e297bbc5660325fa098aa0e92c83787
3
+ metadata.gz: 69ccb933a550ae4dfe699ed42350e4c39eb7b2e0e7488915ec3ead433ef1d2be
4
+ data.tar.gz: cf759f1dddd604d8843fccf1bd71fa3a2d8f7a833c08f35048452bb0de18955e
5
5
  SHA512:
6
- metadata.gz: 585098a85e2b0d6c4b3cd286014a2f2e1578e6744241f3cc3f098f2533f6346268c3e207937f359385b882db3ec4e189d8d680b787d28839c98c72881dbb617d
7
- data.tar.gz: 21cdb3c2918b0d01eee173e24dafbedde1340459e7c884ca7e62e3688e85b53faf576ac883753774738b9b9f7cc62c2901c21150af092b02a1e44492e0a90ab5
6
+ metadata.gz: 65177bdd79e44d0ed83f431c480ec5399ebcd4fb5d196a4c1bab61947984525cc2c2f8aaf6ff3978fd66558d058e8fcf2fb50f88d0c27ed4715613b5426e73f5
7
+ data.tar.gz: 4c2ecc5c6b0be161bb72799e17761d50b5dc8387d1ae1de6043ed8dc02dfd2a16093ed49c5ca529e93c6e3d004079406d345e5d5155e883dd4527e0c4be09f65
data/Gemfile CHANGED
@@ -5,6 +5,7 @@ source 'https://rubygems.org'
5
5
  # Specify your gem's dependencies in rubocop-erb.gemspec
6
6
  gemspec
7
7
 
8
+ gem 'prism'
8
9
  gem 'rake'
9
10
  gem 'rspec'
10
11
  gem 'rubocop-rake'
data/Gemfile.lock CHANGED
@@ -1,25 +1,31 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop-erb (0.3.0)
4
+ rubocop-erb (0.4.0)
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.0.4.2)
12
- activesupport (= 7.0.4.2)
11
+ actionview (7.1.3.2)
12
+ activesupport (= 7.1.3.2)
13
13
  builder (~> 3.1)
14
- erubi (~> 1.4)
15
- rails-dom-testing (~> 2.0)
16
- rails-html-sanitizer (~> 1.1, >= 1.2.0)
17
- activesupport (7.0.4.2)
14
+ erubi (~> 1.11)
15
+ rails-dom-testing (~> 2.2)
16
+ rails-html-sanitizer (~> 1.6)
17
+ activesupport (7.1.3.2)
18
+ base64
19
+ bigdecimal
18
20
  concurrent-ruby (~> 1.0, >= 1.0.2)
21
+ connection_pool (>= 2.2.5)
22
+ drb
19
23
  i18n (>= 1.6, < 2)
20
24
  minitest (>= 5.1)
25
+ mutex_m
21
26
  tzinfo (~> 2.0)
22
27
  ast (2.4.2)
28
+ base64 (0.2.0)
23
29
  better_html (2.0.2)
24
30
  actionview (>= 6.0)
25
31
  activesupport (>= 6.0)
@@ -27,25 +33,32 @@ GEM
27
33
  erubi (~> 1.4)
28
34
  parser (>= 2.4)
29
35
  smart_properties
36
+ bigdecimal (3.1.6)
30
37
  builder (3.2.4)
31
- concurrent-ruby (1.2.0)
38
+ concurrent-ruby (1.2.3)
39
+ connection_pool (2.4.1)
32
40
  crass (1.0.6)
33
- diff-lcs (1.5.0)
41
+ diff-lcs (1.5.1)
42
+ drb (2.2.1)
34
43
  erubi (1.12.0)
35
- i18n (1.12.0)
44
+ i18n (1.14.4)
36
45
  concurrent-ruby (~> 1.0)
37
- json (2.6.3)
38
- loofah (2.21.3)
46
+ json (2.7.1)
47
+ language_server-protocol (3.17.0.3)
48
+ loofah (2.22.0)
39
49
  crass (~> 1.0.2)
40
50
  nokogiri (>= 1.12.0)
41
- minitest (5.17.0)
42
- nokogiri (1.15.3-x86_64-linux)
51
+ minitest (5.22.2)
52
+ mutex_m (0.2.0)
53
+ nokogiri (1.16.2-x86_64-linux)
43
54
  racc (~> 1.4)
44
- parallel (1.22.1)
45
- parser (3.2.0.0)
55
+ parallel (1.24.0)
56
+ parser (3.3.0.5)
46
57
  ast (~> 2.4.1)
47
- racc (1.7.1)
48
- rails-dom-testing (2.1.1)
58
+ racc
59
+ prism (0.24.0)
60
+ racc (1.7.3)
61
+ rails-dom-testing (2.2.0)
49
62
  activesupport (>= 5.0.0)
50
63
  minitest
51
64
  nokogiri (>= 1.6)
@@ -53,54 +66,59 @@ GEM
53
66
  loofah (~> 2.21)
54
67
  nokogiri (~> 1.14)
55
68
  rainbow (3.1.1)
56
- rake (13.0.6)
57
- regexp_parser (2.6.2)
58
- rexml (3.2.5)
59
- rspec (3.12.0)
60
- rspec-core (~> 3.12.0)
61
- rspec-expectations (~> 3.12.0)
62
- rspec-mocks (~> 3.12.0)
63
- rspec-core (3.12.1)
64
- rspec-support (~> 3.12.0)
65
- rspec-expectations (3.12.2)
69
+ rake (13.1.0)
70
+ regexp_parser (2.9.0)
71
+ rexml (3.2.6)
72
+ rspec (3.13.0)
73
+ rspec-core (~> 3.13.0)
74
+ rspec-expectations (~> 3.13.0)
75
+ rspec-mocks (~> 3.13.0)
76
+ rspec-core (3.13.0)
77
+ rspec-support (~> 3.13.0)
78
+ rspec-expectations (3.13.0)
66
79
  diff-lcs (>= 1.2.0, < 2.0)
67
- rspec-support (~> 3.12.0)
68
- rspec-mocks (3.12.3)
80
+ rspec-support (~> 3.13.0)
81
+ rspec-mocks (3.13.0)
69
82
  diff-lcs (>= 1.2.0, < 2.0)
70
- rspec-support (~> 3.12.0)
71
- rspec-support (3.12.0)
72
- rubocop (1.45.0)
83
+ rspec-support (~> 3.13.0)
84
+ rspec-support (3.13.1)
85
+ rubocop (1.62.0)
73
86
  json (~> 2.3)
87
+ language_server-protocol (>= 3.17.0)
74
88
  parallel (~> 1.10)
75
- parser (>= 3.2.0.0)
89
+ parser (>= 3.3.0.2)
76
90
  rainbow (>= 2.2.2, < 4.0)
77
91
  regexp_parser (>= 1.8, < 3.0)
78
92
  rexml (>= 3.2.5, < 4.0)
79
- rubocop-ast (>= 1.24.1, < 2.0)
93
+ rubocop-ast (>= 1.31.1, < 2.0)
80
94
  ruby-progressbar (~> 1.7)
81
95
  unicode-display_width (>= 2.4.0, < 3.0)
82
- rubocop-ast (1.24.1)
83
- parser (>= 3.1.1.0)
84
- rubocop-capybara (2.17.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)
85
101
  rubocop (~> 1.41)
86
102
  rubocop-rake (0.6.0)
87
103
  rubocop (~> 1.0)
88
- rubocop-rspec (2.18.1)
89
- rubocop (~> 1.33)
104
+ rubocop-rspec (2.27.1)
105
+ rubocop (~> 1.40)
90
106
  rubocop-capybara (~> 2.17)
91
- ruby-progressbar (1.11.0)
92
- sevencop (0.33.0)
107
+ rubocop-factory_bot (~> 2.22)
108
+ ruby-progressbar (1.13.0)
109
+ sevencop (0.38.0)
93
110
  activesupport
94
111
  rubocop
95
112
  smart_properties (1.17.0)
96
113
  tzinfo (2.0.6)
97
114
  concurrent-ruby (~> 1.0)
98
- unicode-display_width (2.4.2)
115
+ unicode-display_width (2.5.0)
99
116
 
100
117
  PLATFORMS
101
118
  x86_64-linux
102
119
 
103
120
  DEPENDENCIES
121
+ prism
104
122
  rake
105
123
  rspec
106
124
  rubocop-erb!
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec path: '..'
6
+
7
+ gem 'nokogiri', '~> 1.15.0'
8
+ gem 'rake'
9
+ gem 'rspec'
10
+ gem 'rubocop-rake'
11
+ gem 'rubocop-rspec'
12
+ gem 'sevencop'
@@ -0,0 +1,131 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ rubocop-erb (0.4.0)
5
+ better_html
6
+ rubocop (~> 1.45)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actionview (7.1.2)
12
+ activesupport (= 7.1.2)
13
+ builder (~> 3.1)
14
+ erubi (~> 1.11)
15
+ rails-dom-testing (~> 2.2)
16
+ rails-html-sanitizer (~> 1.6)
17
+ activesupport (7.1.2)
18
+ base64
19
+ bigdecimal
20
+ concurrent-ruby (~> 1.0, >= 1.0.2)
21
+ connection_pool (>= 2.2.5)
22
+ drb
23
+ i18n (>= 1.6, < 2)
24
+ minitest (>= 5.1)
25
+ mutex_m
26
+ tzinfo (~> 2.0)
27
+ ast (2.4.2)
28
+ base64 (0.2.0)
29
+ better_html (2.0.2)
30
+ actionview (>= 6.0)
31
+ activesupport (>= 6.0)
32
+ ast (~> 2.0)
33
+ erubi (~> 1.4)
34
+ parser (>= 2.4)
35
+ smart_properties
36
+ bigdecimal (3.1.5)
37
+ builder (3.2.4)
38
+ concurrent-ruby (1.2.2)
39
+ connection_pool (2.4.1)
40
+ crass (1.0.6)
41
+ diff-lcs (1.5.0)
42
+ drb (2.2.0)
43
+ ruby2_keywords
44
+ erubi (1.12.0)
45
+ i18n (1.14.1)
46
+ concurrent-ruby (~> 1.0)
47
+ json (2.7.1)
48
+ language_server-protocol (3.17.0.3)
49
+ loofah (2.22.0)
50
+ crass (~> 1.0.2)
51
+ nokogiri (>= 1.12.0)
52
+ minitest (5.20.0)
53
+ mutex_m (0.2.0)
54
+ nokogiri (1.15.5-x86_64-linux)
55
+ racc (~> 1.4)
56
+ parallel (1.24.0)
57
+ parser (3.3.0.2)
58
+ ast (~> 2.4.1)
59
+ racc
60
+ racc (1.7.3)
61
+ rails-dom-testing (2.2.0)
62
+ activesupport (>= 5.0.0)
63
+ minitest
64
+ nokogiri (>= 1.6)
65
+ rails-html-sanitizer (1.6.0)
66
+ loofah (~> 2.21)
67
+ nokogiri (~> 1.14)
68
+ rainbow (3.1.1)
69
+ rake (13.1.0)
70
+ regexp_parser (2.8.3)
71
+ rexml (3.2.6)
72
+ rspec (3.12.0)
73
+ rspec-core (~> 3.12.0)
74
+ rspec-expectations (~> 3.12.0)
75
+ rspec-mocks (~> 3.12.0)
76
+ rspec-core (3.12.2)
77
+ rspec-support (~> 3.12.0)
78
+ rspec-expectations (3.12.3)
79
+ diff-lcs (>= 1.2.0, < 2.0)
80
+ rspec-support (~> 3.12.0)
81
+ rspec-mocks (3.12.6)
82
+ diff-lcs (>= 1.2.0, < 2.0)
83
+ rspec-support (~> 3.12.0)
84
+ rspec-support (3.12.1)
85
+ rubocop (1.59.0)
86
+ json (~> 2.3)
87
+ language_server-protocol (>= 3.17.0)
88
+ parallel (~> 1.10)
89
+ parser (>= 3.2.2.4)
90
+ rainbow (>= 2.2.2, < 4.0)
91
+ regexp_parser (>= 1.8, < 3.0)
92
+ rexml (>= 3.2.5, < 4.0)
93
+ rubocop-ast (>= 1.30.0, < 2.0)
94
+ ruby-progressbar (~> 1.7)
95
+ unicode-display_width (>= 2.4.0, < 3.0)
96
+ rubocop-ast (1.30.0)
97
+ parser (>= 3.2.1.0)
98
+ rubocop-capybara (2.20.0)
99
+ rubocop (~> 1.41)
100
+ rubocop-factory_bot (2.25.1)
101
+ rubocop (~> 1.41)
102
+ rubocop-rake (0.6.0)
103
+ rubocop (~> 1.0)
104
+ rubocop-rspec (2.26.1)
105
+ rubocop (~> 1.40)
106
+ rubocop-capybara (~> 2.17)
107
+ rubocop-factory_bot (~> 2.22)
108
+ ruby-progressbar (1.13.0)
109
+ ruby2_keywords (0.0.5)
110
+ sevencop (0.35.1)
111
+ activesupport
112
+ rubocop
113
+ smart_properties (1.17.0)
114
+ tzinfo (2.0.6)
115
+ concurrent-ruby (~> 1.0)
116
+ unicode-display_width (2.5.0)
117
+
118
+ PLATFORMS
119
+ x86_64-linux
120
+
121
+ DEPENDENCIES
122
+ nokogiri (~> 1.15.0)
123
+ rake
124
+ rspec
125
+ rubocop-erb!
126
+ rubocop-rake
127
+ rubocop-rspec
128
+ sevencop
129
+
130
+ BUNDLED WITH
131
+ 2.3.19
@@ -21,6 +21,9 @@ module RuboCop
21
21
  def call
22
22
  [
23
23
  PrecedingKeywordRemover,
24
+ PrecedingBraceRemover,
25
+ TrailingBraceRemover,
26
+ TrailingThenRemover,
24
27
  TrailingDoRemover
25
28
  ].reduce(@ruby_clip) do |previous, callable|
26
29
  result = callable.call(previous.code)
@@ -31,29 +34,7 @@ module RuboCop
31
34
  end
32
35
  end
33
36
 
34
- # Remove preceding keyword.
35
- class PrecedingKeywordRemover
36
- REGEXP = /
37
- \A
38
- \s*
39
- (?:
40
- begin
41
- | case
42
- | else
43
- | elsif
44
- | end
45
- | ensure
46
- | if
47
- | rescue
48
- | unless
49
- | until
50
- | when
51
- | while
52
- | for[ \t]+\w+[ \t]+in
53
- )
54
- \b[ \t]*
55
- /x.freeze
56
-
37
+ class PrecedingSourceRemover
57
38
  class << self
58
39
  # @param [String] code
59
40
  # @return [RubyClip]
@@ -69,7 +50,7 @@ module RuboCop
69
50
 
70
51
  # @return [Hash]
71
52
  def call
72
- data = @code.match(REGEXP)
53
+ data = @code.match(self.class::REGEXP)
73
54
  if data
74
55
  offset = data[0].length
75
56
  RubyClip.new(
@@ -85,17 +66,40 @@ module RuboCop
85
66
  end
86
67
  end
87
68
 
88
- # Remove trailing `do`.
89
- class TrailingDoRemover
69
+ # Remove preceding keyword.
70
+ class PrecedingKeywordRemover < PrecedingSourceRemover
90
71
  REGEXP = /
91
- [ \t]
92
- do
93
- [ \t]*
94
- (\|[^|]*\|)?
95
- [ \t]*
96
- \Z
72
+ \A
73
+ \s*
74
+ (?:
75
+ begin
76
+ | case
77
+ | else
78
+ | elsif
79
+ | end
80
+ | ensure
81
+ | if
82
+ | rescue
83
+ | unless
84
+ | until
85
+ | when
86
+ | while
87
+ | for[ \t]+\w+[ \t]+in
88
+ )
89
+ \b[ \t]*
97
90
  /x.freeze
91
+ end
98
92
 
93
+ # Remove preceding `}`.
94
+ class PrecedingBraceRemover < PrecedingSourceRemover
95
+ REGEXP = /
96
+ \A
97
+ \s*
98
+ }
99
+ /x.freeze
100
+ end
101
+
102
+ class TrailingSourceRemover
99
103
  class << self
100
104
  # @param [String] code
101
105
  # @return [RubyClip]
@@ -112,11 +116,44 @@ module RuboCop
112
116
  # @return [Hash]
113
117
  def call
114
118
  RubyClip.new(
115
- code: @code.sub(REGEXP, ''),
119
+ code: @code.sub(self.class::REGEXP, ''),
116
120
  offset: 0
117
121
  )
118
122
  end
119
123
  end
124
+
125
+ # Remove trailing `{`.
126
+ class TrailingBraceRemover < TrailingSourceRemover
127
+ REGEXP = /
128
+ {
129
+ [ \t]*
130
+ (?:\|[^|]*\|)?
131
+ \s*
132
+ \z
133
+ /x.freeze
134
+ end
135
+
136
+ # Remove trailing `then`.
137
+ class TrailingThenRemover < TrailingSourceRemover
138
+ REGEXP = /
139
+ [ \t]*\b
140
+ then
141
+ \s*
142
+ \z
143
+ /x.freeze
144
+ end
145
+
146
+ # Remove trailing `do`.
147
+ class TrailingDoRemover < TrailingSourceRemover
148
+ REGEXP = /
149
+ [ \t]
150
+ do
151
+ [ \t]*
152
+ (?:\|[^|]*\|)?
153
+ \s*
154
+ \z
155
+ /x.freeze
156
+ end
120
157
  end
121
158
  end
122
159
  end
@@ -26,16 +26,9 @@ module RuboCop
26
26
  return unless supported_file_path_pattern?
27
27
 
28
28
  ruby_clips.map do |ruby_clip|
29
- processed_source = ::RuboCop::ProcessedSource.new(
30
- ruby_clip.code,
31
- @processed_source.ruby_version,
32
- file_path
33
- )
34
- processed_source.config = @processed_source.config
35
- processed_source.registry = @processed_source.registry
36
29
  {
37
30
  offset: ruby_clip.offset,
38
- processed_source: processed_source
31
+ processed_source: ruby_clip_to_processed_source(ruby_clip)
39
32
  }
40
33
  end
41
34
  end
@@ -73,6 +66,28 @@ module RuboCop
73
66
  ).ast
74
67
  end
75
68
 
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
+
76
91
  # @return [Array<RuboCop::Erb::RubyClip>]
77
92
  def ruby_clips
78
93
  nodes.map do |node|
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Erb
5
- VERSION = '0.3.0'
5
+ VERSION = '0.4.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.3.0
4
+ version: 0.4.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-07-20 00:00:00.000000000 Z
11
+ date: 2024-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: better_html
@@ -54,6 +54,8 @@ files:
54
54
  - README.md
55
55
  - Rakefile
56
56
  - config/default.yml
57
+ - gemfiles/ruby_2.7.gemfile
58
+ - gemfiles/ruby_2.7.gemfile.lock
57
59
  - lib/rubocop/erb.rb
58
60
  - lib/rubocop/erb/config_loader.rb
59
61
  - lib/rubocop/erb/keyword_remover.rb