synvert-core 1.34.0 → 1.35.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 +10 -10
- data/README.md +46 -46
- data/lib/synvert/core/rewriter/instance.rb +2 -17
- data/lib/synvert/core/rewriter.rb +3 -4
- data/lib/synvert/core/utils.rb +1 -1
- data/lib/synvert/core/version.rb +1 -1
- data/spec/synvert/core/rewriter/instance_spec.rb +0 -10
- data/spec/synvert/core/utils_spec.rb +1 -1
- data/synvert-core-ruby.gemspec +2 -2
- metadata +5 -8
- data/lib/synvert/core/rewriter/condition/if_only_exist_condition.rb +0 -15
- data/spec/synvert/core/rewriter/condition/if_only_exist_condition_spec.rb +0 -47
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 73d980abab80a00253b41153d665ee2036c4111d8c68fad0884e767e121f20a9
|
|
4
|
+
data.tar.gz: 3f83634246155bc0be00a09ff1ba4c43e31160e9b9ce8337e3c20f39b40392f1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c28dc61a913dfe6b7f65ac76cad9eed4ff71c83b09c5ae26901bb8333707a00d050062f2bdc60ceec32f0a9dafbc6f5bd9a49af687781e1f815a469abb8fe5c0
|
|
7
|
+
data.tar.gz: 3a126aa7dfca96796d8b07aeb666630cf30b12252e3f08f6e5f98b09e998634db0b9f708029ffc975348ca1b713e1e03f317a5740498be2fa6121c20b347f92d
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 1.35.0 (2024-04-07)
|
|
4
|
+
|
|
5
|
+
* Update `prism_ext` to 0.3.0
|
|
6
|
+
* Update `syntax_tree_ext` to 0.8.1
|
|
7
|
+
* Update `parser_node_ext` to 1.3.0
|
|
8
|
+
* Update `node_query` to 1.15.2
|
|
9
|
+
* Update `node_mutation` to 1.24.3
|
|
10
|
+
* Remove `if_only_exist_node` dsl
|
|
11
|
+
|
|
3
12
|
## 1.34.0 (2024-02-29)
|
|
4
13
|
|
|
5
14
|
* Add `with_configurations` dsl
|
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.35.0)
|
|
5
5
|
activesupport (< 7.0.0)
|
|
6
|
-
node_mutation (>= 1.
|
|
6
|
+
node_mutation (>= 1.24.1)
|
|
7
7
|
node_query (>= 1.15.1)
|
|
8
8
|
parallel
|
|
9
9
|
parser
|
|
@@ -43,17 +43,17 @@ GEM
|
|
|
43
43
|
guard (~> 2.1)
|
|
44
44
|
guard-compat (~> 1.1)
|
|
45
45
|
rspec (>= 2.99.0, < 4.0)
|
|
46
|
-
i18n (1.14.
|
|
46
|
+
i18n (1.14.4)
|
|
47
47
|
concurrent-ruby (~> 1.0)
|
|
48
48
|
listen (3.7.1)
|
|
49
49
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
|
50
50
|
rb-inotify (~> 0.9, >= 0.9.10)
|
|
51
51
|
lumberjack (1.2.8)
|
|
52
52
|
method_source (1.0.0)
|
|
53
|
-
minitest (5.22.
|
|
53
|
+
minitest (5.22.3)
|
|
54
54
|
nenv (0.3.0)
|
|
55
|
-
node_mutation (1.
|
|
56
|
-
node_query (1.15.
|
|
55
|
+
node_mutation (1.24.3)
|
|
56
|
+
node_query (1.15.2)
|
|
57
57
|
notiffany (0.1.3)
|
|
58
58
|
nenv (~> 0.1)
|
|
59
59
|
shellany (~> 0.0)
|
|
@@ -61,11 +61,11 @@ GEM
|
|
|
61
61
|
parser (3.3.0.5)
|
|
62
62
|
ast (~> 2.4.1)
|
|
63
63
|
racc
|
|
64
|
-
parser_node_ext (1.
|
|
64
|
+
parser_node_ext (1.3.0)
|
|
65
65
|
parser
|
|
66
66
|
prettier_print (1.2.1)
|
|
67
|
-
prism (0.
|
|
68
|
-
prism_ext (0.
|
|
67
|
+
prism (0.25.0)
|
|
68
|
+
prism_ext (0.3.0)
|
|
69
69
|
prism
|
|
70
70
|
pry (0.14.1)
|
|
71
71
|
coderay (~> 1.1)
|
|
@@ -91,7 +91,7 @@ GEM
|
|
|
91
91
|
shellany (0.0.1)
|
|
92
92
|
syntax_tree (6.2.0)
|
|
93
93
|
prettier_print (>= 1.2.0)
|
|
94
|
-
syntax_tree_ext (0.
|
|
94
|
+
syntax_tree_ext (0.8.1)
|
|
95
95
|
syntax_tree
|
|
96
96
|
thor (1.2.1)
|
|
97
97
|
tzinfo (2.0.6)
|
data/README.md
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
<img src="https://synvert.net/img/logo_96.png" alt="logo" width="32" height="32" />
|
|
4
4
|
|
|
5
|
-
[](https://awesomecode.io/repos/synvert-hq/synvert-core-ruby)
|
|
6
|
+
[](https://github.com/synvert-hq/synvert-core-ruby/actions/workflows/main.yml)
|
|
7
|
+
[](https://rubygems.org/gems/synvert-core)
|
|
7
8
|
|
|
8
9
|
Synvert core provides a set of DSLs to rewrite ruby code. e.g.
|
|
9
10
|
|
|
@@ -53,67 +54,66 @@ Synvert::Rewriter.new 'factory_bot', 'convert_factory_girl_to_factory_bot' do
|
|
|
53
54
|
end
|
|
54
55
|
```
|
|
55
56
|
|
|
56
|
-
Want to see more examples, check out [synvert-snippets-ruby](https://github.com/
|
|
57
|
+
Want to see more examples, check out [synvert-snippets-ruby](https://github.com/synvert-hq/synvert-snippets-ruby).
|
|
57
58
|
|
|
58
|
-
Want to use the CLI, check out [synvert-ruby](https://github.com/
|
|
59
|
+
Want to use the CLI, check out [synvert-ruby](https://github.com/synvert-hq/synvert-ruby).
|
|
59
60
|
|
|
60
61
|
DSLs are as follows
|
|
61
62
|
|
|
62
|
-
* [configure](https://
|
|
63
|
-
* [description](https://
|
|
64
|
-
* [if_ruby](https://
|
|
65
|
-
* [if_gem](https://
|
|
66
|
-
* [within_files](https://
|
|
67
|
-
* [within_file](https://
|
|
68
|
-
* [add_file](https://
|
|
69
|
-
* [remove_file](https://
|
|
70
|
-
* [helper_method](https://
|
|
71
|
-
* [add_snippet](https://
|
|
72
|
-
* [call_helper](https://
|
|
73
|
-
* [with_configurations](https://
|
|
74
|
-
* [save_data](https://
|
|
75
|
-
* [load_data](https://
|
|
63
|
+
* [configure](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#configure-instance_method) - configure the rewriter
|
|
64
|
+
* [description](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#description-instance_method) - describe what the rewriter does
|
|
65
|
+
* [if_ruby](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#if_ruby-instance_method) - check if ruby version is greater than or equal to the specified ruby version
|
|
66
|
+
* [if_gem](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#if_gem-instance_method) - compare version of specified gem
|
|
67
|
+
* [within_files](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#within_files-instance_method) - find specified files
|
|
68
|
+
* [within_file](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#within_file-instance_method) - alias to within_files
|
|
69
|
+
* [add_file](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#add_file-instance_method) - add a new file
|
|
70
|
+
* [remove_file](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#remove_file-instance_method) - remove a file
|
|
71
|
+
* [helper_method](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#helper_method-instance_method) - define a helper method
|
|
72
|
+
* [add_snippet](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#add_snippet-instance_method) - call another rewriter
|
|
73
|
+
* [call_helper](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#call_helper-instance_method) - call a shared rewriter
|
|
74
|
+
* [with_configurations](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#with_configurations-instance_method) - execute a block of code with temporary configurations
|
|
75
|
+
* [save_data](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#save_data-instance_method) - save data
|
|
76
|
+
* [load_data](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#load_data-instance_method) - load data
|
|
76
77
|
|
|
77
78
|
Scopes:
|
|
78
79
|
|
|
79
|
-
* [within_node](https://
|
|
80
|
-
* [with_node](https://
|
|
81
|
-
* [find_node](https://
|
|
82
|
-
* [goto_node](https://
|
|
80
|
+
* [within_node](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#within_node-instance_method) - recursively find matching ast nodes
|
|
81
|
+
* [with_node](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#with_node-instance_method) - alias to within_node
|
|
82
|
+
* [find_node](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#find_node-instance_method) - alias to within_node
|
|
83
|
+
* [goto_node](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#goto_node-instance_method) - go to a child node
|
|
83
84
|
|
|
84
85
|
Conditions:
|
|
85
86
|
|
|
86
|
-
* [if_exist_node](https://
|
|
87
|
-
* [unless_exist_node](https://
|
|
88
|
-
* [if_only_exist_node](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#if_only_exist_node-instance_method) - check if current node has only one child node and the child node matches
|
|
87
|
+
* [if_exist_node](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#if_exist_node-instance_method) - check if matching node exist in the child nodes
|
|
88
|
+
* [unless_exist_node](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#unless_exist_node-instance_method) - check if matching node doesn't exist in the child nodes
|
|
89
89
|
|
|
90
90
|
Actions:
|
|
91
91
|
|
|
92
|
-
* [append](https://
|
|
93
|
-
* [prepend](https://
|
|
94
|
-
* [indent](https://
|
|
95
|
-
* [insert](https://
|
|
96
|
-
* [insert_after](https://
|
|
97
|
-
* [insert_before](https://
|
|
98
|
-
* [replace](https://
|
|
99
|
-
* [delete](https://
|
|
100
|
-
* [remove](https://
|
|
101
|
-
* [wrap](https://
|
|
102
|
-
* [replace_with](https://
|
|
103
|
-
* [warn](https://
|
|
104
|
-
* [replace_erb_stmt_with_expr](https://
|
|
105
|
-
* [noop](https://
|
|
106
|
-
* [group](https://
|
|
107
|
-
* [add_action](https://
|
|
92
|
+
* [append](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#append-instance_method) - append the code to the bottom of current node body
|
|
93
|
+
* [prepend](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#prepend-instance_method) - prepend the code to the bottom of current node body
|
|
94
|
+
* [indent](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#indent-instance_method) - indent code
|
|
95
|
+
* [insert](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#insert-instance_method) - insert code
|
|
96
|
+
* [insert_after](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#insert_after-instance_method) - insert the code next to the current node
|
|
97
|
+
* [insert_before](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#insert_before-instance_method) - insert the code previous to the current node
|
|
98
|
+
* [replace](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#replace-instance_method) - replace the code of specified child nodes
|
|
99
|
+
* [delete](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#delete-instance_method) - delete the code in specified child nodes
|
|
100
|
+
* [remove](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#remove-instance_method) - remove the whole code of current node
|
|
101
|
+
* [wrap](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#wrap-instance_method) - wrap the current node with prefix and suffix code
|
|
102
|
+
* [replace_with](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#replace_with-instance_method) - replace the whole code of current node
|
|
103
|
+
* [warn](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#warn-instance_method) - warn message
|
|
104
|
+
* [replace_erb_stmt_with_expr](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#replace_erb_stmt_with_expr-instance_method) - replace erb stmt code to expr code
|
|
105
|
+
* [noop](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#noop-instance_method) - no operation
|
|
106
|
+
* [group](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#group-instance_method) - group actions
|
|
107
|
+
* [add_action](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#add_action-instance_method) - add custom action
|
|
108
108
|
|
|
109
109
|
Others:
|
|
110
110
|
|
|
111
|
-
* [wrap_with_quotes](https://
|
|
112
|
-
* [add_leading_spaces](https://
|
|
111
|
+
* [wrap_with_quotes](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#wrap_with_quotes-instance_method) - wrap string code with single or doulbe quotes
|
|
112
|
+
* [add_leading_spaces](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#add_leading_spaces-instance_method) - add leading spaces before the string code
|
|
113
113
|
|
|
114
114
|
|
|
115
115
|
Attributes:
|
|
116
116
|
|
|
117
|
-
* [file_path](https://
|
|
118
|
-
* [node](https://
|
|
119
|
-
* [mutation_adapter](https://
|
|
117
|
+
* [file_path](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#file_path-instance_method) - current file path
|
|
118
|
+
* [node](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#node-instance_method) - current ast node
|
|
119
|
+
* [mutation_adapter](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#mutation_adapter-instance_method) - [mutation adapter](https://synvert-hq.github.io/node-mutation-ruby/NodeMutation/Adapter.html) to get some helper methods
|
|
@@ -48,8 +48,8 @@ module Synvert::Core
|
|
|
48
48
|
|
|
49
49
|
absolute_file_path = File.join(Configuration.root_path, @file_path)
|
|
50
50
|
# It keeps running until no conflict,
|
|
51
|
-
# it will try
|
|
52
|
-
|
|
51
|
+
# it will try 5 times at maximum.
|
|
52
|
+
5.times do
|
|
53
53
|
source = read_source(absolute_file_path)
|
|
54
54
|
encoded_source = Engine.encode(File.extname(file_path), source)
|
|
55
55
|
@current_mutation = NodeMutation.new(source, adapter: @rewriter.parser)
|
|
@@ -216,21 +216,6 @@ module Synvert::Core
|
|
|
216
216
|
Rewriter::UnlessExistCondition.new(self, nql_or_rules, &block).process
|
|
217
217
|
end
|
|
218
218
|
|
|
219
|
-
# It creates a {Synvert::Core::Rewriter::IfOnlyExistCondition} to check
|
|
220
|
-
# if current node has only one child node and the child node matches,
|
|
221
|
-
# if so, then continue operating on each matching ast node.
|
|
222
|
-
# @example
|
|
223
|
-
# # it { should matcher }
|
|
224
|
-
# with_node type: 'block', caller: { message: 'it' } do
|
|
225
|
-
# if_only_exist_node type: 'send', receiver: nil, message: 'should' do
|
|
226
|
-
# end
|
|
227
|
-
# end
|
|
228
|
-
# @param nql_or_rules [String|Hash] nql or rules to check mathing ast nodes.
|
|
229
|
-
# @param block [Block] block code to continue operating on the matching nodes.
|
|
230
|
-
def if_only_exist_node(nql_or_rules, &block)
|
|
231
|
-
Rewriter::IfOnlyExistCondition.new(self, nql_or_rules, &block).process
|
|
232
|
-
end
|
|
233
|
-
|
|
234
219
|
# It appends the code to the bottom of current node body.
|
|
235
220
|
# @example
|
|
236
221
|
# # def teardown
|
|
@@ -24,7 +24,6 @@ module Synvert::Core
|
|
|
24
24
|
autoload :Condition, 'synvert/core/rewriter/condition'
|
|
25
25
|
autoload :IfExistCondition, 'synvert/core/rewriter/condition/if_exist_condition'
|
|
26
26
|
autoload :UnlessExistCondition, 'synvert/core/rewriter/condition/unless_exist_condition'
|
|
27
|
-
autoload :IfOnlyExistCondition, 'synvert/core/rewriter/condition/if_only_exist_condition'
|
|
28
27
|
|
|
29
28
|
autoload :Helper, 'synvert/core/rewriter/helper'
|
|
30
29
|
|
|
@@ -346,8 +345,8 @@ module Synvert::Core
|
|
|
346
345
|
# add_snippet 'minitest/assert_kind_of'
|
|
347
346
|
# add_snippet '/Users/flyerhzm/.synvert-ruby/lib/minitest/assert_match.rb'
|
|
348
347
|
# add_snippet '/Users/flyerhzm/.synvert-ruby/lib/minitest/assert_nil.rb'
|
|
349
|
-
# add_snippet 'https://github.com/
|
|
350
|
-
# add_snippet 'https://github.com/
|
|
348
|
+
# add_snippet 'https://github.com/synvert-hq/synvert-snippets-ruby/blob/main/lib/minitest/assert_silent.rb'
|
|
349
|
+
# add_snippet 'https://github.com/synvert-hq/synvert-snippets-ruby/blob/main/lib/minitest/assert_truthy.rb'
|
|
351
350
|
# end
|
|
352
351
|
# @param group [String] group of another rewriter, if there's no name parameter, the group can be http url, file path or snippet name.
|
|
353
352
|
# @param name [String] name of another rewriter.
|
|
@@ -379,7 +378,7 @@ module Synvert::Core
|
|
|
379
378
|
# Synvert::Rewriter.new 'rails', 'upgrade_6_0_to_6_1' do
|
|
380
379
|
# call_helper 'rails/set_load_defaults', rails_version: '6.1'
|
|
381
380
|
# add_snippet '/Users/flyerhzm/.synvert-ruby/lib/rails/set_load_defaults.rb', rails_version: '6.1'
|
|
382
|
-
# add_snippet 'https://github.com/
|
|
381
|
+
# add_snippet 'https://github.com/synvert-hq/synvert-snippets-ruby/blob/main/lib/rails/set_load_defaults.rb', rails_version: '6.1'
|
|
383
382
|
# end
|
|
384
383
|
# @param name [String] name of helper.
|
|
385
384
|
# @param options [Hash] options to pass to helper.
|
data/lib/synvert/core/utils.rb
CHANGED
|
@@ -80,7 +80,7 @@ module Synvert::Core
|
|
|
80
80
|
end
|
|
81
81
|
|
|
82
82
|
def remote_snippet_url(snippet_name)
|
|
83
|
-
"https://github.com/
|
|
83
|
+
"https://github.com/synvert-hq/synvert-snippets-ruby/blob/main/lib/#{snippet_name}.rb"
|
|
84
84
|
end
|
|
85
85
|
|
|
86
86
|
def format_url(url)
|
data/lib/synvert/core/version.rb
CHANGED
|
@@ -91,16 +91,6 @@ module Synvert::Core
|
|
|
91
91
|
instance.unless_exist_node(type: 'send', message: 'create', &block)
|
|
92
92
|
end
|
|
93
93
|
|
|
94
|
-
it 'parses if_only_exist_node' do
|
|
95
|
-
condition = double
|
|
96
|
-
block = proc {}
|
|
97
|
-
expect(Rewriter::IfOnlyExistCondition).to receive(:new)
|
|
98
|
-
.with(instance, { type: 'send', message: 'create' }, &block)
|
|
99
|
-
.and_return(condition)
|
|
100
|
-
expect(condition).to receive(:process)
|
|
101
|
-
instance.if_only_exist_node(type: 'send', message: 'create', &block)
|
|
102
|
-
end
|
|
103
|
-
|
|
104
94
|
it 'parses append' do
|
|
105
95
|
instance.instance_variable_set(:@current_mutation, double)
|
|
106
96
|
instance.current_node = double
|
|
@@ -45,7 +45,7 @@ module Synvert::Core
|
|
|
45
45
|
expect(File).to receive(:exist?).with("group/name").and_return(false)
|
|
46
46
|
expect(described_class).to receive(:default_snippets_home).and_return('/home/richard/.synvert-ruby')
|
|
47
47
|
expect(File).to receive(:exist?).with("/home/richard/.synvert-ruby/lib/group/name.rb").and_return(false)
|
|
48
|
-
expect(described_class).to receive(:remote_snippet_exists?).with(URI.parse("https://raw.githubusercontent.com/
|
|
48
|
+
expect(described_class).to receive(:remote_snippet_exists?).with(URI.parse("https://raw.githubusercontent.com/synvert-hq/synvert-snippets-ruby/main/lib/group/name.rb")).and_return(true)
|
|
49
49
|
expect_any_instance_of(URI::HTTP).to receive(:open).and_return(StringIO.new("Rewriter.new 'group', 'name' do\nend"))
|
|
50
50
|
rewriter = described_class.eval_snippet('group/name')
|
|
51
51
|
expect(rewriter.group).to eq 'group'
|
data/synvert-core-ruby.gemspec
CHANGED
|
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
|
11
11
|
spec.email = ["flyerhzm@gmail.com"]
|
|
12
12
|
spec.summary = 'convert ruby code to better syntax.'
|
|
13
13
|
spec.description = 'convert ruby code to better syntax automatically.'
|
|
14
|
-
spec.homepage = "https://github.com/
|
|
14
|
+
spec.homepage = "https://github.com/synvert-hq/synvert-core-ruby"
|
|
15
15
|
spec.license = "MIT"
|
|
16
16
|
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0")
|
|
@@ -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.15.1"
|
|
24
|
-
spec.add_runtime_dependency "node_mutation", ">= 1.
|
|
24
|
+
spec.add_runtime_dependency "node_mutation", ">= 1.24.1"
|
|
25
25
|
spec.add_runtime_dependency "parser"
|
|
26
26
|
spec.add_runtime_dependency "parser_node_ext", ">= 1.2.2"
|
|
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.35.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-
|
|
11
|
+
date: 2024-04-07 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.24.1
|
|
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.24.1
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
56
56
|
name: parser
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -181,7 +181,6 @@ files:
|
|
|
181
181
|
- lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb
|
|
182
182
|
- lib/synvert/core/rewriter/condition.rb
|
|
183
183
|
- lib/synvert/core/rewriter/condition/if_exist_condition.rb
|
|
184
|
-
- lib/synvert/core/rewriter/condition/if_only_exist_condition.rb
|
|
185
184
|
- lib/synvert/core/rewriter/condition/unless_exist_condition.rb
|
|
186
185
|
- lib/synvert/core/rewriter/gem_spec.rb
|
|
187
186
|
- lib/synvert/core/rewriter/helper.rb
|
|
@@ -203,7 +202,6 @@ files:
|
|
|
203
202
|
- spec/synvert/core/helper_spec.rb
|
|
204
203
|
- spec/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action_spec.rb
|
|
205
204
|
- spec/synvert/core/rewriter/condition/if_exist_condition_spec.rb
|
|
206
|
-
- spec/synvert/core/rewriter/condition/if_only_exist_condition_spec.rb
|
|
207
205
|
- spec/synvert/core/rewriter/condition/unless_exist_condition_spec.rb
|
|
208
206
|
- spec/synvert/core/rewriter/condition_spec.rb
|
|
209
207
|
- spec/synvert/core/rewriter/gem_spec_spec.rb
|
|
@@ -217,7 +215,7 @@ files:
|
|
|
217
215
|
- spec/synvert/core/rewriter_spec.rb
|
|
218
216
|
- spec/synvert/core/utils_spec.rb
|
|
219
217
|
- synvert-core-ruby.gemspec
|
|
220
|
-
homepage: https://github.com/
|
|
218
|
+
homepage: https://github.com/synvert-hq/synvert-core-ruby
|
|
221
219
|
licenses:
|
|
222
220
|
- MIT
|
|
223
221
|
metadata: {}
|
|
@@ -250,7 +248,6 @@ test_files:
|
|
|
250
248
|
- spec/synvert/core/helper_spec.rb
|
|
251
249
|
- spec/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action_spec.rb
|
|
252
250
|
- spec/synvert/core/rewriter/condition/if_exist_condition_spec.rb
|
|
253
|
-
- spec/synvert/core/rewriter/condition/if_only_exist_condition_spec.rb
|
|
254
251
|
- spec/synvert/core/rewriter/condition/unless_exist_condition_spec.rb
|
|
255
252
|
- spec/synvert/core/rewriter/condition_spec.rb
|
|
256
253
|
- spec/synvert/core/rewriter/gem_spec_spec.rb
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Synvert::Core
|
|
4
|
-
# IfOnlyExistCondition checks if node has only one child node and the child node matches.
|
|
5
|
-
class Rewriter::IfOnlyExistCondition < Rewriter::Condition
|
|
6
|
-
private
|
|
7
|
-
|
|
8
|
-
# check if only have one child node and the child node matches.
|
|
9
|
-
#
|
|
10
|
-
# @return [Boolean]
|
|
11
|
-
def match?
|
|
12
|
-
target_node.body.size == 1 && @node_query.match_node?(target_node.body.first)
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
|
|
5
|
-
module Synvert::Core
|
|
6
|
-
describe Rewriter::IfOnlyExistCondition do
|
|
7
|
-
let(:source) { <<~EOS }
|
|
8
|
-
RSpec.configure do |config|
|
|
9
|
-
config.include EmailSpec::Helpers
|
|
10
|
-
config.include EmailSpec::Methods
|
|
11
|
-
end
|
|
12
|
-
EOS
|
|
13
|
-
let(:node) { Parser::CurrentRuby.parse(source) }
|
|
14
|
-
let(:instance) { double(current_node: node, parser: :parser) }
|
|
15
|
-
|
|
16
|
-
describe '#process' do
|
|
17
|
-
it 'gets matching nodes' do
|
|
18
|
-
source = ' RSpec.configure do |config| config.include EmailSpec::Helpers end '
|
|
19
|
-
node = Parser::CurrentRuby.parse(source)
|
|
20
|
-
instance = double(current_node: node, parser: :parser)
|
|
21
|
-
run = false
|
|
22
|
-
condition =
|
|
23
|
-
Rewriter::IfOnlyExistCondition.new instance,
|
|
24
|
-
type: 'send',
|
|
25
|
-
message: 'include',
|
|
26
|
-
arguments: ['EmailSpec::Helpers'] do
|
|
27
|
-
run = true
|
|
28
|
-
end
|
|
29
|
-
condition.process
|
|
30
|
-
expect(run).to be_truthy
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it 'not call block if does not match' do
|
|
34
|
-
run = false
|
|
35
|
-
condition =
|
|
36
|
-
Rewriter::IfOnlyExistCondition.new instance,
|
|
37
|
-
type: 'send',
|
|
38
|
-
message: 'include',
|
|
39
|
-
arguments: ['EmailSpec::Helpers'] do
|
|
40
|
-
run = true
|
|
41
|
-
end
|
|
42
|
-
condition.process
|
|
43
|
-
expect(run).to be_falsey
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|