synvert-core 0.14.0 → 0.16.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +12 -0
- data/Gemfile +2 -0
- data/Guardfile +2 -0
- data/Rakefile +2 -0
- data/lib/synvert/core.rb +2 -0
- data/lib/synvert/core/configuration.rb +2 -1
- data/lib/synvert/core/engine.rb +1 -1
- data/lib/synvert/core/engine/erb.rb +2 -1
- data/lib/synvert/core/exceptions.rb +5 -3
- data/lib/synvert/core/node_ext.rb +7 -2
- data/lib/synvert/core/rewriter.rb +1 -1
- data/lib/synvert/core/rewriter/action.rb +2 -2
- data/lib/synvert/core/rewriter/action/append_action.rb +7 -5
- data/lib/synvert/core/rewriter/action/insert_action.rb +13 -18
- data/lib/synvert/core/rewriter/action/insert_after_action.rb +1 -1
- data/lib/synvert/core/rewriter/action/remove_action.rb +1 -1
- data/lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb +1 -1
- data/lib/synvert/core/rewriter/action/replace_with_action.rb +1 -1
- data/lib/synvert/core/rewriter/condition.rb +1 -1
- data/lib/synvert/core/rewriter/condition/if_exist_condition.rb +1 -1
- data/lib/synvert/core/rewriter/condition/if_only_exist_condition.rb +1 -1
- data/lib/synvert/core/rewriter/condition/unless_exist_condition.rb +1 -1
- data/lib/synvert/core/rewriter/gem_spec.rb +1 -1
- data/lib/synvert/core/rewriter/helper.rb +1 -1
- data/lib/synvert/core/rewriter/instance.rb +18 -7
- data/lib/synvert/core/rewriter/ruby_version.rb +1 -1
- data/lib/synvert/core/rewriter/scope.rb +1 -1
- data/lib/synvert/core/rewriter/scope/goto_scope.rb +2 -1
- data/lib/synvert/core/rewriter/scope/within_scope.rb +23 -7
- data/lib/synvert/core/rewriter/warning.rb +1 -1
- data/lib/synvert/core/version.rb +2 -2
- data/spec/spec_helper.rb +2 -0
- data/spec/support/parser_helper.rb +2 -0
- data/spec/synvert/core/configuration_spec.rb +3 -1
- data/spec/synvert/core/engine/erb_spec.rb +2 -0
- data/spec/synvert/core/node_ext_spec.rb +4 -2
- data/spec/synvert/core/rewriter/action/append_action_spec.rb +2 -0
- data/spec/synvert/core/rewriter/action/insert_action_spec.rb +2 -0
- data/spec/synvert/core/rewriter/action/insert_after_action_spec.rb +2 -0
- data/spec/synvert/core/rewriter/action/remove_action_spec.rb +2 -0
- data/spec/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action_spec.rb +2 -0
- data/spec/synvert/core/rewriter/action/replace_with_action_spec.rb +2 -0
- data/spec/synvert/core/rewriter/action_spec.rb +2 -0
- data/spec/synvert/core/rewriter/condition/if_exist_condition_spec.rb +2 -0
- data/spec/synvert/core/rewriter/condition/if_only_exist_condition_spec.rb +2 -0
- data/spec/synvert/core/rewriter/condition/unless_exist_condition_spec.rb +2 -0
- data/spec/synvert/core/rewriter/condition_spec.rb +2 -0
- data/spec/synvert/core/rewriter/gem_spec_spec.rb +2 -0
- data/spec/synvert/core/rewriter/helper_spec.rb +2 -0
- data/spec/synvert/core/rewriter/instance_spec.rb +22 -4
- data/spec/synvert/core/rewriter/scope/goto_scope_spec.rb +2 -0
- data/spec/synvert/core/rewriter/scope/within_scope.rb +2 -0
- data/spec/synvert/core/rewriter/scope_spec.rb +2 -0
- data/spec/synvert/core/rewriter/warning_spec.rb +2 -0
- data/spec/synvert/core/rewriter_spec.rb +7 -5
- data/synvert-core.gemspec +2 -2
- metadata +12 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 327989a145ffc5562768e51cf54f6a86ad2bed0b329c7398eb9499a3fa0f4b07
|
4
|
+
data.tar.gz: d7cb9ca59c8a821329b7063e515a329ab451a83ce80439028af458d9cf745804
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e3afcda5002e5d275faba969dc193e0d8f88781e647ab7fecb44bbbe3b0de383aa74bfad2341b406e148005c4ec7b44fbe941ab884f2a1968d4c81ec1cb9080
|
7
|
+
data.tar.gz: 2b504f8c0a822ae0874e154d45f811b9301bda4c7399bf4c54c365d30bf719367d17a04f0bd41fd77c618c0045901bf70e825301b3811ba023fe0f20bf1c17d5
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
* Abstract `find_matching_nodes`
|
4
|
+
|
5
|
+
## 0.16.0 (2021-01-17)
|
6
|
+
|
7
|
+
* Use parser 3.0.0
|
8
|
+
* Fix magic number
|
9
|
+
* Add `within_direct_node` scope
|
10
|
+
|
11
|
+
## 0.15.0 (2018-05-23)
|
12
|
+
|
13
|
+
* Use parser 2.5.1.1
|
14
|
+
|
3
15
|
## 0.14.0 (2017-05-10)
|
4
16
|
|
5
17
|
* Add helper add_curly_brackets_if_necessary
|
data/Gemfile
CHANGED
data/Guardfile
CHANGED
data/Rakefile
CHANGED
data/lib/synvert/core.rb
CHANGED
data/lib/synvert/core/engine.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Synvert::Core
|
2
4
|
# Rewriter not found exception.
|
3
|
-
class RewriterNotFound <
|
5
|
+
class RewriterNotFound < RuntimeError
|
4
6
|
end
|
5
7
|
|
6
8
|
# Gemfile.lock not found exception.
|
7
|
-
class GemfileLockNotFound <
|
9
|
+
class GemfileLockNotFound < RuntimeError
|
8
10
|
end
|
9
11
|
|
10
12
|
# Method not supported exception.
|
11
|
-
class MethodNotSupported <
|
13
|
+
class MethodNotSupported < RuntimeError
|
12
14
|
end
|
13
15
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Parser::AST
|
2
4
|
# ArgumentsNode allows to handle all args as one node or handle all args as an array.
|
3
5
|
class ArgumentsNode
|
@@ -133,9 +135,11 @@ module Parser::AST
|
|
133
135
|
self.children
|
134
136
|
when :def, :block
|
135
137
|
return [] if self.children[2].nil?
|
138
|
+
|
136
139
|
:begin == self.children[2].type ? self.children[2].body : self.children[2..-1]
|
137
140
|
when :defs
|
138
141
|
return [] if self.children[3].nil?
|
142
|
+
|
139
143
|
:begin == self.children[3].type ? self.children[3].body : self.children[3..-1]
|
140
144
|
else
|
141
145
|
raise Synvert::Core::MethodNotSupported.new "body is not handled for #{self.debug_info}"
|
@@ -234,7 +238,7 @@ module Parser::AST
|
|
234
238
|
# @return [Parser::AST::Node] variable nodes.
|
235
239
|
# @raise [Synvert::Core::MethodNotSupported] if calls on other node.
|
236
240
|
def left_value
|
237
|
-
if [
|
241
|
+
if %i[masgn lvasgn ivasgn].include? self.type
|
238
242
|
self.children[0]
|
239
243
|
else
|
240
244
|
raise Synvert::Core::MethodNotSupported.new "left_value is not handled for #{self.debug_info}"
|
@@ -246,7 +250,7 @@ module Parser::AST
|
|
246
250
|
# @return [Array<Parser::AST::Node>] variable nodes.
|
247
251
|
# @raise [Synvert::Core::MethodNotSupported] if calls on other node.
|
248
252
|
def right_value
|
249
|
-
if [
|
253
|
+
if %i[masgn lvasgn ivasgn].include? self.type
|
250
254
|
self.children[1]
|
251
255
|
else
|
252
256
|
raise Synvert::Core::MethodNotSupported.new "right_value is not handled for #{self.debug_info}"
|
@@ -425,6 +429,7 @@ module Parser::AST
|
|
425
429
|
end
|
426
430
|
when Array
|
427
431
|
return false unless expected.length == actual.length
|
432
|
+
|
428
433
|
actual.zip(expected).all? { |a, e| match_value?(a, e) }
|
429
434
|
when NilClass
|
430
435
|
actual.nil?
|
@@ -1,9 +1,10 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Synvert::Core
|
4
4
|
# Action defines rewriter action, add, replace or remove code.
|
5
5
|
class Rewriter::Action
|
6
6
|
DEFAULT_OPTIONS = { autoindent: true }
|
7
|
+
DEFAULT_INDENT = 2
|
7
8
|
|
8
9
|
# Initialize an action.
|
9
10
|
#
|
@@ -45,4 +46,3 @@ module Synvert::Core
|
|
45
46
|
end
|
46
47
|
end
|
47
48
|
end
|
48
|
-
|
@@ -1,8 +1,10 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Synvert::Core
|
4
|
-
#
|
4
|
+
# AppendAction to append code to the bottom of node body.
|
5
5
|
class Rewriter::AppendAction < Rewriter::Action
|
6
|
+
END_LENGTH = "\nend".length
|
7
|
+
|
6
8
|
# Begin position to append code.
|
7
9
|
#
|
8
10
|
# @return [Integer] begin position.
|
@@ -10,7 +12,7 @@ module Synvert::Core
|
|
10
12
|
if :begin == @node.type
|
11
13
|
@node.loc.expression.end_pos
|
12
14
|
else
|
13
|
-
@node.loc.expression.end_pos - @node.indent -
|
15
|
+
@node.loc.expression.end_pos - @node.indent - END_LENGTH
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
@@ -28,8 +30,8 @@ module Synvert::Core
|
|
28
30
|
# @param node [Parser::AST::Node]
|
29
31
|
# @return [String] n times whitesphace
|
30
32
|
def indent(node)
|
31
|
-
if [
|
32
|
-
' ' * (node.indent +
|
33
|
+
if %i[block class].include? node.type
|
34
|
+
' ' * (node.indent + DEFAULT_INDENT)
|
33
35
|
else
|
34
36
|
' ' * node.indent
|
35
37
|
end
|
@@ -1,13 +1,22 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Synvert::Core
|
4
4
|
# InsertAction to insert code to the top of node body.
|
5
5
|
class Rewriter::InsertAction < Rewriter::Action
|
6
|
+
DO_LENGTH = " do".length
|
7
|
+
|
6
8
|
# Begin position to insert code.
|
7
9
|
#
|
8
10
|
# @return [Integer] begin position.
|
9
11
|
def begin_pos
|
10
|
-
|
12
|
+
case @node.type
|
13
|
+
when :block
|
14
|
+
@node.children[1].children.empty? ? @node.children[0].loc.expression.end_pos + DO_LENGTH : @node.children[1].loc.expression.end_pos
|
15
|
+
when :class
|
16
|
+
@node.children[1] ? @node.children[1].loc.expression.end_pos : @node.children[0].loc.expression.end_pos
|
17
|
+
else
|
18
|
+
@node.children.last.loc.expression.end_pos
|
19
|
+
end
|
11
20
|
end
|
12
21
|
|
13
22
|
# End position, always same to begin position.
|
@@ -19,27 +28,13 @@ module Synvert::Core
|
|
19
28
|
|
20
29
|
private
|
21
30
|
|
22
|
-
# Insert position.
|
23
|
-
#
|
24
|
-
# @return [Integer] insert position.
|
25
|
-
def insert_position(node)
|
26
|
-
case node.type
|
27
|
-
when :block
|
28
|
-
node.children[1].children.empty? ? node.children[0].loc.expression.end_pos + 3 : node.children[1].loc.expression.end_pos
|
29
|
-
when :class
|
30
|
-
node.children[1] ? node.children[1].loc.expression.end_pos : node.children[0].loc.expression.end_pos
|
31
|
-
else
|
32
|
-
node.children.last.loc.expression.end_pos
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
31
|
# Indent of the node.
|
37
32
|
#
|
38
33
|
# @param node [Parser::AST::Node]
|
39
34
|
# @return [String] n times whitesphace
|
40
35
|
def indent(node)
|
41
|
-
if [
|
42
|
-
' ' * (node.indent +
|
36
|
+
if %i[block class].include? node.type
|
37
|
+
' ' * (node.indent + DEFAULT_INDENT)
|
43
38
|
else
|
44
39
|
' ' * node.indent
|
45
40
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Synvert::Core
|
4
4
|
# Instance is an execution unit, it finds specified ast nodes,
|
@@ -91,7 +91,7 @@ module Synvert::Core
|
|
91
91
|
unless Configuration.instance.get(:skip_files).include? file_path
|
92
92
|
begin
|
93
93
|
conflict_actions = []
|
94
|
-
source = self.class.file_source(file_path)
|
94
|
+
source = +self.class.file_source(file_path)
|
95
95
|
ast = self.class.file_ast(file_path)
|
96
96
|
|
97
97
|
@current_file = file_path
|
@@ -108,7 +108,7 @@ module Synvert::Core
|
|
108
108
|
if @actions.length > 0
|
109
109
|
@actions.sort_by! { |action| action.send(@options[:sort_by]) }
|
110
110
|
conflict_actions = get_conflict_actions
|
111
|
-
@actions.
|
111
|
+
@actions.reverse_each do |action|
|
112
112
|
source[action.begin_pos...action.end_pos] = action.rewritten_code
|
113
113
|
source = remove_code_or_whole_line(source, action.line)
|
114
114
|
end
|
@@ -156,15 +156,28 @@ module Synvert::Core
|
|
156
156
|
# DSL #
|
157
157
|
#######
|
158
158
|
|
159
|
-
# Parse within_node dsl, it creates a [Synvert::Core::Rewriter::WithinScope] to find matching ast nodes,
|
159
|
+
# Parse within_node dsl, it creates a [Synvert::Core::Rewriter::WithinScope] to find recursive matching ast nodes,
|
160
160
|
# then continue operating on each matching ast node.
|
161
161
|
#
|
162
162
|
# @param rules [Hash] rules to find mathing ast nodes.
|
163
163
|
# @param block [Block] block code to continue operating on the matching nodes.
|
164
164
|
def within_node(rules, &block)
|
165
|
-
Rewriter::WithinScope.new(self, rules, &block).process
|
165
|
+
Rewriter::WithinScope.new(self, rules, { recursive: true }, &block).process
|
166
166
|
end
|
167
167
|
|
168
|
+
alias_method :with_node, :within_node
|
169
|
+
|
170
|
+
# Parse within_direct_node dsl, it creates a [Synvert::Core::Rewriter::WithinScope] to find direct matching ast nodes,
|
171
|
+
# then continue operating on each matching ast node.
|
172
|
+
#
|
173
|
+
# @param rules [Hash] rules to find mathing ast nodes.
|
174
|
+
# @param block [Block] block code to continue operating on the matching nodes.
|
175
|
+
def within_direct_node(rules, &block)
|
176
|
+
Rewriter::WithinScope.new(self, rules, { recursive: false }, &block).process
|
177
|
+
end
|
178
|
+
|
179
|
+
alias_method :with_direct_node, :within_direct_node
|
180
|
+
|
168
181
|
# Parse goto_node dsl, it creates a [Synvert::Core::Rewriter::GotoScope] to go to a child node,
|
169
182
|
# then continue operating on the child node.
|
170
183
|
#
|
@@ -174,8 +187,6 @@ module Synvert::Core
|
|
174
187
|
Rewriter::GotoScope.new(self, child_node_name, &block).process
|
175
188
|
end
|
176
189
|
|
177
|
-
alias_method :with_node, :within_node
|
178
|
-
|
179
190
|
# Parse if_exist_node dsl, it creates a [Synvert::Core::Rewriter::IfExistCondition] to check
|
180
191
|
# if matching nodes exist in the child nodes, if so, then continue operating on each matching ast node.
|
181
192
|
#
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Synvert::Core
|
4
4
|
# Go to and change its scope to a child node.
|
@@ -18,6 +18,7 @@ module Synvert::Core
|
|
18
18
|
def process
|
19
19
|
current_node = @instance.current_node
|
20
20
|
return unless current_node
|
21
|
+
|
21
22
|
child_node = current_node.send @child_node_name
|
22
23
|
@instance.process_with_other_node child_node do
|
23
24
|
@instance.instance_eval &@block
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Synvert::Core
|
4
4
|
# WithinScope finds out nodes which match rules, then change its scope to matching node.
|
@@ -7,10 +7,12 @@ module Synvert::Core
|
|
7
7
|
#
|
8
8
|
# @param instance [Synvert::Core::Rewriter::Instance]
|
9
9
|
# @param rules [Hash]
|
10
|
+
# @param options [Hash]
|
10
11
|
# @param block [Block]
|
11
|
-
def initialize(instance, rules, &block)
|
12
|
+
def initialize(instance, rules, options = { recursive: true }, &block)
|
12
13
|
@instance = instance
|
13
14
|
@rules = rules
|
15
|
+
@options = options
|
14
16
|
@block = block
|
15
17
|
end
|
16
18
|
|
@@ -19,12 +21,9 @@ module Synvert::Core
|
|
19
21
|
def process
|
20
22
|
current_node = @instance.current_node
|
21
23
|
return unless current_node
|
24
|
+
|
25
|
+
matching_nodes = find_matching_nodes(current_node)
|
22
26
|
@instance.process_with_node current_node do
|
23
|
-
matching_nodes = []
|
24
|
-
matching_nodes << current_node if current_node.match? @rules
|
25
|
-
current_node.recursive_children do |child_node|
|
26
|
-
matching_nodes << child_node if child_node.match? @rules
|
27
|
-
end
|
28
27
|
matching_nodes.each do |matching_node|
|
29
28
|
@instance.process_with_node matching_node do
|
30
29
|
@instance.instance_eval &@block
|
@@ -32,5 +31,22 @@ module Synvert::Core
|
|
32
31
|
end
|
33
32
|
end
|
34
33
|
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def find_matching_nodes(current_node)
|
38
|
+
matching_nodes = []
|
39
|
+
if @options[:recursive]
|
40
|
+
matching_nodes << current_node if current_node.match? @rules
|
41
|
+
current_node.recursive_children do |child_node|
|
42
|
+
matching_nodes << child_node if child_node.match? @rules
|
43
|
+
end
|
44
|
+
else
|
45
|
+
current_node.each do |child_node|
|
46
|
+
matching_nodes << child_node if child_node.match? @rules
|
47
|
+
end
|
48
|
+
end
|
49
|
+
matching_nodes
|
50
|
+
end
|
35
51
|
end
|
36
52
|
end
|
data/lib/synvert/core/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Synvert::Core
|
4
6
|
describe Configuration do
|
5
7
|
it 'sets / gets' do
|
6
8
|
Configuration.instance.set :key, 'value'
|
7
|
-
expect(Configuration.instance.get
|
9
|
+
expect(Configuration.instance.get(:key)).to eq 'value'
|
8
10
|
end
|
9
11
|
end
|
10
12
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Parser::AST::Node do
|
@@ -102,12 +104,12 @@ describe Parser::AST::Node do
|
|
102
104
|
describe '#arguments' do
|
103
105
|
it 'gets for def node' do
|
104
106
|
node = parse("def test(foo, bar); foo + bar; end")
|
105
|
-
expect(node.arguments.map { |argument| argument.to_source }).to eq [
|
107
|
+
expect(node.arguments.map { |argument| argument.to_source }).to eq %w[foo bar]
|
106
108
|
end
|
107
109
|
|
108
110
|
it 'gets for defs node' do
|
109
111
|
node = parse("def self.test(foo, bar); foo + bar; end")
|
110
|
-
expect(node.arguments.map { |argument| argument.to_source }).to eq [
|
112
|
+
expect(node.arguments.map { |argument| argument.to_source }).to eq %w[foo bar]
|
111
113
|
end
|
112
114
|
|
113
115
|
it 'gets for block node' do
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Synvert::Core
|
@@ -12,7 +14,7 @@ module Synvert::Core
|
|
12
14
|
it 'parses within_node' do
|
13
15
|
scope = double()
|
14
16
|
block = Proc.new {}
|
15
|
-
expect(Rewriter::WithinScope).to receive(:new).with(instance, type: 'send', message: 'create', &block).and_return(scope)
|
17
|
+
expect(Rewriter::WithinScope).to receive(:new).with(instance, { type: 'send', message: 'create' }, { recursive: true }, &block).and_return(scope)
|
16
18
|
expect(scope).to receive(:process)
|
17
19
|
instance.within_node(type: 'send', message: 'create', &block)
|
18
20
|
end
|
@@ -20,11 +22,27 @@ module Synvert::Core
|
|
20
22
|
it 'parses with_node' do
|
21
23
|
scope = double()
|
22
24
|
block = Proc.new {}
|
23
|
-
expect(Rewriter::WithinScope).to receive(:new).with(instance, type: 'send', message: 'create', &block).and_return(scope)
|
25
|
+
expect(Rewriter::WithinScope).to receive(:new).with(instance, { type: 'send', message: 'create' }, { recursive: true }, &block).and_return(scope)
|
24
26
|
expect(scope).to receive(:process)
|
25
27
|
instance.with_node(type: 'send', message: 'create', &block)
|
26
28
|
end
|
27
29
|
|
30
|
+
it 'parses within_direct_node' do
|
31
|
+
scope = double()
|
32
|
+
block = Proc.new {}
|
33
|
+
expect(Rewriter::WithinScope).to receive(:new).with(instance, { type: 'send', message: 'create' }, { recursive: false }, &block).and_return(scope)
|
34
|
+
expect(scope).to receive(:process)
|
35
|
+
instance.within_direct_node(type: 'send', message: 'create', &block)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'parses with_direct_node' do
|
39
|
+
scope = double()
|
40
|
+
block = Proc.new {}
|
41
|
+
expect(Rewriter::WithinScope).to receive(:new).with(instance, { type: 'send', message: 'create' }, { recursive: false }, &block).and_return(scope)
|
42
|
+
expect(scope).to receive(:process)
|
43
|
+
instance.with_direct_node(type: 'send', message: 'create', &block)
|
44
|
+
end
|
45
|
+
|
28
46
|
it 'parses goto_node' do
|
29
47
|
scope = double()
|
30
48
|
block = Proc.new {}
|
@@ -205,7 +223,7 @@ end
|
|
205
223
|
instance.instance_variable_set :@actions, [action1, action2, action3]
|
206
224
|
conflict_actions = instance.send(:get_conflict_actions)
|
207
225
|
expect(conflict_actions).to eq []
|
208
|
-
expect(instance.instance_variable_get
|
226
|
+
expect(instance.instance_variable_get(:@actions)).to eq [action1, action2, action3]
|
209
227
|
end
|
210
228
|
|
211
229
|
it "has no conflict" do
|
@@ -216,7 +234,7 @@ end
|
|
216
234
|
instance.instance_variable_set :@actions, [action1, action2, action3]
|
217
235
|
conflict_actions = instance.send(:get_conflict_actions)
|
218
236
|
expect(conflict_actions).to eq [action2, action1]
|
219
|
-
expect(instance.instance_variable_get
|
237
|
+
expect(instance.instance_variable_get(:@actions)).to eq [action3]
|
220
238
|
end
|
221
239
|
end
|
222
240
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Synvert::Core
|
@@ -92,7 +94,7 @@ module Synvert::Core
|
|
92
94
|
add_file 'foo.bar', 'FooBar'
|
93
95
|
end
|
94
96
|
rewriter.process
|
95
|
-
expect(File.read
|
97
|
+
expect(File.read('./foo.bar')).to eq 'FooBar'
|
96
98
|
FileUtils.rm './foo.bar'
|
97
99
|
end
|
98
100
|
|
@@ -112,7 +114,7 @@ module Synvert::Core
|
|
112
114
|
remove_file 'foo.bar'
|
113
115
|
end
|
114
116
|
rewriter.process
|
115
|
-
expect(File.exist?
|
117
|
+
expect(File.exist?('./foo.bar')).to be_falsey
|
116
118
|
end
|
117
119
|
|
118
120
|
it 'does nothing if file not exist' do
|
@@ -120,7 +122,7 @@ module Synvert::Core
|
|
120
122
|
remove_file 'foo.bar'
|
121
123
|
end
|
122
124
|
rewriter.process
|
123
|
-
expect(File.exist?
|
125
|
+
expect(File.exist?('./foo.bar')).to be_falsey
|
124
126
|
end
|
125
127
|
|
126
128
|
it 'does nothing in sandbox mode' do
|
@@ -204,11 +206,11 @@ module Synvert::Core
|
|
204
206
|
context "exist?" do
|
205
207
|
it 'returns true if rewriter exists' do
|
206
208
|
Rewriter.new 'group', 'rewriter'
|
207
|
-
expect(Rewriter.exist?
|
209
|
+
expect(Rewriter.exist?('group', 'rewriter')).to be_truthy
|
208
210
|
end
|
209
211
|
|
210
212
|
it 'returns false if rewriter does not exist' do
|
211
|
-
expect(Rewriter.exist?
|
213
|
+
expect(Rewriter.exist?('group', 'rewriter')).to be_falsey
|
212
214
|
end
|
213
215
|
end
|
214
216
|
|
data/synvert-core.gemspec
CHANGED
@@ -18,11 +18,11 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_runtime_dependency "parser", "~>
|
21
|
+
spec.add_runtime_dependency "parser", "~> 3.0.0"
|
22
22
|
spec.add_runtime_dependency "activesupport"
|
23
23
|
spec.add_runtime_dependency "erubis"
|
24
24
|
|
25
|
-
spec.add_development_dependency "bundler"
|
25
|
+
spec.add_development_dependency "bundler"
|
26
26
|
spec.add_development_dependency "rake"
|
27
27
|
spec.add_development_dependency "rspec"
|
28
28
|
spec.add_development_dependency "guard"
|
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: 0.
|
4
|
+
version: 0.16.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 3.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 3.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,16 +56,16 @@ dependencies:
|
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -194,7 +194,7 @@ homepage: https://github.com/xinminlabs/synvert-core
|
|
194
194
|
licenses:
|
195
195
|
- MIT
|
196
196
|
metadata: {}
|
197
|
-
post_install_message:
|
197
|
+
post_install_message:
|
198
198
|
rdoc_options: []
|
199
199
|
require_paths:
|
200
200
|
- lib
|
@@ -209,9 +209,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
209
209
|
- !ruby/object:Gem::Version
|
210
210
|
version: '0'
|
211
211
|
requirements: []
|
212
|
-
|
213
|
-
|
214
|
-
signing_key:
|
212
|
+
rubygems_version: 3.1.4
|
213
|
+
signing_key:
|
215
214
|
specification_version: 4
|
216
215
|
summary: convert ruby code to better syntax.
|
217
216
|
test_files:
|