synvert-core 0.58.2 → 0.61.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: b5580dae81209573a74a22792f5f50f329805eb67d74c67d28beb9438115a6ba
4
- data.tar.gz: 3e97957ff1b4af95a5506ff240c0e500ccf69242d4c03a5db16c84ae03917520
3
+ metadata.gz: ff83abb1009ca5d9fe97a1c2e64701c31942a1c235e2b5a9bfe6cec1875f0956
4
+ data.tar.gz: b983862aa7a7861801104d43dc19cd794a5b83e4c2be5b137888b2e92a6f8068
5
5
  SHA512:
6
- metadata.gz: 6829aded4d70daf81fa7cab074c7029ee945997434d357cc251cd993ba89ec56bb1b74b4d98964a150cad0d8f3fbb0f9781f31c5eab760b3c5ba392dffac17f1
7
- data.tar.gz: 57d35f30118d60e234595d66b65580f29b205e7f09115ce3b44c1085d6845ff02c831855e2cd7267983b9e7a87a1480080f28a4cb533a0520b944e445bccd15b
6
+ metadata.gz: 6978c684ad91c8a59c9774129c5ab21162b66f4f3b4eb043337a008c2dd5a5df3634b7781442d03147ae8829b250bd73f279b31379f6b3861e852da75209ba26
7
+ data.tar.gz: 96299eb5b9b6254a3781abaff6e3d9f2ac6e1da8e1216b17990471558408bf6ceecb439175183819f3aadd860de94754639c4434705910469318e91abd57f124
data/CHANGELOG.md CHANGED
@@ -1,8 +1,21 @@
1
1
  # CHANGELOG
2
2
 
3
- ## 0.58.2 (2021-10-23)
3
+ ## 0.61.0 (2021-12-10)
4
4
 
5
- * Do not break the whole `recursive_children`
5
+ * Add `Node#child_node_by_name`
6
+ * Fix `Node#child_node_range` for array
7
+
8
+ ## 0.60.0 (2021-12-02)
9
+
10
+ * Add `to_string` to `sym` node
11
+
12
+ ## 0.59.0 (2021-11-17)
13
+
14
+ * Use option `stop_when_match` instead of `recursive`
15
+ * Add file pattern constants
16
+ * Instance supports array of file patterns
17
+ * Return block value by `next`
18
+ * Add `Node#filename` method
6
19
 
7
20
  ## 0.58.0 (2021-10-23)
8
21
 
@@ -315,6 +315,13 @@ module Parser::AST
315
315
  ].join("\n")
316
316
  end
317
317
 
318
+ # Get the file name of the current node.
319
+ #
320
+ # @return [String] file name.
321
+ def filename
322
+ loc.expression&.source_buffer.name
323
+ end
324
+
318
325
  # Get the source code of current node.
319
326
  #
320
327
  # @return [String] source code.
@@ -336,6 +343,43 @@ module Parser::AST
336
343
  loc.expression.line
337
344
  end
338
345
 
346
+ # Get child node by child name.
347
+ #
348
+ # @param [String] name of child node.
349
+ # @return [Parser::AST::Node] the child node.
350
+ def child_node_by_name(child_name)
351
+ direct_child_name, nested_child_name = child_name.to_s.split('.', 2)
352
+ if respond_to?(direct_child_name)
353
+ child_node = send(direct_child_name)
354
+
355
+ if nested_child_name
356
+ if child_node.is_a?(Array)
357
+ child_direct_child_name, child_nested_child_name = nested_child_name.split('.', 2)
358
+ child_direct_child_node = child_direct_child_name =~ /\A\d+\z/ ? child_node[child_direct_child_name.to_i - 1] : child_node.send(child_direct_child_name)
359
+ return child_direct_child_node.child_node_by_name(child_nested_child_name) if child_nested_child_name
360
+ return child_direct_child_node if child_direct_child_node
361
+
362
+ raise Synvert::Core::MethodNotSupported,
363
+ "child_node_by_name is not handled for #{debug_info}, child_name: #{child_name}"
364
+ end
365
+
366
+ return child_node.child_node_by_name(nested_child_name)
367
+ end
368
+
369
+ return nil if child_node.nil?
370
+
371
+ return child_node if child_node.is_a?(Parser::AST::Node)
372
+
373
+ # arguments
374
+ return nil if child_node.empty?
375
+
376
+ return child_node
377
+ end
378
+
379
+ raise Synvert::Core::MethodNotSupported,
380
+ "child_node_by_name is not handled for #{debug_info}, child_name: #{child_name}"
381
+ end
382
+
339
383
  # Get the source range of child node.
340
384
  #
341
385
  # @param [String] name of child node.
@@ -375,10 +419,10 @@ module Parser::AST
375
419
 
376
420
  if nested_child_name
377
421
  if child_node.is_a?(Array)
378
- child_direct_child_name, *child_nested_child_name = nested_child_name
379
- child_direct_child_node = child_direct_child_name =~ /\A\d+\z/ ? child_node[child_direct_child_name] : child_node.send(child_direct_child_name)
380
- if child_nested_child_name.length > 0
381
- return child_direct_child_node.child_node_range(child_nested_child_name.join('.'))
422
+ child_direct_child_name, child_nested_child_name = nested_child_name.split('.', 2)
423
+ child_direct_child_node = child_direct_child_name =~ /\A\d+\z/ ? child_node[child_direct_child_name.to_i - 1] : child_node.send(child_direct_child_name)
424
+ if child_nested_child_name
425
+ return child_direct_child_node.child_node_range(child_nested_child_name)
382
426
  elsif child_direct_child_node
383
427
  return (
384
428
  Parser::Source::Range.new(
@@ -479,8 +523,8 @@ module Parser::AST
479
523
  def rewritten_source(code)
480
524
  code.gsub(/{{(.*?)}}/m) do
481
525
  old_code = Regexp.last_match(1)
482
- if respond_to? old_code.split(/\.|\[/).first
483
- evaluated = instance_eval old_code
526
+ if respond_to?(old_code.split('.').first)
527
+ evaluated = child_node_by_name(old_code)
484
528
  case evaluated
485
529
  when Parser::AST::Node
486
530
  if evaluated.type == :args
@@ -545,6 +589,13 @@ module Parser::AST
545
589
  ":#{to_value}"
546
590
  end
547
591
 
592
+ # convert symbol to string
593
+ def to_string
594
+ return to_source unless type == :sym
595
+
596
+ "#{to_value}"
597
+ end
598
+
548
599
  # convert lambda {} to -> {}
549
600
  def to_lambda_literal
550
601
  if type == :block && caller.type == :send && caller.receiver.nil? && caller.message == :lambda
@@ -72,13 +72,13 @@ module Synvert::Core
72
72
  # Initialize an instance.
73
73
  #
74
74
  # @param rewriter [Synvert::Core::Rewriter]
75
- # @param file_pattern [String] pattern to find files, e.g. spec/**/*_spec.rb
75
+ # @param file_patterns [Array<String>] pattern list to find files, e.g. ['spec/**/*_spec.rb']
76
76
  # @param block [Block] block code to find nodes, match conditions and rewrite code.
77
77
  # @return [Synvert::Core::Rewriter::Instance]
78
- def initialize(rewriter, file_pattern, &block)
78
+ def initialize(rewriter, file_patterns, &block)
79
79
  @rewriter = rewriter
80
80
  @actions = []
81
- @file_pattern = file_pattern
81
+ @file_patterns = file_patterns
82
82
  @block = block
83
83
  rewriter.helpers.each { |helper| singleton_class.send(:define_method, helper[:name], &helper[:block]) }
84
84
  end
@@ -87,41 +87,42 @@ module Synvert::Core
87
87
  # It finds all files, for each file, it executes the block code, gets all rewrite actions,
88
88
  # and rewrite source code back to original file.
89
89
  def process
90
- file_pattern = File.join(Configuration.path, @file_pattern)
91
- Dir.glob(file_pattern).each do |file_path|
92
- next if Configuration.skip_files.include? file_path
93
-
94
- begin
95
- puts file_path if Configuration.show_run_process
96
- conflict_actions = []
97
- source = +self.class.file_source(file_path)
98
- ast = self.class.file_ast(file_path)
99
-
100
- @current_file = file_path
101
-
102
- process_with_node ast do
103
- begin
104
- instance_eval(&@block)
105
- rescue NoMethodError
106
- puts @current_node.debug_info
107
- raise
108
- end
109
- end
90
+ @file_patterns.each do |file_pattern|
91
+ Dir.glob(File.join(Configuration.path, file_pattern)).each do |file_path|
92
+ next if Configuration.skip_files.include? file_path
110
93
 
111
- if @actions.length > 0
112
- @actions.sort_by! { |action| [action.begin_pos, action.end_pos] }
113
- conflict_actions = get_conflict_actions
114
- @actions.reverse_each do |action|
115
- source[action.begin_pos...action.end_pos] = action.rewritten_code
94
+ begin
95
+ puts file_path if Configuration.show_run_process
96
+ conflict_actions = []
97
+ source = +self.class.file_source(file_path)
98
+ ast = self.class.file_ast(file_path)
99
+
100
+ @current_file = file_path
101
+
102
+ process_with_node ast do
103
+ begin
104
+ instance_eval(&@block)
105
+ rescue NoMethodError
106
+ puts @current_node.debug_info
107
+ raise
108
+ end
116
109
  end
117
- @actions = []
118
110
 
119
- update_file(file_path, source)
120
- end
121
- rescue Parser::SyntaxError
122
- puts "[Warn] file #{file_path} was not parsed correctly."
123
- # do nothing, iterate next file
124
- end while !conflict_actions.empty?
111
+ if @actions.length > 0
112
+ @actions.sort_by! { |action| [action.begin_pos, action.end_pos] }
113
+ conflict_actions = get_conflict_actions
114
+ @actions.reverse_each do |action|
115
+ source[action.begin_pos...action.end_pos] = action.rewritten_code
116
+ end
117
+ @actions = []
118
+
119
+ update_file(file_path, source)
120
+ end
121
+ rescue Parser::SyntaxError
122
+ puts "[Warn] file #{file_path} was not parsed correctly."
123
+ # do nothing, iterate next file
124
+ end while !conflict_actions.empty?
125
+ end
125
126
  end
126
127
  end
127
128
 
@@ -161,10 +162,10 @@ module Synvert::Core
161
162
  # then continue operating on each matching ast node.
162
163
  #
163
164
  # @param rules [Hash] rules to find mathing ast nodes.
164
- # @param options [Hash] optional, set if recursive or not.
165
+ # @param options [Hash] optional, set if stop_when_match or not.
165
166
  # @param block [Block] block code to continue operating on the matching nodes.
166
167
  def within_node(rules, options = nil, &block)
167
- options ||= { recursive: true }
168
+ options ||= { stop_when_match: false }
168
169
  Rewriter::WithinScope.new(self, rules, options, &block).process
169
170
  end
170
171
 
@@ -26,10 +26,10 @@ module Synvert::Core
26
26
  matching_nodes =
27
27
  if @options[:direct]
28
28
  find_direct_matching_nodes(current_node)
29
- elsif @options[:recursive]
30
- find_recursive_matching_nodes(current_node)
31
- else
29
+ elsif @options[:stop_when_match]
32
30
  find_matching_nodes(current_node)
31
+ else
32
+ find_recursive_matching_nodes(current_node)
33
33
  end
34
34
  @instance.process_with_node current_node do
35
35
  matching_nodes.each do |matching_node|
@@ -89,12 +89,10 @@ module Synvert::Core
89
89
  return matching_nodes
90
90
  end
91
91
  current_node.recursive_children do |child_node|
92
- stop = nil
93
92
  if child_node.match?(@rules)
94
93
  matching_nodes << child_node
95
- stop = :stop
94
+ next :stop
96
95
  end
97
- stop
98
96
  end
99
97
  else
100
98
  current_node.each do |node|
@@ -103,12 +101,10 @@ module Synvert::Core
103
101
  next
104
102
  end
105
103
  node.recursive_children do |child_node|
106
- stop = nil
107
104
  if child_node.match?(@rules)
108
105
  matching_nodes << child_node
109
- stop = :stop
106
+ next :stop
110
107
  end
111
- stop
112
108
  end
113
109
  end
114
110
  end
@@ -231,13 +231,13 @@ module Synvert::Core
231
231
  # Parse within_files dsl, it finds specified files.
232
232
  # It creates a [Synvert::Core::Rewriter::Instance] to rewrite code.
233
233
  #
234
- # @param file_pattern [String] pattern to find files, e.g. spec/**/*_spec.rb
234
+ # @param file_patterns [String|Array<String>] string pattern or list of string pattern to find files, e.g. ['spec/**/*_spec.rb']
235
235
  # @param block [Block] the block to rewrite code in the matching files.
236
- def within_files(file_pattern, &block)
236
+ def within_files(file_patterns, &block)
237
237
  return if @sandbox
238
238
 
239
239
  if (!@ruby_version || @ruby_version.match?) && (!@gem_spec || @gem_spec.match?)
240
- Rewriter::Instance.new(self, file_pattern, &block).process
240
+ Rewriter::Instance.new(self, Array(file_patterns), &block).process
241
241
  end
242
242
  end
243
243
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Synvert
4
4
  module Core
5
- VERSION = '0.58.2'
5
+ VERSION = '0.61.0'
6
6
  end
7
7
  end
data/lib/synvert/core.rb CHANGED
@@ -24,4 +24,35 @@ end
24
24
 
25
25
  module Synvert
26
26
  Rewriter = Core::Rewriter
27
+
28
+ ALL_RUBY_FILES = %w[**/*.rb]
29
+ ALL_RAKE_FILES = %w[**/*.rake]
30
+
31
+ RAILS_APP_FILES = %w[app/**/*.rb engines/*/app/**/*.rb]
32
+ RAILS_CONTROLLER_FILES = %w[app/controllers/**/*.rb engines/*/app/controllers/**/*.rb]
33
+ RAILS_JOB_FILES = %w[app/jobs/**/*.rb engines/*/app/jobs/**/*.rb]
34
+ RAILS_OBSERVER_FILES = %w[app/observers/**/*.rb engines/*/app/observers/**/*.rb]
35
+ RAILS_HELPER_FILES = %w[app/helpers/**/*.rb]
36
+ RAILS_LIB_FILES = %w[lib/**/*.rb engines/*/lib/**/*.rb]
37
+ RAILS_MAILER_FILES = %w[app/mailers/**/*.rb engines/*/app/mailers/**/*.rb]
38
+ RAILS_MIGRATION_FILES = %w[db/migrate/**/*.rb engines/*/db/migrate/**/*.rb]
39
+ RAILS_MODEL_FILES = %w[app/models/**/*.rb engines/*/app/models/**/*.rb]
40
+ RAILS_ROUTE_FILES = %w[config/routes.rb config/routes/**/*.rb engines/*/config/routes.rb engines/*/config/routes/**/*.rb]
41
+ RAILS_VIEW_FILES = %w[app/views/**/*.html.{erb,haml,slim}]
42
+
43
+ RAILS_CONTROLLER_TEST_FILES = %w[
44
+ test/functional/**/*.rb test/controllers/**/*.rb engines/*/test/functional/**/*.rb engines/*/test/controllers/**/*.rb
45
+ spec/functional/**/*.rb spec/controllers/**/*.rb engines/*/spec/functional/**/*.rb engines/*/spec/controllers/**/*.rb
46
+ ]
47
+ RAILS_INTEGRATION_TEST_FILES = %w[test/integration/**/*.rb spec/integration/**/*.rb]
48
+ RAILS_MODEL_TEST_FILES = %w[
49
+ test/unit/**/*.rb engines/*/test/unit/**/*.rb test/models/**/*.rb engines/*/test/models/**/*.rb
50
+ spec/models/**/*.rb engines/*/spec/models/**/*.rb
51
+ ]
52
+
53
+ RAILS_FACTORY_FILES = %w[test/factories/**/*.rb spec/factories/**/*.rb]
54
+ RAILS_RSPEC_FILES = %w[spec/**/*.rb engines/*/spec/**/*.rb]
55
+ RAILS_MINITEST_FILES = %w[test/**/*.rb engines/*/test/**/*.rb]
56
+ RAILS_CUCUMBER_FILES = %w[features/**/*.rb]
57
+ RAILS_TEST_FILES = RAILS_MINITEST_FILES + RAILS_RSPEC_FILES + RAILS_CUCUMBER_FILES
27
58
  end
@@ -396,6 +396,14 @@ describe Parser::AST::Node do
396
396
  end
397
397
  end
398
398
 
399
+ describe '#filename' do
400
+ it 'gets file name' do
401
+ source = 'foobar'
402
+ node = parse(source)
403
+ expect(node.filename).to eq '(string)'
404
+ end
405
+ end
406
+
399
407
  describe '#to_source' do
400
408
  it 'gets for node' do
401
409
  source = 'params[:user][:email]'
@@ -546,6 +554,54 @@ describe Parser::AST::Node do
546
554
  end
547
555
  end
548
556
 
557
+ describe '#child_node_by_name' do
558
+ context 'block node' do
559
+ it 'checks caller' do
560
+ node = parse('Factory.define :user do |user|; end')
561
+ child_node = node.child_node_by_name(:caller)
562
+ expect(child_node).to eq node.caller
563
+ end
564
+
565
+ it 'checks arguments' do
566
+ node = parse('Factory.define :user do |user|; end')
567
+ child_node = node.child_node_by_name(:arguments)
568
+ expect(child_node).to eq node.arguments
569
+ end
570
+
571
+ it 'checks caller.receiver' do
572
+ node = parse('Factory.define :user do |user|; end')
573
+ child_node = node.child_node_by_name('caller.receiver')
574
+ expect(child_node).to eq node.caller.receiver
575
+ end
576
+
577
+ it 'checks caller.message' do
578
+ node = parse('Factory.define :user do |user|; end')
579
+ child_node = node.child_node_by_name('caller.message')
580
+ expect(child_node).to eq node.caller.message
581
+ end
582
+ end
583
+
584
+ context 'array' do
585
+ it 'checks array by index' do
586
+ node = parse('factory :admin, class: User do; end')
587
+ child_node = node.child_node_by_name('caller.arguments.2')
588
+ expect(child_node).to eq node.caller.arguments[1]
589
+ end
590
+
591
+ it 'checks array by method' do
592
+ node = parse('factory :admin, class: User do; end')
593
+ child_node = node.child_node_by_name('caller.arguments.second')
594
+ expect(child_node).to eq node.caller.arguments[1]
595
+ end
596
+
597
+ it "checks array' value" do
598
+ node = parse('factory :admin, class: User do; end')
599
+ child_node = node.child_node_by_name('caller.arguments.second.class_value')
600
+ expect(child_node).to eq node.caller.arguments[1].class_value
601
+ end
602
+ end
603
+ end
604
+
549
605
  describe '#child_node_range' do
550
606
  context 'block node' do
551
607
  it 'checks caller' do
@@ -712,6 +768,26 @@ describe Parser::AST::Node do
712
768
  expect(range).to be_nil
713
769
  end
714
770
  end
771
+
772
+ context 'array' do
773
+ it 'checks array by index' do
774
+ node = parse('factory :admin, class: User do; end')
775
+ range = node.child_node_range('caller.arguments.2')
776
+ expect(range.to_range).to eq(16...27)
777
+ end
778
+
779
+ it 'checks array by method' do
780
+ node = parse('factory :admin, class: User do; end')
781
+ range = node.child_node_range('caller.arguments.second')
782
+ expect(range.to_range).to eq(16...27)
783
+ end
784
+
785
+ it "checks array' value" do
786
+ node = parse('factory :admin, class: User do; end')
787
+ range = node.child_node_range('caller.arguments.second.class_value')
788
+ expect(range.to_range).to eq(23...27)
789
+ end
790
+ end
715
791
  end
716
792
 
717
793
  describe '#rewritten_source' do
@@ -819,6 +895,22 @@ describe Parser::AST::Node do
819
895
  end
820
896
  end
821
897
 
898
+ describe '#to_string' do
899
+ context 'sym node' do
900
+ it 'converts symbol to string' do
901
+ node = parse(':foobar')
902
+ expect(node.to_string).to eq 'foobar'
903
+ end
904
+ end
905
+
906
+ context 'other node' do
907
+ it 'does nothing' do
908
+ node = parse("'foobar'")
909
+ expect(node.to_string).to eq "'foobar'"
910
+ end
911
+ end
912
+ end
913
+
822
914
  describe '#to_lambda_literal' do
823
915
  context 'lambda node' do
824
916
  it 'converts to lambda literal without arguments' do
@@ -8,14 +8,14 @@ module Synvert::Core
8
8
 
9
9
  let(:instance) {
10
10
  rewriter = Rewriter.new('foo', 'bar')
11
- Rewriter::Instance.new(rewriter, 'file pattern')
11
+ Rewriter::Instance.new(rewriter, ['file pattern'])
12
12
  }
13
13
 
14
14
  it 'parses within_node' do
15
15
  scope = double
16
16
  block = proc {}
17
17
  expect(Rewriter::WithinScope).to receive(:new)
18
- .with(instance, { type: 'send', message: 'create' }, { recursive: true }, &block)
18
+ .with(instance, { type: 'send', message: 'create' }, { stop_when_match: false }, &block)
19
19
  .and_return(scope)
20
20
  expect(scope).to receive(:process)
21
21
  instance.within_node(type: 'send', message: 'create', &block)
@@ -25,7 +25,7 @@ module Synvert::Core
25
25
  scope = double
26
26
  block = proc {}
27
27
  expect(Rewriter::WithinScope).to receive(:new)
28
- .with(instance, { type: 'send', message: 'create' }, { recursive: true }, &block)
28
+ .with(instance, { type: 'send', message: 'create' }, { stop_when_match: false }, &block)
29
29
  .and_return(scope)
30
30
  expect(scope).to receive(:process)
31
31
  instance.with_node(type: 'send', message: 'create', &block)
@@ -35,10 +35,10 @@ module Synvert::Core
35
35
  scope = double
36
36
  block = proc {}
37
37
  expect(Rewriter::WithinScope).to receive(:new)
38
- .with(instance, { type: 'send', message: 'create' }, { recursive: false }, &block)
38
+ .with(instance, { type: 'send', message: 'create' }, { stop_when_match: true }, &block)
39
39
  .and_return(scope)
40
40
  expect(scope).to receive(:process)
41
- instance.within_node({ type: 'send', message: 'create' }, { recursive: false }, &block)
41
+ instance.within_node({ type: 'send', message: 'create' }, { stop_when_match: true }, &block)
42
42
  end
43
43
 
44
44
  it 'parses within_direct_node' do
@@ -185,7 +185,7 @@ module Synvert::Core
185
185
 
186
186
  it 'writes new code to file' do
187
187
  instance =
188
- Rewriter::Instance.new rewriter, 'spec/**/*_spec.rb' do
188
+ Rewriter::Instance.new rewriter, ['spec/**/*_spec.rb'] do
189
189
  with_node type: 'send', receiver: 'FactoryGirl', message: 'create' do
190
190
  replace_with 'create {{arguments}}'
191
191
  end
@@ -212,7 +212,7 @@ module Synvert::Core
212
212
 
213
213
  it 'does not write if file content is not changed' do
214
214
  instance =
215
- Rewriter::Instance.new rewriter, 'spec/spec_helper.rb' do
215
+ Rewriter::Instance.new rewriter, ['spec/spec_helper.rb'] do
216
216
  with_node type: 'block', caller: { receiver: 'RSpec', message: 'configure' } do
217
217
  unless_exist_node type: 'send', message: 'include', arguments: ['FactoryGirl::Syntax::Methods'] do
218
218
  insert '{{arguments.first}}.include FactoryGirl::Syntax::Methods'
@@ -237,7 +237,7 @@ module Synvert::Core
237
237
 
238
238
  it 'does not read file if already read' do
239
239
  instance =
240
- Rewriter::Instance.new rewriter, 'spec/spec_helper.rb' do
240
+ Rewriter::Instance.new rewriter, ['spec/spec_helper.rb'] do
241
241
  with_node type: 'block', caller: { receiver: 'RSpec', message: 'configure' } do
242
242
  unless_exist_node type: 'send', message: 'include', arguments: ['FactoryGirl::Syntax::Methods'] do
243
243
  insert '{{arguments.first}}.include FactoryGirl::Syntax::Methods'
@@ -263,7 +263,7 @@ module Synvert::Core
263
263
 
264
264
  it 'updates file_source and file_ast when writing a file' do
265
265
  instance =
266
- Rewriter::Instance.new rewriter, 'spec/**/*_spec.rb' do
266
+ Rewriter::Instance.new rewriter, ['spec/**/*_spec.rb'] do
267
267
  with_node type: 'send', receiver: 'FactoryGirl', message: 'create' do
268
268
  replace_with 'create {{arguments}}'
269
269
  end
@@ -299,7 +299,7 @@ module Synvert::Core
299
299
  action1 = double(begin_pos: 10, end_pos: 20)
300
300
  action2 = double(begin_pos: 30, end_pos: 40)
301
301
  action3 = double(begin_pos: 50, end_pos: 60)
302
- instance = Rewriter::Instance.new rewriter, 'spec/spec_helper.rb'
302
+ instance = Rewriter::Instance.new rewriter, ['spec/spec_helper.rb']
303
303
  instance.instance_variable_set :@actions, [action1, action2, action3]
304
304
  conflict_actions = instance.send(:get_conflict_actions)
305
305
  expect(conflict_actions).to eq []
@@ -310,7 +310,7 @@ module Synvert::Core
310
310
  action1 = double(begin_pos: 30, end_pos: 40)
311
311
  action2 = double(begin_pos: 50, end_pos: 60)
312
312
  action3 = double(begin_pos: 10, end_pos: 20)
313
- instance = Rewriter::Instance.new rewriter, 'spec/spec_helper.rb'
313
+ instance = Rewriter::Instance.new rewriter, ['spec/spec_helper.rb']
314
314
  instance.instance_variable_set :@actions, [action1, action2, action3]
315
315
  conflict_actions = instance.send(:get_conflict_actions)
316
316
  expect(conflict_actions).to eq [action2, action1]
@@ -54,7 +54,7 @@ module Synvert::Core
54
54
 
55
55
  it 'matches multiple block nodes' do
56
56
  block_nodes = []
57
- scope = Rewriter::WithinScope.new(instance, { type: 'block' }, { recursive: true }) do
57
+ scope = Rewriter::WithinScope.new(instance, { type: 'block' }, { stop_when_match: false }) do
58
58
  block_nodes << node
59
59
  end
60
60
  scope.process
@@ -63,7 +63,7 @@ module Synvert::Core
63
63
 
64
64
  it 'matches only one block node if no recursive' do
65
65
  block_nodes = []
66
- scope = Rewriter::WithinScope.new(instance, { type: 'block' } , { recursive: false }) do
66
+ scope = Rewriter::WithinScope.new(instance, { type: 'block' } , { stop_when_match: true }) do
67
67
  block_nodes << node
68
68
  end
69
69
  scope.process
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: 0.58.2
4
+ version: 0.61.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: 2021-10-22 00:00:00.000000000 Z
11
+ date: 2021-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport