synvert-core 1.30.2 → 1.31.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: 5fce0db1974beb18ed0cdfbaae3e68e11c50c3f7ba4bd0dc5904dd7b2035975b
4
- data.tar.gz: 7de77483010cb937b6ae1020579d0d8c21889f9c4076a47c8d3a379e23fd76c1
3
+ metadata.gz: 3346883848c81ac9a130e077d0aae4eec34df1fcc365c95b9971b558b346f1a9
4
+ data.tar.gz: 15f5f83ef0d59c08edcf2cd076a36d0e057e94fee8d0435ca679c1a3e094dd01
5
5
  SHA512:
6
- metadata.gz: 175fc9b3ffef5f498d68667aa766a62c739940e3f2f525277c2a6c196ca4a33c025ace8b4d7dbb13ef41596e873f6fa477e46b35ddaa319fb0484debac0e5730
7
- data.tar.gz: 3c43b3b9d6319998e5c9dd628c68890481c57974d68937a52586762d606772099f04f702b337a0cd1192bae733cd122d7d09742318893b1fa0ce14ed25b6fe4a
6
+ metadata.gz: a24728c75868284ed17baa5cdc9b9ab1d0961ba560ea00f7a71eaf0fe4bf3a01f322435002a9911e934d87a51a744f77b1c21b54bb8126739d31e0a50a9a991c
7
+ data.tar.gz: 65505c1d4f55b82d789f119463d535a67c11c85f18cbcbb0d7311d572f23e42085b44477d7d70c14e4019511cf5db7c502ac2e7278f0481720aaf64da7031e1f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.31.0 (2024-01-14)
4
+
5
+ * Support `Configuration.test_result` in `add_file` and `remove_file` dsl
6
+ * Get new source in `Rewriter#test`
7
+
8
+ ## 1.30.3 (2024-01-13)
9
+
10
+ * Add `Configuration.test_result` option
11
+
3
12
  ## 1.30.2 (2024-01-09)
4
13
 
5
14
  * Add `Configuration.strict` option
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- synvert-core (1.30.2)
4
+ synvert-core (1.31.0)
5
5
  activesupport (< 7.0.0)
6
6
  node_mutation (>= 1.21.6)
7
7
  node_query (>= 1.13.12)
@@ -48,7 +48,7 @@ GEM
48
48
  rb-inotify (~> 0.9, >= 0.9.10)
49
49
  lumberjack (1.2.8)
50
50
  method_source (1.0.0)
51
- minitest (5.20.0)
51
+ minitest (5.21.1)
52
52
  nenv (0.3.0)
53
53
  node_mutation (1.22.2)
54
54
  node_query (1.14.1)
@@ -56,7 +56,7 @@ GEM
56
56
  nenv (~> 0.1)
57
57
  shellany (~> 0.0)
58
58
  parallel (1.24.0)
59
- parser (3.3.0.2)
59
+ parser (3.3.0.3)
60
60
  ast (~> 2.4.1)
61
61
  racc
62
62
  parser_node_ext (1.2.1)
@@ -12,6 +12,7 @@ module Synvert::Core
12
12
  # @!attribute [w] single_quote
13
13
  # @!attribute [w] tab_width
14
14
  # @!attribute [w] strict, if strict is false, it will ignore ruby version and gem version check.
15
+ # @!attribute [w] test_result, default is 'actions', it can be 'actions' or 'new_source'.
15
16
  attr_writer :root_path,
16
17
  :skip_paths,
17
18
  :only_paths,
@@ -19,7 +20,8 @@ module Synvert::Core
19
20
  :number_of_workers,
20
21
  :single_quote,
21
22
  :tab_width,
22
- :strict
23
+ :strict,
24
+ :test_result
23
25
 
24
26
  # Get the path.
25
27
  #
@@ -80,6 +82,15 @@ module Synvert::Core
80
82
  def strict
81
83
  @strict.nil? ? true : @strict
82
84
  end
85
+
86
+ # Returns the value of the test_result flag.
87
+ #
88
+ # If the test_result flag is not set, it returns 'actions' by default.
89
+ #
90
+ # @return [String] the value of the test_result flag
91
+ def test_result
92
+ @test_result || 'actions'
93
+ end
83
94
  end
84
95
  end
85
96
  end
@@ -88,7 +88,7 @@ module Synvert::Core
88
88
  instance_eval(&@block)
89
89
  end
90
90
 
91
- result = @current_mutation.test
91
+ result = Configuration.test_result == 'new_source' ? @current_mutation.process : @current_mutation.test
92
92
  result.file_path = file_path
93
93
  result
94
94
  rescue Parser::SyntaxError => e
@@ -149,22 +149,26 @@ module Synvert::Core
149
149
  if !@affected_files.empty? && @redo_until_no_change # redo
150
150
  test
151
151
  end
152
- @test_results.map do |filename, test_results|
153
- new_actions = test_results.map(&:actions).flatten.sort_by(&:end)
154
- last_start = -1
155
- conflicted =
156
- new_actions.any? do |action|
157
- if last_start > action.end
158
- true
159
- else
160
- last_start = action.start
161
- false
152
+ if Configuration.test_result == 'new_source'
153
+ @test_results.values.flatten
154
+ else
155
+ @test_results.map do |filename, test_results|
156
+ new_actions = test_results.map(&:actions).flatten.sort_by(&:end)
157
+ last_start = -1
158
+ conflicted =
159
+ new_actions.any? do |action|
160
+ if last_start > action.end
161
+ true
162
+ else
163
+ last_start = action.start
164
+ false
165
+ end
162
166
  end
163
- end
164
- result = NodeMutation::Result.new(affected: true, conflicted: conflicted)
165
- result.actions = new_actions
166
- result.file_path = filename
167
- result
167
+ result = NodeMutation::Result.new(affected: true, conflicted: conflicted)
168
+ result.actions = new_actions
169
+ result.file_path = filename
170
+ result
171
+ end
168
172
  end
169
173
  end
170
174
 
@@ -289,7 +293,11 @@ module Synvert::Core
289
293
 
290
294
  unless @options[:write_to_file]
291
295
  result = NodeMutation::Result.new(affected: true, conflicted: false)
292
- result.actions = [NodeMutation::Struct::Action.new(:add_file, 0, 0, content)]
296
+ if Configuration.test_result == 'new_source'
297
+ result.new_source = content
298
+ else
299
+ result.actions = [NodeMutation::Struct::Action.new(:add_file, 0, 0, content)]
300
+ end
293
301
  result.file_path = filename
294
302
  merge_test_result(result)
295
303
  return
@@ -316,7 +324,11 @@ module Synvert::Core
316
324
 
317
325
  unless @options[:write_to_file]
318
326
  result = NodeMutation::Result.new(affected: true, conflicted: false)
319
- result.actions = [NodeMutation::Struct::Action.new(:remove_file, 0, -1)]
327
+ if Configuration.test_result == 'new_source'
328
+ result.new_source = nil
329
+ else
330
+ result.actions = [NodeMutation::Struct::Action.new(:remove_file, 0, -1)]
331
+ end
320
332
  result.file_path = filename
321
333
  merge_test_result(result)
322
334
  return
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Synvert
4
4
  module Core
5
- VERSION = '1.30.2'
5
+ VERSION = '1.31.0'
6
6
  end
7
7
  end
@@ -429,7 +429,7 @@ module Synvert::Core
429
429
  describe '#test' do
430
430
  let(:rewriter) { Rewriter.new('foo', 'bar') }
431
431
 
432
- it 'gets actions if afected' do
432
+ it 'gets actions if affected' do
433
433
  instance =
434
434
  Rewriter::Instance.new rewriter, 'spec/models/post_spec.rb' do
435
435
  with_node type: 'send', receiver: 'FactoryGirl', message: 'create' do
@@ -452,6 +452,37 @@ module Synvert::Core
452
452
  ]
453
453
  end
454
454
 
455
+ context 'Configuration.test_result is new_source' do
456
+ before { Configuration.test_result = 'new_source' }
457
+ after { Configuration.test_result = nil }
458
+
459
+ it 'gets new_source' do
460
+ instance =
461
+ Rewriter::Instance.new rewriter, 'spec/models/post_spec.rb' do
462
+ with_node type: 'send', receiver: 'FactoryGirl', message: 'create' do
463
+ replace_with 'create {{arguments}}'
464
+ end
465
+ end
466
+ input = <<~EOS
467
+ it 'uses factory_girl' do
468
+ user = FactoryGirl.create :user
469
+ post = FactoryGirl.create :post, user: user
470
+ assert post.valid?
471
+ end
472
+ EOS
473
+ expect(File).to receive(:read).with('./spec/models/post_spec.rb', encoding: 'UTF-8').and_return(input)
474
+ results = instance.test
475
+ expect(results.file_path).to eq 'spec/models/post_spec.rb'
476
+ expect(results.new_source).to eq <<~EOS
477
+ it 'uses factory_girl' do
478
+ user = create :user
479
+ post = create :post, user: user
480
+ assert post.valid?
481
+ end
482
+ EOS
483
+ end
484
+ end
485
+
455
486
  it 'gets nothing if not affected' do
456
487
  instance =
457
488
  Rewriter::Instance.new rewriter, 'spec/spec_helper.rb' do
@@ -591,7 +622,7 @@ module Synvert::Core
591
622
 
592
623
  context 'Configuration.single_quote = false' do
593
624
  before { Configuration.single_quote = false }
594
- after { Configuration.single_quote = true }
625
+ after { Configuration.single_quote = nil }
595
626
 
596
627
  it 'wraps with double quotes' do
597
628
  expect(instance.wrap_with_quotes('foobar')).to eq '"foobar"'
@@ -100,6 +100,31 @@ module Synvert::Core
100
100
  expect(results[0].actions).to eq [NodeMutation::Struct::Action.new(:replace, 6, 12, 'Synvert')]
101
101
  end
102
102
  end
103
+
104
+ context 'Configuration.test_result is new_source' do
105
+ before { Configuration.test_result = 'new_source' }
106
+ after { Configuration.test_result = nil }
107
+
108
+ it 'gets test results with new_source' do
109
+ rewriter =
110
+ Rewriter.new('group', 'name') do
111
+ within_files '**/*.rb' do
112
+ with_node node_type: 'class', name: 'Foobar' do
113
+ replace :name, with: 'Synvert'
114
+ end
115
+ end
116
+ end
117
+ input = "class Foobar\nend"
118
+ FakeFS do
119
+ File.write("code.rb", input)
120
+ results = rewriter.test
121
+ expect(results[0].file_path).to eq '/code.rb'
122
+ expect(results[0].affected?).to be_truthy
123
+ expect(results[0].conflicted?).to be_falsey
124
+ expect(results[0].new_source).to eq "class Synvert\nend"
125
+ end
126
+ end
127
+ end
103
128
  end
104
129
 
105
130
  describe 'parses within_file' do
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.30.2
4
+ version: 1.31.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: 2024-01-09 00:00:00.000000000 Z
11
+ date: 2024-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport