synvert-core 1.3.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -4
  3. data/CHANGELOG.md +16 -0
  4. data/Gemfile +0 -3
  5. data/Guardfile +0 -9
  6. data/README.md +30 -12
  7. data/Rakefile +1 -15
  8. data/lib/synvert/core/engine/erb.rb +1 -1
  9. data/lib/synvert/core/engine.rb +1 -1
  10. data/lib/synvert/core/node_ext.rb +0 -466
  11. data/lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb +20 -17
  12. data/lib/synvert/core/rewriter/condition/if_exist_condition.rb +1 -1
  13. data/lib/synvert/core/rewriter/condition/unless_exist_condition.rb +1 -1
  14. data/lib/synvert/core/rewriter/instance.rb +89 -135
  15. data/lib/synvert/core/rewriter/scope/query_scope.rb +2 -2
  16. data/lib/synvert/core/rewriter/scope/within_scope.rb +4 -4
  17. data/lib/synvert/core/rewriter.rb +0 -10
  18. data/lib/synvert/core/version.rb +1 -1
  19. data/lib/synvert/core.rb +4 -6
  20. data/spec/synvert/core/engine/erb_spec.rb +3 -3
  21. data/spec/synvert/core/node_ext_spec.rb +0 -795
  22. data/spec/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action_spec.rb +21 -1
  23. data/spec/synvert/core/rewriter/instance_spec.rb +49 -112
  24. data/spec/synvert/core/rewriter/scope/goto_scope_spec.rb +1 -4
  25. data/spec/synvert/core/rewriter/scope/query_scope_spec.rb +8 -4
  26. data/spec/synvert/core/rewriter/scope/within_scope_spec.rb +1 -4
  27. data/synvert-core-ruby.gemspec +4 -2
  28. metadata +44 -61
  29. data/lib/synvert/core/array_ext.rb +0 -48
  30. data/lib/synvert/core/node_query/compiler/array.rb +0 -34
  31. data/lib/synvert/core/node_query/compiler/attribute.rb +0 -39
  32. data/lib/synvert/core/node_query/compiler/attribute_list.rb +0 -24
  33. data/lib/synvert/core/node_query/compiler/boolean.rb +0 -23
  34. data/lib/synvert/core/node_query/compiler/comparable.rb +0 -86
  35. data/lib/synvert/core/node_query/compiler/dynamic_attribute.rb +0 -51
  36. data/lib/synvert/core/node_query/compiler/expression.rb +0 -58
  37. data/lib/synvert/core/node_query/compiler/float.rb +0 -23
  38. data/lib/synvert/core/node_query/compiler/identifier.rb +0 -41
  39. data/lib/synvert/core/node_query/compiler/integer.rb +0 -23
  40. data/lib/synvert/core/node_query/compiler/invalid_operator_error.rb +0 -7
  41. data/lib/synvert/core/node_query/compiler/nil.rb +0 -23
  42. data/lib/synvert/core/node_query/compiler/parse_error.rb +0 -7
  43. data/lib/synvert/core/node_query/compiler/regexp.rb +0 -37
  44. data/lib/synvert/core/node_query/compiler/selector.rb +0 -138
  45. data/lib/synvert/core/node_query/compiler/simple_selector.rb +0 -29
  46. data/lib/synvert/core/node_query/compiler/string.rb +0 -23
  47. data/lib/synvert/core/node_query/compiler/symbol.rb +0 -23
  48. data/lib/synvert/core/node_query/compiler.rb +0 -25
  49. data/lib/synvert/core/node_query/lexer.rex +0 -108
  50. data/lib/synvert/core/node_query/lexer.rex.rb +0 -321
  51. data/lib/synvert/core/node_query/parser.racc.rb +0 -322
  52. data/lib/synvert/core/node_query/parser.y +0 -62
  53. data/lib/synvert/core/node_query.rb +0 -37
  54. data/lib/synvert/core/rewriter/action/append_action.rb +0 -28
  55. data/lib/synvert/core/rewriter/action/delete_action.rb +0 -32
  56. data/lib/synvert/core/rewriter/action/insert_action.rb +0 -34
  57. data/lib/synvert/core/rewriter/action/insert_after_action.rb +0 -22
  58. data/lib/synvert/core/rewriter/action/prepend_action.rb +0 -44
  59. data/lib/synvert/core/rewriter/action/remove_action.rb +0 -53
  60. data/lib/synvert/core/rewriter/action/replace_action.rb +0 -33
  61. data/lib/synvert/core/rewriter/action/replace_with_action.rb +0 -36
  62. data/lib/synvert/core/rewriter/action/wrap_action.rb +0 -37
  63. data/lib/synvert/core/rewriter/action.rb +0 -102
  64. data/spec/synvert/core/node_query/lexer_spec.rb +0 -640
  65. data/spec/synvert/core/node_query/parser_spec.rb +0 -382
  66. data/spec/synvert/core/rewriter/action/append_action_spec.rb +0 -70
  67. data/spec/synvert/core/rewriter/action/delete_action_spec.rb +0 -26
  68. data/spec/synvert/core/rewriter/action/insert_action_spec.rb +0 -70
  69. data/spec/synvert/core/rewriter/action/insert_after_action_spec.rb +0 -26
  70. data/spec/synvert/core/rewriter/action/prepend_action_spec.rb +0 -175
  71. data/spec/synvert/core/rewriter/action/remove_action_spec.rb +0 -26
  72. data/spec/synvert/core/rewriter/action/replace_action_spec.rb +0 -28
  73. data/spec/synvert/core/rewriter/action/replace_with_action_spec.rb +0 -59
  74. data/spec/synvert/core/rewriter/action/wrap_action_spec.rb +0 -31
  75. data/spec/synvert/core/rewriter/action_spec.rb +0 -14
@@ -1,175 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- module Synvert::Core
6
- describe Rewriter::PrependAction do
7
- describe 'block node without args' do
8
- subject {
9
- source = "Synvert::Application.configure do\nend"
10
- block_node = Parser::CurrentRuby.parse(source)
11
- instance = double(current_node: block_node)
12
- Rewriter::PrependAction.new(instance, 'config.eager_load = true').process
13
- }
14
-
15
- it 'gets begin_pos' do
16
- expect(subject.begin_pos).to eq 'Synvert::Application.configure do'.length
17
- end
18
-
19
- it 'gets end_pos' do
20
- expect(subject.end_pos).to eq 'Synvert::Application.configure do'.length
21
- end
22
-
23
- it 'gets rewritten_code' do
24
- expect(subject.rewritten_code).to eq "\n config.eager_load = true"
25
- end
26
- end
27
-
28
- describe 'block node with args' do
29
- subject {
30
- source = "RSpec.configure do |config|\nend"
31
- block_node = Parser::CurrentRuby.parse(source)
32
- instance = double(current_node: block_node)
33
- Rewriter::PrependAction.new(instance, '{{arguments.first}}.include FactoryGirl::Syntax::Methods').process
34
- }
35
-
36
- it 'gets begin_pos' do
37
- expect(subject.begin_pos).to eq 'RSpec.configure do |config|'.length
38
- end
39
-
40
- it 'gets end_pos' do
41
- expect(subject.end_pos).to eq 'RSpec.configure do |config|'.length
42
- end
43
-
44
- it 'gets rewritten_code' do
45
- expect(subject.rewritten_code).to eq "\n config.include FactoryGirl::Syntax::Methods"
46
- end
47
- end
48
-
49
- describe 'class node without superclass' do
50
- subject {
51
- source = "class User\n has_many :posts\nend"
52
- class_node = Parser::CurrentRuby.parse(source)
53
- instance = double(current_node: class_node)
54
- Rewriter::PrependAction.new(instance, 'include Deletable').process
55
- }
56
-
57
- it 'gets begin_pos' do
58
- expect(subject.begin_pos).to eq 'class User'.length
59
- end
60
-
61
- it 'gets end_pos' do
62
- expect(subject.end_pos).to eq 'class User'.length
63
- end
64
-
65
- it 'gets rewritten_code' do
66
- expect(subject.rewritten_code).to eq "\n include Deletable"
67
- end
68
- end
69
-
70
- describe 'class node with superclass' do
71
- subject {
72
- source = "class User < ActiveRecord::Base\n has_many :posts\nend"
73
- class_node = Parser::CurrentRuby.parse(source)
74
- instance = double(current_node: class_node)
75
- Rewriter::PrependAction.new(instance, 'include Deletable').process
76
- }
77
-
78
- it 'gets begin_pos' do
79
- expect(subject.begin_pos).to eq 'class User < ActionRecord::Base'.length
80
- end
81
-
82
- it 'gets end_pos' do
83
- expect(subject.end_pos).to eq 'class User < ActionRecord::Base'.length
84
- end
85
-
86
- it 'gets rewritten_code' do
87
- expect(subject.rewritten_code).to eq "\n include Deletable"
88
- end
89
- end
90
-
91
- describe 'def node without args' do
92
- subject do
93
- source = "def setup\n do_something\nend"
94
- def_node = Parser::CurrentRuby.parse(source)
95
- instance = double(current_node: def_node)
96
- Rewriter::PrependAction.new(instance, 'super').process
97
- end
98
-
99
- it 'gets begin_pos' do
100
- expect(subject.begin_pos).to eq 'def setup'.length
101
- end
102
-
103
- it 'gets end_pos' do
104
- expect(subject.end_pos).to eq 'def setup'.length
105
- end
106
-
107
- it 'gets rewritten_code' do
108
- expect(subject.rewritten_code).to eq "\n super"
109
- end
110
- end
111
-
112
- describe 'def node with args' do
113
- subject do
114
- source = "def setup(foobar)\n do_something\nend"
115
- def_node = Parser::CurrentRuby.parse(source)
116
- instance = double(current_node: def_node)
117
- Rewriter::PrependAction.new(instance, 'super').process
118
- end
119
-
120
- it 'gets begin_pos' do
121
- expect(subject.begin_pos).to eq 'def setup(foobar)'.length
122
- end
123
-
124
- it 'gets end_pos' do
125
- expect(subject.end_pos).to eq 'def setup(foobar)'.length
126
- end
127
-
128
- it 'gets rewritten_code' do
129
- expect(subject.rewritten_code).to eq "\n super"
130
- end
131
- end
132
-
133
- describe 'defs node without args' do
134
- subject do
135
- source = "def self.foo\n do_something\nend"
136
- def_node = Parser::CurrentRuby.parse(source)
137
- instance = double(current_node: def_node)
138
- Rewriter::PrependAction.new(instance, 'do_something_first').process
139
- end
140
-
141
- it 'gets begin_pos' do
142
- expect(subject.begin_pos).to eq 'def self.foo'.length
143
- end
144
-
145
- it 'gets end_pos' do
146
- expect(subject.end_pos).to eq 'def self.foo'.length
147
- end
148
-
149
- it 'gets rewritten_code' do
150
- expect(subject.rewritten_code).to eq "\n do_something_first"
151
- end
152
- end
153
-
154
- describe 'defs node with args' do
155
- subject do
156
- source = "def self.foo(bar)\n do_something\nend"
157
- def_node = Parser::CurrentRuby.parse(source)
158
- instance = double(current_node: def_node)
159
- Rewriter::PrependAction.new(instance, 'do_something_first').process
160
- end
161
-
162
- it 'gets begin_pos' do
163
- expect(subject.begin_pos).to eq 'def self.foo(bar)'.length
164
- end
165
-
166
- it 'gets end_pos' do
167
- expect(subject.end_pos).to eq 'def self.foo(bar)'.length
168
- end
169
-
170
- it 'gets rewritten_code' do
171
- expect(subject.rewritten_code).to eq "\n do_something_first"
172
- end
173
- end
174
- end
175
- end
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- module Synvert::Core
6
- describe Rewriter::RemoveAction do
7
- subject {
8
- source = "user = User.new params[:user]\nuser.save\nrender\n"
9
- send_node = Parser::CurrentRuby.parse(source).children[1]
10
- instance = double(current_node: send_node, file_source: source)
11
- Rewriter::RemoveAction.new(instance).process
12
- }
13
-
14
- it 'gets begin_pos' do
15
- expect(subject.begin_pos).to eq "user = User.new params[:user]\n".length
16
- end
17
-
18
- it 'gets end_pos' do
19
- expect(subject.end_pos).to eq "user = User.new params[:user]\nuser.save\n".length
20
- end
21
-
22
- it 'gets rewritten_code' do
23
- expect(subject.rewritten_code).to eq ''
24
- end
25
- end
26
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- module Synvert::Core
6
- describe Rewriter::ReplaceAction do
7
- context 'replace with single line' do
8
- subject {
9
- source = 'FactoryBot.create(:user)'
10
- node = Parser::CurrentRuby.parse(source)
11
- instance = double(current_node: node)
12
- Rewriter::ReplaceAction.new(instance, :receiver, :dot, :message, with: 'create').process
13
- }
14
-
15
- it 'gets begin_pos' do
16
- expect(subject.begin_pos).to eq 0
17
- end
18
-
19
- it 'gets end_pos' do
20
- expect(subject.end_pos).to eq 'FactoryBot.create'.length
21
- end
22
-
23
- it 'gets rewritten_code' do
24
- expect(subject.rewritten_code).to eq 'create'
25
- end
26
- end
27
- end
28
- end
@@ -1,59 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- module Synvert::Core
6
- describe Rewriter::ReplaceWithAction do
7
- context 'replace with single line' do
8
- subject {
9
- source = 'post = FactoryGirl.create_list :post, 2'
10
- send_node = Parser::CurrentRuby.parse(source).children[1]
11
- instance = double(current_node: send_node)
12
- Rewriter::ReplaceWithAction.new(instance, 'create_list {{arguments}}').process
13
- }
14
-
15
- it 'gets begin_pos' do
16
- expect(subject.begin_pos).to eq 'post = '.length
17
- end
18
-
19
- it 'gets end_pos' do
20
- expect(subject.end_pos).to eq 'post = FactoryGirl.create_list :post, 2'.length
21
- end
22
-
23
- it 'gets rewritten_code' do
24
- expect(subject.rewritten_code).to eq 'create_list :post, 2'
25
- end
26
- end
27
-
28
- context '#replace with multiple line' do
29
- subject {
30
- source = ' its(:size) { should == 1 }'
31
- send_node = Parser::CurrentRuby.parse(source)
32
- instance = double(current_node: send_node)
33
- Rewriter::ReplaceWithAction.new(instance, <<~EOS).process
34
- describe '#size' do
35
- subject { super().size }
36
- it { {{body}} }
37
- end
38
- EOS
39
- }
40
-
41
- it 'gets begin_pos' do
42
- expect(subject.begin_pos).to eq 2
43
- end
44
-
45
- it 'gets end_pos' do
46
- expect(subject.end_pos).to eq ' its(:size) { should == 1 }'.length
47
- end
48
-
49
- it 'gets rewritten_code' do
50
- expect(subject.rewritten_code).to eq <<~EOS.strip
51
- describe '#size' do
52
- subject { super().size }
53
- it { should == 1 }
54
- end
55
- EOS
56
- end
57
- end
58
- end
59
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- module Synvert::Core
6
- describe Rewriter::WrapAction do
7
- subject {
8
- source = "class Bar\nend"
9
- node = Parser::CurrentRuby.parse(source)
10
- instance = double(current_node: node)
11
- Rewriter::WrapAction.new(instance, with: 'module Foo').process
12
- }
13
-
14
- it 'gets begin_pos' do
15
- expect(subject.begin_pos).to eq 0
16
- end
17
-
18
- it 'gets end_pos' do
19
- expect(subject.end_pos).to eq "class Bar\nend".length
20
- end
21
-
22
- it 'gets rewritten_code' do
23
- expect(subject.rewritten_code).to eq <<~EOS.strip
24
- module Foo
25
- class Bar
26
- end
27
- end
28
- EOS
29
- end
30
- end
31
- end
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- module Synvert::Core
6
- describe Rewriter::Action do
7
- subject {
8
- source = "before_save do\n return false\nend"
9
- block_node = Parser::CurrentRuby.parse(source).body.first
10
- instance = double(current_node: block_node)
11
- Rewriter::Action.new(instance, source)
12
- }
13
- end
14
- end