synvert-core 1.21.6 → 1.22.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: be03ea2206a20768b84cfc41ae93146510c561b1ae271ae4f1d1e6edc1a5c0c8
4
- data.tar.gz: fa219393c0c4db9e4b2080d9e6a53245e525a29f12416e013c0afaaaa2c3629c
3
+ metadata.gz: 90f6acc3b15b0d25a8df1320393862f574dffbfc1743fd5bbb03f7323d994ae1
4
+ data.tar.gz: 7fa5d3c80ed1c86fc8c67abc2add07e374681c3bb54bc53e590195ffb51c3fb2
5
5
  SHA512:
6
- metadata.gz: e9700c9b08ea11158f741634883e1cec3a69c5b18b15dd80424e42d6541f605aa16ac494dfd4bc25b4d2aa88b61b976e76d1a2e8b9f09c4a4e7a870bb9d5b43a
7
- data.tar.gz: e382f8066407aa95c8079ced3e08bc453574e8329779c1d80c425441fbb72882cca60b217a482c4c691dd0ed02d1d7a3c88a712ff5b53c8f64a6dda922a8ec59
6
+ metadata.gz: 755e6b198dc2ce1c652ea6bced3f9ee002599e6ab51dee5ea1a9dd8d103b0aafa86fa495808db548a675e0a6bf0356533687f7cd652e73dd519bec9e50cb55dd
7
+ data.tar.gz: f2364e3359310b864a813d6132e9475ea4f19f95219e849bcbd33cdfe362f849c5a11ddc9220ca6b7689058ca795e70be75a63043fc9498224d336f2fd10a567
@@ -11,10 +11,10 @@ jobs:
11
11
  runs-on: ubuntu-latest
12
12
  strategy:
13
13
  matrix:
14
- ruby-version: ['2.6', '2.7', '3.0', '3.1']
14
+ ruby-version: ['2.7', '3.0', '3.1', '3.2']
15
15
 
16
16
  steps:
17
- - uses: actions/checkout@v2
17
+ - uses: actions/checkout@v3
18
18
  - name: Set up Ruby
19
19
  uses: ruby/setup-ruby@v1
20
20
  with:
@@ -28,10 +28,11 @@ jobs:
28
28
  needs: test
29
29
  name: Update gh-pages to docs
30
30
  steps:
31
- - uses: actions/checkout@v2
32
- - uses: actions/setup-ruby@v1
31
+ - uses: actions/checkout@v3
32
+ - uses: ruby/setup-ruby@v1
33
33
  with:
34
- ruby-version: '3.1'
34
+ ruby-version: '3.2'
35
+ bundler-cache: true
35
36
  - name: Install required gem dependencies
36
37
  run: gem install yard redcarpet github-markup --no-document
37
38
  - name: Build YARD Ruby Documentation
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.22.0 (2023-03-24)
4
+
5
+ * Add `and_comma` option to `insert`, `insert_before`, `insert_after` api
6
+
7
+ ## 1.21.7 (2023-03-23)
8
+
9
+ * Polish `erb` engine
10
+ * Update `node_mutation` to 1.12.1
11
+
3
12
  ## 1.21.6 (2023-02-16)
4
13
 
5
14
  * `RAILS_VIEW_FILES` do not check `haml` and `slim` files until we support them
data/Gemfile CHANGED
@@ -5,7 +5,6 @@ source 'https://rubygems.org'
5
5
  # Specify your gem's dependencies in synvert.gemspec
6
6
  gemspec
7
7
 
8
- require 'pp' # https://github.com/defunkt/fakefs/issues/99
9
8
  gem "fakefs", require: "fakefs/safe"
10
9
  gem "guard"
11
10
  gem "guard-rspec"
data/Gemfile.lock CHANGED
@@ -1,10 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- synvert-core (1.21.6)
4
+ synvert-core (1.22.0)
5
5
  activesupport (< 7.0.0)
6
- erubis
7
- node_mutation (>= 1.9.2)
6
+ node_mutation (>= 1.12.1)
8
7
  node_query (>= 1.12.0)
9
8
  parallel
10
9
  parser
@@ -13,7 +12,7 @@ PATH
13
12
  GEM
14
13
  remote: https://rubygems.org/
15
14
  specs:
16
- activesupport (6.1.7.2)
15
+ activesupport (6.1.7.3)
17
16
  concurrent-ruby (~> 1.0, >= 1.0.2)
18
17
  i18n (>= 1.6, < 2)
19
18
  minitest (>= 5.1)
@@ -21,10 +20,10 @@ GEM
21
20
  zeitwerk (~> 2.3)
22
21
  ast (2.4.2)
23
22
  coderay (1.1.3)
24
- concurrent-ruby (1.2.0)
23
+ concurrent-ruby (1.2.2)
25
24
  diff-lcs (1.5.0)
26
25
  erubis (2.7.0)
27
- fakefs (1.8.0)
26
+ fakefs (2.4.0)
28
27
  ffi (1.15.5)
29
28
  formatador (1.1.0)
30
29
  guard (2.18.0)
@@ -48,16 +47,16 @@ GEM
48
47
  rb-inotify (~> 0.9, >= 0.9.10)
49
48
  lumberjack (1.2.8)
50
49
  method_source (1.0.0)
51
- minitest (5.17.0)
50
+ minitest (5.18.0)
52
51
  nenv (0.3.0)
53
- node_mutation (1.9.3)
52
+ node_mutation (1.12.1)
54
53
  erubis
55
54
  node_query (1.12.0)
56
55
  notiffany (0.1.3)
57
56
  nenv (~> 0.1)
58
57
  shellany (~> 0.0)
59
58
  parallel (1.22.1)
60
- parser (3.2.1.0)
59
+ parser (3.2.1.1)
61
60
  ast (~> 2.4.1)
62
61
  parser_node_ext (1.0.0)
63
62
  parser
@@ -1,19 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'erubis'
4
-
5
3
  module Synvert::Core
6
4
  module Engine
7
5
  class Erb
8
6
  class << self
9
- # convert erb to ruby code.
7
+ # Encode erb string, leave only ruby code, replace other erb code with whitespace.
10
8
  #
11
- # @param source [String] erb source code.
12
- # @return [String] ruby source code.
9
+ # @param source [String] erb code.
10
+ # @return [String] encoded ruby code.
13
11
  def encode(source)
14
- source.gsub(/^.*?<%=?/m) { |str| ' ' * str.size }
15
- .gsub(/%>.*?$/m) { |str| ' ' * str.size }
16
- .gsub(/%>.*?<%=?/m) { |str| ' ' * str.size }
12
+ source.gsub(/%>.*?<%=?/m) { |str| ' ' * str.size }
13
+ .sub(/^.*?<%=?/m) { |str| ' ' * str.size }
14
+ .sub(/%>.*?$/m) { |str| ' ' * str.size }
17
15
  end
18
16
  end
19
17
  end
@@ -20,7 +20,7 @@ module Synvert::Core
20
20
  @block = block
21
21
  strategy = NodeMutation::Strategy::KEEP_RUNNING
22
22
  if rewriter.options[:strategy] == Strategy::ALLOW_INSERT_AT_SAME_POSITION
23
- strategy |= NodeMutation::Strategy::ALLOW_INSERT_AT_SAME_POSITION
23
+ strategy |= NodeMutation::Strategy::ALLOW_INSERT_AT_SAME_POSITION
24
24
  end
25
25
  NodeMutation.configure({ strategy: strategy, tab_width: Configuration.tab_width })
26
26
  rewriter.helpers.each { |helper| singleton_class.send(:define_method, helper[:name], &helper[:block]) }
@@ -90,7 +90,6 @@ module Synvert::Core
90
90
  end
91
91
  end
92
92
 
93
-
94
93
  # Gets current node, it allows to get current node in block code.
95
94
  #
96
95
  # @return [Parser::AST::Node]
@@ -251,8 +250,9 @@ module Synvert::Core
251
250
  # @param code [String] code need to be inserted.
252
251
  # @param at [String] insert position, beginning or end
253
252
  # @param to [String] where to insert, if it is nil, will insert to current node.
254
- def insert(code, at: 'end', to: nil)
255
- @current_mutation.insert(@current_node, code, at: at, to: to)
253
+ # @param and_comma [Boolean] insert extra comma.
254
+ def insert(code, at: 'end', to: nil, and_comma: false)
255
+ @current_mutation.insert(@current_node, code, at: at, to: to, and_comma: and_comma)
256
256
  end
257
257
 
258
258
  # It inserts the code next to the current node.
@@ -265,9 +265,11 @@ module Synvert::Core
265
265
  # insert_after "{{receiver}}.secret_key_base = \"#{SecureRandom.hex(64)}\""
266
266
  # end
267
267
  # @param code [String] code need to be inserted.
268
- def insert_after(code, to: nil)
268
+ # @param to [String] where to insert, if it is nil, will insert to current node.
269
+ # @param and_comma [Boolean] insert extra comma.
270
+ def insert_after(code, to: nil, and_comma: false)
269
271
  column = ' ' * NodeMutation.adapter.get_start_loc(@current_node).column
270
- @current_mutation.insert(@current_node, "\n#{column}#{code}", at: 'end', to: to)
272
+ @current_mutation.insert(@current_node, "\n#{column}#{code}", at: 'end', to: to, and_comma: and_comma)
271
273
  end
272
274
 
273
275
  # It inserts the code previous to the current node.
@@ -280,9 +282,11 @@ module Synvert::Core
280
282
  # insert_before "{{receiver}}.secret_key_base = \"#{SecureRandom.hex(64)}\""
281
283
  # end
282
284
  # @param code [String] code need to be inserted.
283
- def insert_before(code, to: nil)
285
+ # @param to [String] where to insert, if it is nil, will insert to current node.
286
+ # @param and_comma [Boolean] insert extra comma.
287
+ def insert_before(code, to: nil, and_comma: false)
284
288
  column = ' ' * NodeMutation.adapter.get_start_loc(@current_node).column
285
- @current_mutation.insert(@current_node, "#{code}\n#{column}", at: 'beginning', to: to)
289
+ @current_mutation.insert(@current_node, "#{code}\n#{column}", at: 'beginning', to: to, and_comma: and_comma)
286
290
  end
287
291
 
288
292
  # It replaces erb stmt code to expr code.
@@ -333,10 +337,9 @@ module Synvert::Core
333
337
  # with_node type: 'send', message: { in: %w[puts p] } do
334
338
  # remove
335
339
  # end
336
- # @param options [Hash] options.
337
340
  # @option and_comma [Boolean] delete extra comma.
338
- def remove(**options)
339
- @current_mutation.remove(@current_node, **options)
341
+ def remove(and_comma: false)
342
+ @current_mutation.remove(@current_node, and_comma: and_comma)
340
343
  end
341
344
 
342
345
  # It deletes child nodes.
@@ -348,10 +351,9 @@ module Synvert::Core
348
351
  # delete :receiver, :dot
349
352
  # end
350
353
  # @param selectors [Array<Symbol>] selector names of child node.
351
- # @param options [Hash]
352
354
  # @option and_comma [Boolean] delete extra comma.
353
- def delete(*selectors, **options)
354
- @current_mutation.delete(@current_node, *selectors, **options)
355
+ def delete(*selectors, and_comma: false)
356
+ @current_mutation.delete(@current_node, *selectors, and_comma: and_comma)
355
357
  end
356
358
 
357
359
  # It wraps current node with code.
@@ -404,7 +406,8 @@ module Synvert::Core
404
406
  if str.include?(quote) && !str.include?(another_quote)
405
407
  return "#{another_quote}#{str}#{another_quote}"
406
408
  end
407
- escaped_str = str.gsub(quote) { |char| '\\' + quote }
409
+
410
+ escaped_str = str.gsub(quote) { |_char| '\\' + quote }
408
411
  quote + escaped_str + quote
409
412
  end
410
413
 
@@ -413,7 +416,7 @@ module Synvert::Core
413
416
  # @param tab_size [Integer] tab size
414
417
  # @return [String]
415
418
  def add_leading_spaces(str, tab_size: 1)
416
- " " * Configuration.tab_width * tab_size + str;
419
+ (" " * Configuration.tab_width * tab_size) + str;
417
420
  end
418
421
 
419
422
  private
@@ -94,7 +94,15 @@ module Synvert::Core
94
94
  # @return [Array<Object>] the test results
95
95
  # @!attribute [rw] options
96
96
  # @return [Hash] the rewriter options
97
- attr_reader :group, :name, :sub_snippets, :helpers, :warnings, :affected_files, :ruby_version, :gem_spec, :test_results
97
+ attr_reader :group,
98
+ :name,
99
+ :sub_snippets,
100
+ :helpers,
101
+ :warnings,
102
+ :affected_files,
103
+ :ruby_version,
104
+ :gem_spec,
105
+ :test_results
98
106
  attr_accessor :options
99
107
 
100
108
  # Initialize a Rewriter.
@@ -230,10 +238,11 @@ module Synvert::Core
230
238
  instance.process
231
239
  end
232
240
  else
233
- results = handle_one_file(Array(file_patterns)) do |file_path|
234
- instance = Rewriter::Instance.new(self, file_path, &block)
235
- instance.test
236
- end
241
+ results =
242
+ handle_one_file(Array(file_patterns)) do |file_path|
243
+ instance = Rewriter::Instance.new(self, file_path, &block)
244
+ instance.test
245
+ end
237
246
  merge_test_results(results)
238
247
  end
239
248
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class SnippetNotFoundError < StandardError
4
- end
4
+ end
@@ -4,4 +4,4 @@ module Synvert::Core
4
4
  class Strategy
5
5
  ALLOW_INSERT_AT_SAME_POSITION = "allow_insert_at_same_position"
6
6
  end
7
- end
7
+ end
@@ -15,14 +15,17 @@ module Synvert::Core
15
15
  if is_valid_url?(snippet_name)
16
16
  uri = URI.parse(format_url(snippet_name))
17
17
  return uri.open.read if remote_snippet_exists?(uri)
18
+
18
19
  raise SnippetNotFoundError.new("#{snippet_name} nout found")
19
20
  elsif is_valid_file?(snippet_name)
20
21
  return File.read(snippet_name)
21
22
  else
22
23
  snippet_path = snippet_expand_path(snippet_name)
23
24
  return File.read(snippet_path) if File.exist?(snippet_path)
25
+
24
26
  snippet_uri = URI.parse(format_url(remote_snippet_url(snippet_name)))
25
27
  return snippet_uri.open.read if remote_snippet_exists?(snippet_uri)
28
+
26
29
  raise SnippetNotFoundError.new("#{snippet_name} nout found")
27
30
  end
28
31
  end
@@ -32,9 +35,10 @@ module Synvert::Core
32
35
  # @return [Array<String>] file paths
33
36
  def glob(file_patterns)
34
37
  Dir.chdir(Configuration.root_path) do
35
- all_files = file_patterns.flat_map do |file_pattern|
36
- Dir.glob(file_pattern)
37
- end
38
+ all_files =
39
+ file_patterns.flat_map do |file_pattern|
40
+ Dir.glob(file_pattern)
41
+ end
38
42
  filter_only_paths(all_files) - get_skip_files
39
43
  end
40
44
  end
@@ -105,4 +109,4 @@ module Synvert::Core
105
109
  end
106
110
  end
107
111
  end
108
- end
112
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Synvert
4
4
  module Core
5
- VERSION = '1.21.6'
5
+ VERSION = '1.22.0'
6
6
  end
7
7
  end
data/lib/synvert/core.rb CHANGED
@@ -9,7 +9,6 @@ require_relative './core/node_ext'
9
9
  require 'active_support'
10
10
  require 'active_support/core_ext'
11
11
  require 'erubis'
12
- require 'set'
13
12
  require 'node_query'
14
13
  require 'node_mutation'
15
14
 
@@ -34,11 +34,14 @@ module Synvert::Core
34
34
  <% end %>
35
35
  <% end %>
36
36
  EOF
37
- encoded_lines = Engine::Erb.encode(source).split("\n")
38
- expect(encoded_lines[0]).to eq ' content_for :head do '
39
- expect(encoded_lines[1]).to eq " asset_path('bg.png') "
40
- expect(encoded_lines[-2]).to eq ' end '
41
- expect(encoded_lines[-1]).to eq ' end '
37
+ encoded_source = Engine::Erb.encode(source)
38
+ expect(encoded_source).to be_include 'content_for :head do'
39
+ expect(encoded_source).to be_include " asset_path('bg.png')"
40
+ expect(encoded_source).to be_include 'post = Post.find(:first)'
41
+ expect(encoded_source).to be_include "link_to_function 'test', \"confirm('test');\""
42
+ expect(encoded_source).to be_include 'end'
43
+ expect(encoded_source).not_to be_include 'style'
44
+ expect(encoded_source).not_to be_include 'div'
42
45
  end
43
46
  end
44
47
  end
@@ -12,7 +12,12 @@ module Synvert::Core
12
12
  it 'parses find_node' do
13
13
  scope = double
14
14
  block = proc {}
15
- expect(Rewriter::WithinScope).to receive(:new).with(instance, '.send[message=create]', {}, &block).and_return(scope)
15
+ expect(Rewriter::WithinScope).to receive(:new).with(
16
+ instance,
17
+ '.send[message=create]',
18
+ {},
19
+ &block
20
+ ).and_return(scope)
16
21
  expect(scope).to receive(:process)
17
22
  instance.find_node('.send[message=create]', &block)
18
23
  end
@@ -99,28 +104,46 @@ module Synvert::Core
99
104
  it 'parses append' do
100
105
  instance.instance_variable_set(:@current_mutation, double)
101
106
  instance.current_node = double
102
- expect(instance.instance_variable_get(:@current_mutation)).to receive(:append).with(instance.current_node, 'Foobar')
107
+ expect(instance.instance_variable_get(:@current_mutation)).to receive(:append).with(
108
+ instance.current_node,
109
+ 'Foobar'
110
+ )
103
111
  instance.append 'Foobar'
104
112
  end
105
113
 
106
114
  it 'parses prepend' do
107
115
  instance.instance_variable_set(:@current_mutation, double)
108
116
  instance.current_node = double
109
- expect(instance.instance_variable_get(:@current_mutation)).to receive(:prepend).with(instance.current_node, 'Foobar')
117
+ expect(instance.instance_variable_get(:@current_mutation)).to receive(:prepend).with(
118
+ instance.current_node,
119
+ 'Foobar'
120
+ )
110
121
  instance.prepend 'Foobar'
111
122
  end
112
123
 
113
124
  it 'parses insert at end' do
114
125
  instance.instance_variable_set(:@current_mutation, double)
115
126
  instance.current_node = double
116
- expect(instance.instance_variable_get(:@current_mutation)).to receive(:insert).with(instance.current_node, 'Foobar', at: 'end', to: 'receiver')
127
+ expect(instance.instance_variable_get(:@current_mutation)).to receive(:insert).with(
128
+ instance.current_node,
129
+ 'Foobar',
130
+ at: 'end',
131
+ to: 'receiver',
132
+ and_comma: false
133
+ )
117
134
  instance.insert 'Foobar', to: 'receiver'
118
135
  end
119
136
 
120
137
  it 'parses insert at beginning' do
121
138
  instance.instance_variable_set(:@current_mutation, double)
122
139
  instance.current_node = double
123
- expect(instance.instance_variable_get(:@current_mutation)).to receive(:insert).with(instance.current_node, 'Foobar', at: 'beginning', to: nil)
140
+ expect(instance.instance_variable_get(:@current_mutation)).to receive(:insert).with(
141
+ instance.current_node,
142
+ 'Foobar',
143
+ at: 'beginning',
144
+ to: nil,
145
+ and_comma: false
146
+ )
124
147
  instance.insert 'Foobar', at: 'beginning'
125
148
  end
126
149
 
@@ -128,7 +151,13 @@ module Synvert::Core
128
151
  instance.instance_variable_set(:@current_mutation, double)
129
152
  instance.current_node = double
130
153
  expect(NodeMutation).to receive_message_chain(:adapter, :get_start_loc, :column).and_return(2)
131
- expect(instance.instance_variable_get(:@current_mutation)).to receive(:insert).with(instance.current_node, "\n Foobar", at: 'end', to: nil)
154
+ expect(instance.instance_variable_get(:@current_mutation)).to receive(:insert).with(
155
+ instance.current_node,
156
+ "\n Foobar",
157
+ at: 'end',
158
+ to: nil,
159
+ and_comma: false
160
+ )
132
161
  instance.insert_after 'Foobar'
133
162
  end
134
163
 
@@ -136,7 +165,13 @@ module Synvert::Core
136
165
  instance.instance_variable_set(:@current_mutation, double)
137
166
  instance.current_node = double
138
167
  expect(NodeMutation).to receive_message_chain(:adapter, :get_start_loc, :column).and_return(2)
139
- expect(instance.instance_variable_get(:@current_mutation)).to receive(:insert).with(instance.current_node, "Foobar\n ", at: 'beginning', to: nil)
168
+ expect(instance.instance_variable_get(:@current_mutation)).to receive(:insert).with(
169
+ instance.current_node,
170
+ "Foobar\n ",
171
+ at: 'beginning',
172
+ to: nil,
173
+ and_comma: false
174
+ )
140
175
  instance.insert_before 'Foobar'
141
176
  end
142
177
 
@@ -153,35 +188,53 @@ module Synvert::Core
153
188
  it 'parses replace_with' do
154
189
  instance.instance_variable_set(:@current_mutation, double)
155
190
  instance.current_node = double
156
- expect(instance.instance_variable_get(:@current_mutation)).to receive(:replace_with).with(instance.current_node, 'Foobar')
191
+ expect(instance.instance_variable_get(:@current_mutation)).to receive(:replace_with).with(
192
+ instance.current_node,
193
+ 'Foobar'
194
+ )
157
195
  instance.replace_with 'Foobar'
158
196
  end
159
197
 
160
198
  it 'parses replace with' do
161
199
  instance.instance_variable_set(:@current_mutation, double)
162
200
  instance.current_node = double
163
- expect(instance.instance_variable_get(:@current_mutation)).to receive(:replace).with(instance.current_node, :message, with: 'Foobar')
201
+ expect(instance.instance_variable_get(:@current_mutation)).to receive(:replace).with(
202
+ instance.current_node,
203
+ :message,
204
+ with: 'Foobar'
205
+ )
164
206
  instance.replace :message, with: 'Foobar'
165
207
  end
166
208
 
167
209
  it 'parses remove' do
168
210
  instance.instance_variable_set(:@current_mutation, double)
169
211
  instance.current_node = double
170
- expect(instance.instance_variable_get(:@current_mutation)).to receive(:remove).with(instance.current_node, and_comma: true)
212
+ expect(instance.instance_variable_get(:@current_mutation)).to receive(:remove).with(
213
+ instance.current_node,
214
+ and_comma: true
215
+ )
171
216
  instance.remove and_comma: true
172
217
  end
173
218
 
174
219
  it 'parses delete' do
175
220
  instance.instance_variable_set(:@current_mutation, double)
176
221
  instance.current_node = double
177
- expect(instance.instance_variable_get(:@current_mutation)).to receive(:delete).with(instance.current_node, :dot, :message, and_comma: true)
222
+ expect(instance.instance_variable_get(:@current_mutation)).to receive(:delete).with(
223
+ instance.current_node,
224
+ :dot,
225
+ :message,
226
+ and_comma: true
227
+ )
178
228
  instance.delete :dot, :message, and_comma: true
179
229
  end
180
230
 
181
231
  it 'parses wrap with' do
182
232
  instance.instance_variable_set(:@current_mutation, double)
183
233
  instance.current_node = double
184
- expect(instance.instance_variable_get(:@current_mutation)).to receive(:wrap).with(instance.current_node, with: 'module Foobar')
234
+ expect(instance.instance_variable_get(:@current_mutation)).to receive(:wrap).with(
235
+ instance.current_node,
236
+ with: 'module Foobar'
237
+ )
185
238
  instance.wrap with: 'module Foobar'
186
239
  end
187
240
 
@@ -330,8 +383,8 @@ module Synvert::Core
330
383
  results = instance.test
331
384
  expect(results.file_path).to eq 'spec/models/post_spec.rb'
332
385
  expect(results.actions).to eq [
333
- OpenStruct.new(start: 35, end: 59, new_code: 'create :user'),
334
- OpenStruct.new(start: 69, end: 105, new_code: 'create :post, user: user')
386
+ NodeMutation::Struct::Action.new(35, 59, 'create :user'),
387
+ NodeMutation::Struct::Action.new(69, 105, 'create :post, user: user')
335
388
  ]
336
389
  end
337
390
 
@@ -369,7 +422,7 @@ module Synvert::Core
369
422
  expect(File).to receive(:read).with('./app/views/posts/_form.html.erb', encoding: 'UTF-8').and_return(input)
370
423
  result = instance.test
371
424
  expect(result.file_path).to eq 'app/views/posts/_form.html.erb'
372
- expect(result.actions).to eq [OpenStruct.new(start: 2, end: 2, new_code: '=')]
425
+ expect(result.actions).to eq [NodeMutation::Struct::Action.new(2, 2, '=')]
373
426
  end
374
427
  end
375
428
 
@@ -33,13 +33,14 @@ module Synvert::Core
33
33
 
34
34
  describe '#process' do
35
35
  it 'rewrites the file' do
36
- rewriter = Rewriter.new('group', 'name') do
37
- within_files '**/*.rb' do
38
- with_node node_type: 'class', name: 'Foobar' do
39
- replace :name, with: 'Synvert'
36
+ rewriter =
37
+ Rewriter.new('group', 'name') do
38
+ within_files '**/*.rb' do
39
+ with_node node_type: 'class', name: 'Foobar' do
40
+ replace :name, with: 'Synvert'
41
+ end
40
42
  end
41
43
  end
42
- end
43
44
  input = "class Foobar\nend"
44
45
  output = "class Synvert\nend"
45
46
  FakeFS do
@@ -52,13 +53,14 @@ module Synvert::Core
52
53
 
53
54
  describe '#test' do
54
55
  it 'gets test results' do
55
- rewriter = Rewriter.new('group', 'name') do
56
- within_files '**/*.rb' do
57
- with_node node_type: 'class', name: 'Foobar' do
58
- replace :name, with: 'Synvert'
56
+ rewriter =
57
+ Rewriter.new('group', 'name') do
58
+ within_files '**/*.rb' do
59
+ with_node node_type: 'class', name: 'Foobar' do
60
+ replace :name, with: 'Synvert'
61
+ end
59
62
  end
60
63
  end
61
- end
62
64
  input = "class Foobar\nend"
63
65
  FakeFS do
64
66
  File.write("code.rb", input)
@@ -66,7 +68,7 @@ module Synvert::Core
66
68
  expect(results[0].file_path).to eq '/code.rb'
67
69
  expect(results[0].affected?).to be_truthy
68
70
  expect(results[0].conflicted?).to be_falsey
69
- expect(results[0].actions).to eq [OpenStruct.new(start: 6, end: 12, new_code: 'Synvert')]
71
+ expect(results[0].actions).to eq [NodeMutation::Struct::Action.new(6, 12, 'Synvert')]
70
72
  end
71
73
  end
72
74
  end
@@ -226,9 +228,10 @@ module Synvert::Core
226
228
  it 'adds snippet by http url' do
227
229
  expect(Utils).to receive(:remote_snippet_exists?).with(URI.parse('http://synvert.net/foo/bar.rb')).and_return(true)
228
230
  expect_any_instance_of(URI::HTTP).to receive(:open).and_return(StringIO.new("Rewriter.new 'group', 'sub_rewriter' do\nend"))
229
- rewriter = Rewriter.new 'group', 'rewriter' do
230
- add_snippet 'http://synvert.net/foo/bar.rb'
231
- end
231
+ rewriter =
232
+ Rewriter.new 'group', 'rewriter' do
233
+ add_snippet 'http://synvert.net/foo/bar.rb'
234
+ end
232
235
  rewriter.process
233
236
  expect(Rewriter.fetch('group', 'sub_rewriter')).not_to be_nil
234
237
  end
@@ -236,9 +239,10 @@ module Synvert::Core
236
239
  it 'adds snippet by file path' do
237
240
  expect(File).to receive(:exist?).and_return(true)
238
241
  expect(File).to receive(:read).and_return("Rewriter.new 'group', 'sub_rewriter' do\nend")
239
- rewriter = Rewriter.new 'group', 'rewriter' do
240
- add_snippet '/home/richard/foo/bar.rb'
241
- end
242
+ rewriter =
243
+ Rewriter.new 'group', 'rewriter' do
244
+ add_snippet '/home/richard/foo/bar.rb'
245
+ end
242
246
  rewriter.process
243
247
  expect(Rewriter.fetch('group', 'sub_rewriter')).not_to be_nil
244
248
  end
@@ -61,22 +61,37 @@ module Synvert::Core
61
61
  end
62
62
 
63
63
  it 'gets all files' do
64
- expect(Dir).to receive(:glob).with('**/*.rb').and_return(['app/models/post.rb', 'app/controllers/posts_controller.rb'])
64
+ expect(Dir).to receive(:glob).with('**/*.rb').and_return(
65
+ [
66
+ 'app/models/post.rb',
67
+ 'app/controllers/posts_controller.rb'
68
+ ]
69
+ )
65
70
  expect(described_class.glob(['**/*.rb'])).to eq(['app/models/post.rb', 'app/controllers/posts_controller.rb'])
66
71
  end
67
72
 
68
73
  it 'filters only paths' do
69
74
  Configuration.only_paths = ['app/models']
70
- expect(Dir).to receive(:glob).with('**/*.rb').and_return(['app/models/post.rb', 'app/controllers/posts_controller.rb'])
75
+ expect(Dir).to receive(:glob).with('**/*.rb').and_return(
76
+ [
77
+ 'app/models/post.rb',
78
+ 'app/controllers/posts_controller.rb'
79
+ ]
80
+ )
71
81
  expect(described_class.glob(['**/*.rb'])).to eq(['app/models/post.rb'])
72
82
  end
73
83
 
74
84
  it 'skip files' do
75
85
  Configuration.skip_paths = ['app/controllers/**/*']
76
- expect(Dir).to receive(:glob).with('**/*.rb').and_return(['app/models/post.rb', 'app/controllers/posts_controller.rb'])
86
+ expect(Dir).to receive(:glob).with('**/*.rb').and_return(
87
+ [
88
+ 'app/models/post.rb',
89
+ 'app/controllers/posts_controller.rb'
90
+ ]
91
+ )
77
92
  expect(Dir).to receive(:glob).with('app/controllers/**/*').and_return(['app/controllers/posts_controller.rb'])
78
93
  expect(described_class.glob(['**/*.rb'])).to eq(['app/models/post.rb'])
79
94
  end
80
95
  end
81
96
  end
82
- end
97
+ end
@@ -20,9 +20,8 @@ Gem::Specification.new do |spec|
20
20
  spec.require_paths = ["lib"]
21
21
 
22
22
  spec.add_runtime_dependency "activesupport", "< 7.0.0"
23
- spec.add_runtime_dependency "erubis"
24
23
  spec.add_runtime_dependency "node_query", ">= 1.12.0"
25
- spec.add_runtime_dependency "node_mutation", ">= 1.9.2"
24
+ spec.add_runtime_dependency "node_mutation", ">= 1.12.1"
26
25
  spec.add_runtime_dependency "parser"
27
26
  spec.add_runtime_dependency "parser_node_ext", ">= 1.0.0"
28
27
  spec.add_runtime_dependency "parallel"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synvert-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.21.6
4
+ version: 1.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-16 00:00:00.000000000 Z
11
+ date: 2023-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - "<"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 7.0.0
27
- - !ruby/object:Gem::Dependency
28
- name: erubis
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: node_query
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +44,14 @@ dependencies:
58
44
  requirements:
59
45
  - - ">="
60
46
  - !ruby/object:Gem::Version
61
- version: 1.9.2
47
+ version: 1.12.1
62
48
  type: :runtime
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
52
  - - ">="
67
53
  - !ruby/object:Gem::Version
68
- version: 1.9.2
54
+ version: 1.12.1
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: parser
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -188,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
174
  - !ruby/object:Gem::Version
189
175
  version: '0'
190
176
  requirements: []
191
- rubygems_version: 3.4.1
177
+ rubygems_version: 3.4.6
192
178
  signing_key:
193
179
  specification_version: 4
194
180
  summary: convert ruby code to better syntax.