synvert-core 1.4.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/main.yml +0 -1
  3. data/.gitignore +0 -5
  4. data/CHANGELOG.md +12 -0
  5. data/Gemfile +0 -3
  6. data/Gemfile.lock +101 -0
  7. data/Guardfile +0 -9
  8. data/README.md +31 -13
  9. data/Rakefile +1 -15
  10. data/lib/synvert/core/engine/erb.rb +1 -1
  11. data/lib/synvert/core/engine.rb +1 -1
  12. data/lib/synvert/core/node_ext.rb +0 -639
  13. data/lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb +20 -17
  14. data/lib/synvert/core/rewriter/condition/if_exist_condition.rb +1 -5
  15. data/lib/synvert/core/rewriter/condition/if_only_exist_condition.rb +1 -1
  16. data/lib/synvert/core/rewriter/condition/unless_exist_condition.rb +1 -5
  17. data/lib/synvert/core/rewriter/condition.rb +5 -1
  18. data/lib/synvert/core/rewriter/instance.rb +91 -140
  19. data/lib/synvert/core/rewriter/scope/query_scope.rb +8 -6
  20. data/lib/synvert/core/rewriter/scope/within_scope.rb +4 -87
  21. data/lib/synvert/core/rewriter.rb +0 -10
  22. data/lib/synvert/core/version.rb +1 -1
  23. data/lib/synvert/core.rb +4 -6
  24. data/spec/synvert/core/engine/erb_spec.rb +3 -3
  25. data/spec/synvert/core/node_ext_spec.rb +0 -965
  26. data/spec/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action_spec.rb +21 -1
  27. data/spec/synvert/core/rewriter/instance_spec.rb +64 -131
  28. data/spec/synvert/core/rewriter/scope/goto_scope_spec.rb +1 -4
  29. data/spec/synvert/core/rewriter/scope/query_scope_spec.rb +1 -16
  30. data/spec/synvert/core/rewriter/scope/within_scope_spec.rb +22 -13
  31. data/synvert-core-ruby.gemspec +5 -3
  32. metadata +46 -62
  33. data/lib/synvert/core/array_ext.rb +0 -48
  34. data/lib/synvert/core/node_query/compiler/array.rb +0 -34
  35. data/lib/synvert/core/node_query/compiler/attribute.rb +0 -39
  36. data/lib/synvert/core/node_query/compiler/attribute_list.rb +0 -24
  37. data/lib/synvert/core/node_query/compiler/basic_selector.rb +0 -28
  38. data/lib/synvert/core/node_query/compiler/boolean.rb +0 -23
  39. data/lib/synvert/core/node_query/compiler/comparable.rb +0 -86
  40. data/lib/synvert/core/node_query/compiler/dynamic_attribute.rb +0 -51
  41. data/lib/synvert/core/node_query/compiler/expression.rb +0 -41
  42. data/lib/synvert/core/node_query/compiler/float.rb +0 -23
  43. data/lib/synvert/core/node_query/compiler/identifier.rb +0 -41
  44. data/lib/synvert/core/node_query/compiler/integer.rb +0 -23
  45. data/lib/synvert/core/node_query/compiler/invalid_operator_error.rb +0 -7
  46. data/lib/synvert/core/node_query/compiler/nil.rb +0 -23
  47. data/lib/synvert/core/node_query/compiler/parse_error.rb +0 -7
  48. data/lib/synvert/core/node_query/compiler/regexp.rb +0 -37
  49. data/lib/synvert/core/node_query/compiler/selector.rb +0 -113
  50. data/lib/synvert/core/node_query/compiler/string.rb +0 -23
  51. data/lib/synvert/core/node_query/compiler/symbol.rb +0 -23
  52. data/lib/synvert/core/node_query/compiler.rb +0 -25
  53. data/lib/synvert/core/node_query/lexer.rex +0 -99
  54. data/lib/synvert/core/node_query/lexer.rex.rb +0 -299
  55. data/lib/synvert/core/node_query/parser.racc.rb +0 -306
  56. data/lib/synvert/core/node_query/parser.y +0 -60
  57. data/lib/synvert/core/node_query.rb +0 -36
  58. data/lib/synvert/core/rewriter/action/append_action.rb +0 -28
  59. data/lib/synvert/core/rewriter/action/delete_action.rb +0 -34
  60. data/lib/synvert/core/rewriter/action/insert_action.rb +0 -34
  61. data/lib/synvert/core/rewriter/action/insert_after_action.rb +0 -22
  62. data/lib/synvert/core/rewriter/action/prepend_action.rb +0 -44
  63. data/lib/synvert/core/rewriter/action/remove_action.rb +0 -56
  64. data/lib/synvert/core/rewriter/action/replace_action.rb +0 -33
  65. data/lib/synvert/core/rewriter/action/replace_with_action.rb +0 -36
  66. data/lib/synvert/core/rewriter/action/wrap_action.rb +0 -37
  67. data/lib/synvert/core/rewriter/action.rb +0 -102
  68. data/spec/synvert/core/node_query/lexer_spec.rb +0 -580
  69. data/spec/synvert/core/node_query/parser_spec.rb +0 -337
  70. data/spec/synvert/core/rewriter/action/append_action_spec.rb +0 -70
  71. data/spec/synvert/core/rewriter/action/delete_action_spec.rb +0 -26
  72. data/spec/synvert/core/rewriter/action/insert_action_spec.rb +0 -70
  73. data/spec/synvert/core/rewriter/action/insert_after_action_spec.rb +0 -26
  74. data/spec/synvert/core/rewriter/action/prepend_action_spec.rb +0 -175
  75. data/spec/synvert/core/rewriter/action/remove_action_spec.rb +0 -26
  76. data/spec/synvert/core/rewriter/action/replace_action_spec.rb +0 -28
  77. data/spec/synvert/core/rewriter/action/replace_with_action_spec.rb +0 -59
  78. data/spec/synvert/core/rewriter/action/wrap_action_spec.rb +0 -31
  79. data/spec/synvert/core/rewriter/action_spec.rb +0 -14
@@ -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