synvert-core 1.30.3 → 1.31.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/Gemfile.lock +6 -6
- data/README.md +0 -1
- data/lib/synvert/core/rewriter.rb +29 -32
- data/lib/synvert/core/utils.rb +2 -2
- data/lib/synvert/core/version.rb +1 -1
- data/spec/synvert/core/rewriter/instance_spec.rb +1 -1
- data/spec/synvert/core/rewriter_spec.rb +25 -9
- data/synvert-core-ruby.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6afbabeda5ddf0d37764d420af4dea4751ede79c6f1c58319b854e351825f82
|
4
|
+
data.tar.gz: 18b68174ac1418246ccfbeabac6797fd5f695bdaf2a341c6c2427aa6628b96fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c081ce34db2a4f400d14e2fac14b7cab18ccc5099e16079f4c8a88eb8aeb7004a7f61a8ca4e2538146fb8ea0610f099cfc5da6f403efb965e57db31afc3e459a
|
7
|
+
data.tar.gz: 75f4b8858fb303d11226719ae9c87304de3a07c56005cd888335e7386ede75a3345f6500857968a7608e67f364f477450f5c3fa1d8e2089eb2d16e991d434cfc
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 1.31.1 (2024-01-30)
|
4
|
+
|
5
|
+
* Update `node_mutation` to 1.22.4
|
6
|
+
* Remove `redo_until_no_change` dsl
|
7
|
+
|
8
|
+
## 1.31.0 (2024-01-14)
|
9
|
+
|
10
|
+
* Support `Configuration.test_result` in `add_file` and `remove_file` dsl
|
11
|
+
* Get new source in `Rewriter#test`
|
12
|
+
|
3
13
|
## 1.30.3 (2024-01-13)
|
4
14
|
|
5
15
|
* Add `Configuration.test_result` option
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
synvert-core (1.
|
4
|
+
synvert-core (1.31.1)
|
5
5
|
activesupport (< 7.0.0)
|
6
|
-
node_mutation (>= 1.
|
6
|
+
node_mutation (>= 1.22.4)
|
7
7
|
node_query (>= 1.13.12)
|
8
8
|
parallel
|
9
9
|
parser
|
@@ -22,7 +22,7 @@ GEM
|
|
22
22
|
zeitwerk (~> 2.3)
|
23
23
|
ast (2.4.2)
|
24
24
|
coderay (1.1.3)
|
25
|
-
concurrent-ruby (1.2.
|
25
|
+
concurrent-ruby (1.2.3)
|
26
26
|
diff-lcs (1.5.0)
|
27
27
|
fakefs (2.4.0)
|
28
28
|
ffi (1.15.5)
|
@@ -48,15 +48,15 @@ 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.21.
|
51
|
+
minitest (5.21.2)
|
52
52
|
nenv (0.3.0)
|
53
|
-
node_mutation (1.22.
|
53
|
+
node_mutation (1.22.4)
|
54
54
|
node_query (1.14.1)
|
55
55
|
notiffany (0.1.3)
|
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.5)
|
60
60
|
ast (~> 2.4.1)
|
61
61
|
racc
|
62
62
|
parser_node_ext (1.2.1)
|
data/README.md
CHANGED
@@ -70,7 +70,6 @@ DSLs are as follows
|
|
70
70
|
* [helper_method](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#helper_method-instance_method) - define a helper method
|
71
71
|
* [add_snippet](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#add_snippet-instance_method) - call another rewriter
|
72
72
|
* [call_helper](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#call_helper-instance_method) - call a shared rewriter
|
73
|
-
* [redo_until_no_change](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#redo_until_no_change-instance_method) - run the snippet until no change
|
74
73
|
|
75
74
|
Scopes:
|
76
75
|
|
@@ -119,7 +119,6 @@ module Synvert::Core
|
|
119
119
|
@sub_snippets = []
|
120
120
|
@warnings = []
|
121
121
|
@affected_files = Set.new
|
122
|
-
@redo_until_no_change = false
|
123
122
|
@options = DEFAULT_OPTIONS.dup
|
124
123
|
@test_results = Hash.new { |h, k| h[k] = [] }
|
125
124
|
self.class.register(@group, @name, self)
|
@@ -130,8 +129,6 @@ module Synvert::Core
|
|
130
129
|
def process
|
131
130
|
@affected_files = Set.new
|
132
131
|
instance_eval(&@block)
|
133
|
-
|
134
|
-
process if !@affected_files.empty? && @redo_until_no_change # redo
|
135
132
|
end
|
136
133
|
|
137
134
|
# Process rewriter with sandbox mode.
|
@@ -146,25 +143,26 @@ module Synvert::Core
|
|
146
143
|
@affected_files = Set.new
|
147
144
|
instance_eval(&@block)
|
148
145
|
|
149
|
-
if
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
146
|
+
if Configuration.test_result == 'new_source'
|
147
|
+
@test_results.values.flatten
|
148
|
+
else
|
149
|
+
@test_results.map do |filename, test_results|
|
150
|
+
new_actions = test_results.map(&:actions).flatten.sort_by(&:end)
|
151
|
+
last_start = -1
|
152
|
+
conflicted =
|
153
|
+
new_actions.any? do |action|
|
154
|
+
if last_start > action.end
|
155
|
+
true
|
156
|
+
else
|
157
|
+
last_start = action.start
|
158
|
+
false
|
159
|
+
end
|
162
160
|
end
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
161
|
+
result = NodeMutation::Result.new(affected: true, conflicted: conflicted)
|
162
|
+
result.actions = new_actions
|
163
|
+
result.file_path = filename
|
164
|
+
result
|
165
|
+
end
|
168
166
|
end
|
169
167
|
end
|
170
168
|
|
@@ -289,7 +287,11 @@ module Synvert::Core
|
|
289
287
|
|
290
288
|
unless @options[:write_to_file]
|
291
289
|
result = NodeMutation::Result.new(affected: true, conflicted: false)
|
292
|
-
|
290
|
+
if Configuration.test_result == 'new_source'
|
291
|
+
result.new_source = content
|
292
|
+
else
|
293
|
+
result.actions = [NodeMutation::Struct::Action.new(:add_file, 0, 0, content)]
|
294
|
+
end
|
293
295
|
result.file_path = filename
|
294
296
|
merge_test_result(result)
|
295
297
|
return
|
@@ -316,7 +318,11 @@ module Synvert::Core
|
|
316
318
|
|
317
319
|
unless @options[:write_to_file]
|
318
320
|
result = NodeMutation::Result.new(affected: true, conflicted: false)
|
319
|
-
|
321
|
+
if Configuration.test_result == 'new_source'
|
322
|
+
result.new_source = nil
|
323
|
+
else
|
324
|
+
result.actions = [NodeMutation::Struct::Action.new(:remove_file, 0, -1)]
|
325
|
+
end
|
320
326
|
result.file_path = filename
|
321
327
|
merge_test_result(result)
|
322
328
|
return
|
@@ -394,15 +400,6 @@ module Synvert::Core
|
|
394
400
|
@helpers << { name: name, block: block }
|
395
401
|
end
|
396
402
|
|
397
|
-
# Rerun the snippet until no change.
|
398
|
-
# @example
|
399
|
-
# Synvert::Rewriter.new 'ruby', 'nested_class_definition' do
|
400
|
-
# redo_until_no_change
|
401
|
-
# end
|
402
|
-
def redo_until_no_change
|
403
|
-
@redo_until_no_change = true
|
404
|
-
end
|
405
|
-
|
406
403
|
private
|
407
404
|
|
408
405
|
# Handle one file.
|
data/lib/synvert/core/utils.rb
CHANGED
@@ -16,7 +16,7 @@ module Synvert::Core
|
|
16
16
|
uri = URI.parse(format_url(snippet_name))
|
17
17
|
return uri.open.read if remote_snippet_exists?(uri)
|
18
18
|
|
19
|
-
raise Errors::SnippetNotFound.new("#{snippet_name}
|
19
|
+
raise Errors::SnippetNotFound.new("#{snippet_name} not found")
|
20
20
|
elsif is_valid_file?(snippet_name)
|
21
21
|
return File.read(snippet_name)
|
22
22
|
else
|
@@ -26,7 +26,7 @@ module Synvert::Core
|
|
26
26
|
snippet_uri = URI.parse(format_url(remote_snippet_url(snippet_name)))
|
27
27
|
return snippet_uri.open.read if remote_snippet_exists?(snippet_uri)
|
28
28
|
|
29
|
-
raise Errors::SnippetNotFound.new("#{snippet_name}
|
29
|
+
raise Errors::SnippetNotFound.new("#{snippet_name} not found")
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
data/lib/synvert/core/version.rb
CHANGED
@@ -456,7 +456,7 @@ module Synvert::Core
|
|
456
456
|
before { Configuration.test_result = 'new_source' }
|
457
457
|
after { Configuration.test_result = nil }
|
458
458
|
|
459
|
-
it 'gets new_source
|
459
|
+
it 'gets new_source' do
|
460
460
|
instance =
|
461
461
|
Rewriter::Instance.new rewriter, 'spec/models/post_spec.rb' do
|
462
462
|
with_node type: 'send', receiver: 'FactoryGirl', message: 'create' do
|
@@ -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
|
@@ -357,15 +382,6 @@ module Synvert::Core
|
|
357
382
|
expect(instance.dynamic_helper('arg1', 'arg2')).to eq 'dynamic result'
|
358
383
|
end
|
359
384
|
|
360
|
-
it 'parses redo_until_no_change' do
|
361
|
-
rewriter =
|
362
|
-
Rewriter.new 'group', 'name' do
|
363
|
-
redo_until_no_change
|
364
|
-
end
|
365
|
-
rewriter.process
|
366
|
-
expect(rewriter.instance_variable_get('@redo_until_no_change')).to be_truthy
|
367
|
-
end
|
368
|
-
|
369
385
|
describe 'class methods' do
|
370
386
|
before :each do
|
371
387
|
Rewriter.clear
|
data/synvert-core-ruby.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.add_runtime_dependency "activesupport", "< 7.0.0"
|
23
23
|
spec.add_runtime_dependency "node_query", ">= 1.13.12"
|
24
|
-
spec.add_runtime_dependency "node_mutation", ">= 1.
|
24
|
+
spec.add_runtime_dependency "node_mutation", ">= 1.22.4"
|
25
25
|
spec.add_runtime_dependency "parser"
|
26
26
|
spec.add_runtime_dependency "parser_node_ext", ">= 1.2.1"
|
27
27
|
spec.add_runtime_dependency "syntax_tree"
|
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.1
|
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-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 1.
|
47
|
+
version: 1.22.4
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 1.
|
54
|
+
version: 1.22.4
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: parser
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|