synvert-core 1.30.2 → 1.31.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 +4 -4
- data/CHANGELOG.md +9 -0
- data/Gemfile.lock +3 -3
- data/lib/synvert/core/configuration.rb +12 -1
- data/lib/synvert/core/rewriter/instance.rb +1 -1
- data/lib/synvert/core/rewriter.rb +29 -17
- data/lib/synvert/core/version.rb +1 -1
- data/spec/synvert/core/rewriter/instance_spec.rb +33 -2
- data/spec/synvert/core/rewriter_spec.rb +25 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3346883848c81ac9a130e077d0aae4eec34df1fcc365c95b9971b558b346f1a9
|
4
|
+
data.tar.gz: 15f5f83ef0d59c08edcf2cd076a36d0e057e94fee8d0435ca679c1a3e094dd01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
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.
|
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
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
new_actions
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
last_start
|
161
|
-
|
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
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
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
|
-
|
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
|
-
|
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
|
data/lib/synvert/core/version.rb
CHANGED
@@ -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
|
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 =
|
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.
|
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-
|
11
|
+
date: 2024-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|