synvert-core 1.28.2 → 1.28.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/Gemfile.lock +9 -9
- data/lib/synvert/core/rewriter.rb +27 -6
- data/lib/synvert/core/version.rb +1 -1
- data/lib/synvert/core.rb +0 -1
- data/synvert-core-ruby.gemspec +2 -2
- metadata +7 -10
- data/lib/synvert/core/node_ext.rb +0 -130
- data/spec/synvert/core/node_ext_spec.rb +0 -108
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc7906502ebd8ee2093236003a46a312f11487be41316be86777128c1685bda1
|
4
|
+
data.tar.gz: 706c9c932dfbfb16ba5cff3374380b54ae8239d12e2ef98dd7c4c45dd765d7a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 767ec7b8f201e7cdb28fd145ac83a5afbc0c96f4d1536dc7bd18c996f948a780ee70925c041b134078fbdfb6728605840e285badce8635beb6631b045220c4c4
|
7
|
+
data.tar.gz: 6514f640f49da23297fd5ce904fa71ab913bf6b2fd352c56fd04248e28ae303700b0fd72e548c25ca72839b787a1730d7dc862cdcc00f02fda126ed7ce90956e
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 1.28.4 (2023-08-16)
|
4
|
+
|
5
|
+
* Merge `test_results` based on file_path
|
6
|
+
* Update `node-query` to 1.13.9
|
7
|
+
* Update `node_mutation` to 1.19.3
|
8
|
+
|
9
|
+
## 1.28.3 (2023-06-22)
|
10
|
+
|
11
|
+
* Update `node_mutation` to 1.19.1
|
12
|
+
* Remove `node_ext`
|
13
|
+
|
3
14
|
## 1.28.2 (2023-06-17)
|
4
15
|
|
5
16
|
* Update `node_query` to 1.13.5
|
data/Gemfile.lock
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
synvert-core (1.28.
|
4
|
+
synvert-core (1.28.4)
|
5
5
|
activesupport (< 7.0.0)
|
6
|
-
node_mutation (>= 1.
|
7
|
-
node_query (>= 1.13.
|
6
|
+
node_mutation (>= 1.19.3)
|
7
|
+
node_query (>= 1.13.9)
|
8
8
|
parallel
|
9
9
|
parser
|
10
10
|
parser_node_ext (>= 1.2.0)
|
@@ -14,7 +14,7 @@ PATH
|
|
14
14
|
GEM
|
15
15
|
remote: https://rubygems.org/
|
16
16
|
specs:
|
17
|
-
activesupport (6.1.7.
|
17
|
+
activesupport (6.1.7.4)
|
18
18
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
19
19
|
i18n (>= 1.6, < 2)
|
20
20
|
minitest (>= 5.1)
|
@@ -48,10 +48,10 @@ 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.19.0)
|
52
52
|
nenv (0.3.0)
|
53
|
-
node_mutation (1.
|
54
|
-
node_query (1.13.
|
53
|
+
node_mutation (1.19.3)
|
54
|
+
node_query (1.13.10)
|
55
55
|
notiffany (0.1.3)
|
56
56
|
nenv (~> 0.1)
|
57
57
|
shellany (~> 0.0)
|
@@ -86,12 +86,12 @@ GEM
|
|
86
86
|
shellany (0.0.1)
|
87
87
|
syntax_tree (6.1.1)
|
88
88
|
prettier_print (>= 1.2.0)
|
89
|
-
syntax_tree_ext (0.6.
|
89
|
+
syntax_tree_ext (0.6.3)
|
90
90
|
syntax_tree
|
91
91
|
thor (1.2.1)
|
92
92
|
tzinfo (2.0.6)
|
93
93
|
concurrent-ruby (~> 1.0)
|
94
|
-
zeitwerk (2.6.
|
94
|
+
zeitwerk (2.6.11)
|
95
95
|
|
96
96
|
PLATFORMS
|
97
97
|
ruby
|
@@ -91,7 +91,7 @@ module Synvert::Core
|
|
91
91
|
# @!attribute [r] gem_spec
|
92
92
|
# @return [Rewriter::GemSpec] the gem spec
|
93
93
|
# @!attribute [r] test_results
|
94
|
-
# @return [
|
94
|
+
# @return [Hash<String, Object>] the test results
|
95
95
|
# @!attribute [rw] options
|
96
96
|
# @return [Hash] the rewriter options
|
97
97
|
attr_reader :group,
|
@@ -121,7 +121,7 @@ module Synvert::Core
|
|
121
121
|
@affected_files = Set.new
|
122
122
|
@redo_until_no_change = false
|
123
123
|
@options = DEFAULT_OPTIONS.dup
|
124
|
-
@test_results = []
|
124
|
+
@test_results = Hash.new { |h, k| h[k] = [] }
|
125
125
|
self.class.register(@group, @name, self)
|
126
126
|
end
|
127
127
|
|
@@ -153,7 +153,22 @@ module Synvert::Core
|
|
153
153
|
if !@affected_files.empty? && @redo_until_no_change # redo
|
154
154
|
test
|
155
155
|
end
|
156
|
-
@test_results
|
156
|
+
@test_results.map do |filename, test_results|
|
157
|
+
new_actions = test_results.map(&:actions).flatten.sort_by(&:end)
|
158
|
+
last_start = -1
|
159
|
+
conflicted = new_actions.any? do |action|
|
160
|
+
if last_start > action.end
|
161
|
+
true
|
162
|
+
else
|
163
|
+
last_start = action.start
|
164
|
+
false
|
165
|
+
end
|
166
|
+
end
|
167
|
+
result = NodeMutation::Result.new(affected: true, conflicted: conflicted)
|
168
|
+
result.actions = new_actions
|
169
|
+
result.file_path = filename
|
170
|
+
result
|
171
|
+
end
|
157
172
|
end
|
158
173
|
|
159
174
|
# Add a warning.
|
@@ -287,7 +302,7 @@ module Synvert::Core
|
|
287
302
|
result = NodeMutation::Result.new(affected: true, conflicted: false)
|
288
303
|
result.actions = [NodeMutation::Struct::Action.new(:add_file, 0, 0, content)]
|
289
304
|
result.file_path = filename
|
290
|
-
|
305
|
+
merge_test_result(result)
|
291
306
|
return
|
292
307
|
end
|
293
308
|
|
@@ -314,7 +329,7 @@ module Synvert::Core
|
|
314
329
|
result = NodeMutation::Result.new(affected: true, conflicted: false)
|
315
330
|
result.actions = [NodeMutation::Struct::Action.new(:remove_file, 0, -1)]
|
316
331
|
result.file_path = filename
|
317
|
-
|
332
|
+
merge_test_result(result)
|
318
333
|
return
|
319
334
|
end
|
320
335
|
|
@@ -430,7 +445,13 @@ module Synvert::Core
|
|
430
445
|
end
|
431
446
|
|
432
447
|
def merge_test_results(results)
|
433
|
-
|
448
|
+
results.compact.select(&:affected?).each do |result|
|
449
|
+
merge_test_result(result)
|
450
|
+
end
|
451
|
+
end
|
452
|
+
|
453
|
+
def merge_test_result(result)
|
454
|
+
@test_results[result.file_path] << result
|
434
455
|
end
|
435
456
|
end
|
436
457
|
end
|
data/lib/synvert/core/version.rb
CHANGED
data/lib/synvert/core.rb
CHANGED
data/synvert-core-ruby.gemspec
CHANGED
@@ -20,8 +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 "node_query", ">= 1.13.
|
24
|
-
spec.add_runtime_dependency "node_mutation", ">= 1.
|
23
|
+
spec.add_runtime_dependency "node_query", ">= 1.13.9"
|
24
|
+
spec.add_runtime_dependency "node_mutation", ">= 1.19.3"
|
25
25
|
spec.add_runtime_dependency "parser"
|
26
26
|
spec.add_runtime_dependency "parser_node_ext", ">= 1.2.0"
|
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.28.
|
4
|
+
version: 1.28.4
|
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-
|
11
|
+
date: 2023-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -30,28 +30,28 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.13.
|
33
|
+
version: 1.13.9
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.13.
|
40
|
+
version: 1.13.9
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: node_mutation
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 1.
|
47
|
+
version: 1.19.3
|
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.19.3
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: parser
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -149,7 +149,6 @@ files:
|
|
149
149
|
- lib/synvert/core/engine/slim.rb
|
150
150
|
- lib/synvert/core/errors.rb
|
151
151
|
- lib/synvert/core/helper.rb
|
152
|
-
- lib/synvert/core/node_ext.rb
|
153
152
|
- lib/synvert/core/rewriter.rb
|
154
153
|
- lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb
|
155
154
|
- lib/synvert/core/rewriter/condition.rb
|
@@ -173,7 +172,6 @@ files:
|
|
173
172
|
- spec/synvert/core/engine/haml_spec.rb
|
174
173
|
- spec/synvert/core/engine/slim_spec.rb
|
175
174
|
- spec/synvert/core/helper_spec.rb
|
176
|
-
- spec/synvert/core/node_ext_spec.rb
|
177
175
|
- spec/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action_spec.rb
|
178
176
|
- spec/synvert/core/rewriter/condition/if_exist_condition_spec.rb
|
179
177
|
- spec/synvert/core/rewriter/condition/if_only_exist_condition_spec.rb
|
@@ -209,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
209
207
|
- !ruby/object:Gem::Version
|
210
208
|
version: '0'
|
211
209
|
requirements: []
|
212
|
-
rubygems_version: 3.4.
|
210
|
+
rubygems_version: 3.4.18
|
213
211
|
signing_key:
|
214
212
|
specification_version: 4
|
215
213
|
summary: convert ruby code to better syntax.
|
@@ -220,7 +218,6 @@ test_files:
|
|
220
218
|
- spec/synvert/core/engine/haml_spec.rb
|
221
219
|
- spec/synvert/core/engine/slim_spec.rb
|
222
220
|
- spec/synvert/core/helper_spec.rb
|
223
|
-
- spec/synvert/core/node_ext_spec.rb
|
224
221
|
- spec/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action_spec.rb
|
225
222
|
- spec/synvert/core/rewriter/condition/if_exist_condition_spec.rb
|
226
223
|
- spec/synvert/core/rewriter/condition/if_only_exist_condition_spec.rb
|
@@ -1,130 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'parser'
|
4
|
-
|
5
|
-
module Parser::AST
|
6
|
-
# Extend Parser::AST::Node.
|
7
|
-
# {https://github.com/whitequark/parser/blob/master/lib/parser/ast/node.rb}
|
8
|
-
#
|
9
|
-
# Rules
|
10
|
-
#
|
11
|
-
# Synvert compares ast nodes with key / value pairs, each ast node has
|
12
|
-
# multiple attributes, e.g. +receiver+, +message+ and +arguments+, it
|
13
|
-
# matches only when all of key / value pairs match.
|
14
|
-
#
|
15
|
-
# +type: 'send', message: :include, arguments: ['FactoryGirl::Syntax::Methods']+
|
16
|
-
#
|
17
|
-
# Synvert does comparison based on the value type
|
18
|
-
#
|
19
|
-
# 1. if value is a symbol, then compares ast node value as symbol, e.g. +message: :include+
|
20
|
-
# 2. if value is a string, then compares ast node original source code, e.g. +name: 'Synvert::Application'+
|
21
|
-
# 3. if value is a regexp, then compares ast node original source code, e.g. +message: /find_all_by_/+
|
22
|
-
# 4. if value is an array, then compares each ast node, e.g. +arguments: ['FactoryGirl::Syntax::Methods']+
|
23
|
-
# 5. if value is nil, then check if ast node is nil, e.g. +arguments: [nil]+
|
24
|
-
# 6. if value is true or false, then check if ast node is :true or :false, e.g. +arguments: [false]+
|
25
|
-
# 7. if value is ast, then compare ast node directly, e.g. +to_ast: Parser::CurrentRuby.parse("self.class.serialized_attributes")+
|
26
|
-
#
|
27
|
-
# It can also compare nested key / value pairs, like
|
28
|
-
#
|
29
|
-
# +type: 'send', receiver: { type: 'send', receiver: { type: 'send', message: 'config' }, message: 'active_record' }, message: 'identity_map='+
|
30
|
-
#
|
31
|
-
# Source Code to Ast Node
|
32
|
-
# {https://playground.synvert.net/ruby}
|
33
|
-
class Node
|
34
|
-
# Get the file name of node.
|
35
|
-
#
|
36
|
-
# @return [String] file name.
|
37
|
-
def filename
|
38
|
-
loc.expression&.source_buffer.name
|
39
|
-
end
|
40
|
-
|
41
|
-
# Get the column of node.
|
42
|
-
#
|
43
|
-
# @return [Integer] column.
|
44
|
-
def column
|
45
|
-
loc.expression.column
|
46
|
-
end
|
47
|
-
|
48
|
-
# Get the line of node.
|
49
|
-
#
|
50
|
-
# @return [Integer] line.
|
51
|
-
def line
|
52
|
-
loc.expression.line
|
53
|
-
end
|
54
|
-
|
55
|
-
# Strip curly braces for hash.
|
56
|
-
# @example
|
57
|
-
# node # s(:hash, s(:pair, s(:sym, :foo), s(:str, "bar")))
|
58
|
-
# node.strip_curly_braces # "foo: 'bar'"
|
59
|
-
# @return [String]
|
60
|
-
def strip_curly_braces
|
61
|
-
return to_source unless type == :hash
|
62
|
-
|
63
|
-
to_source.sub(/^{(.*)}$/) { Regexp.last_match(1).strip }
|
64
|
-
end
|
65
|
-
|
66
|
-
# Wrap curly braces for hash.
|
67
|
-
# @example
|
68
|
-
# node # s(:hash, s(:pair, s(:sym, :foo), s(:str, "bar")))
|
69
|
-
# node.wrap_curly_braces # "{ foo: 'bar' }"
|
70
|
-
# @return [String]
|
71
|
-
def wrap_curly_braces
|
72
|
-
return to_source unless type == :hash
|
73
|
-
|
74
|
-
"{ #{to_source} }"
|
75
|
-
end
|
76
|
-
|
77
|
-
# Get single quote string.
|
78
|
-
# @example
|
79
|
-
# node # s(:str, "foobar")
|
80
|
-
# node.to_single_quote # "'foobar'"
|
81
|
-
# @return [String]
|
82
|
-
def to_single_quote
|
83
|
-
return to_source unless type == :str
|
84
|
-
|
85
|
-
"'#{to_value}'"
|
86
|
-
end
|
87
|
-
|
88
|
-
# Convert string to symbol.
|
89
|
-
# @example
|
90
|
-
# node # s(:str, "foobar")
|
91
|
-
# node.to_symbol # ":foobar"
|
92
|
-
# @return [String]
|
93
|
-
def to_symbol
|
94
|
-
return to_source unless type == :str
|
95
|
-
|
96
|
-
":#{to_value}"
|
97
|
-
end
|
98
|
-
|
99
|
-
# Convert symbol to string.
|
100
|
-
# @example
|
101
|
-
# node # s(:sym, :foobar)
|
102
|
-
# node.to_string # "foobar"
|
103
|
-
# @return [String]
|
104
|
-
def to_string
|
105
|
-
return to_source unless type == :sym
|
106
|
-
|
107
|
-
to_value.to_s
|
108
|
-
end
|
109
|
-
|
110
|
-
# Convert lambda {} to -> {}
|
111
|
-
# @example
|
112
|
-
# node # s(:block, s(:send, nil, :lambda), s(:args), s(:send, nil, :foobar))
|
113
|
-
# node.to_lambda_literal # "-> { foobar }"
|
114
|
-
# @return [String]
|
115
|
-
def to_lambda_literal
|
116
|
-
if type == :block && caller.type == :send && caller.receiver.nil? && caller.message == :lambda
|
117
|
-
new_source = to_source
|
118
|
-
if arguments.size > 1
|
119
|
-
new_source = new_source[0...arguments.first.loc.expression.begin_pos - 2] + new_source[arguments.last.loc.expression.end_pos + 1..-1]
|
120
|
-
new_source = new_source.sub('lambda', "->(#{arguments.map(&:to_source).join(', ')})")
|
121
|
-
else
|
122
|
-
new_source = new_source.sub('lambda', '->')
|
123
|
-
end
|
124
|
-
new_source
|
125
|
-
else
|
126
|
-
to_source
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
@@ -1,108 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Parser::AST::Node do
|
6
|
-
describe '#strip_curly_braces' do
|
7
|
-
context 'hash node' do
|
8
|
-
it 'removes curly braces' do
|
9
|
-
node = parser_parse("{ foo: 'bar' }")
|
10
|
-
expect(node.strip_curly_braces).to eq("foo: 'bar'")
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
context 'other node' do
|
15
|
-
it 'do nothing' do
|
16
|
-
node = parser_parse("'foobar'")
|
17
|
-
expect(node.strip_curly_braces).to eq("'foobar'")
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe '#wrap_curly_braces' do
|
23
|
-
context 'hash node' do
|
24
|
-
it 'adds curly braces' do
|
25
|
-
node = parser_parse("test(foo: 'bar')").arguments.first
|
26
|
-
expect(node.to_source).to eq("foo: 'bar'")
|
27
|
-
expect(node.wrap_curly_braces).to eq("{ foo: 'bar' }")
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'other node' do
|
32
|
-
it 'does nothing' do
|
33
|
-
node = parser_parse("'foobar'")
|
34
|
-
expect(node.wrap_curly_braces).to eq("'foobar'")
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe '#to_single_quote' do
|
40
|
-
context 'str node' do
|
41
|
-
it 'converts double quote to single quote' do
|
42
|
-
node = parser_parse('"foobar"')
|
43
|
-
expect(node.to_source).to eq '"foobar"'
|
44
|
-
expect(node.to_single_quote).to eq "'foobar'"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context 'other node' do
|
49
|
-
it 'does nothing' do
|
50
|
-
node = parser_parse(':foobar')
|
51
|
-
expect(node.to_single_quote).to eq ':foobar'
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe '#to_symbol' do
|
57
|
-
context 'str node' do
|
58
|
-
it 'converts string to symbol' do
|
59
|
-
node = parser_parse("'foobar'")
|
60
|
-
expect(node.to_symbol).to eq ':foobar'
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
context 'other node' do
|
65
|
-
it 'does nothing' do
|
66
|
-
node = parser_parse(':foobar')
|
67
|
-
expect(node.to_symbol).to eq ':foobar'
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
describe '#to_string' do
|
73
|
-
context 'sym node' do
|
74
|
-
it 'converts symbol to string' do
|
75
|
-
node = parser_parse(':foobar')
|
76
|
-
expect(node.to_string).to eq 'foobar'
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
context 'other node' do
|
81
|
-
it 'does nothing' do
|
82
|
-
node = parser_parse("'foobar'")
|
83
|
-
expect(node.to_string).to eq "'foobar'"
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
describe '#to_lambda_literal' do
|
89
|
-
context 'lambda node' do
|
90
|
-
it 'converts to lambda literal without arguments' do
|
91
|
-
node = parser_parse('lambda { foobar }')
|
92
|
-
expect(node.to_lambda_literal).to eq('-> { foobar }')
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'converts to lambda literal with arguments' do
|
96
|
-
node = parser_parse('lambda { |x, y| foobar }')
|
97
|
-
expect(node.to_lambda_literal).to eq('->(x, y) { foobar }')
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
context 'other node' do
|
102
|
-
it 'does nothing' do
|
103
|
-
node = parser_parse(':foobar')
|
104
|
-
expect(node.to_lambda_literal).to eq ':foobar'
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|