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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 741ca9c2f6f29e5bbafbc5b63d94b3cd9a56aa20e8a00f3f70830b73b1fb697e
4
- data.tar.gz: a8bbf6e0c48a4af42578abb20807f3d86359fc069dc85ff90e12cf011f076998
3
+ metadata.gz: 5d838da042cfdbc68e4a235117a465ca340fa732203f7470684a9279e6797fff
4
+ data.tar.gz: ad784c3e09faa73a55e0bf0ad51a982230d9a1b2a328c43414e4aa297e38a00e
5
5
  SHA512:
6
- metadata.gz: 7fcadf632c863b1f3ba410b65f63c741b594255567f337ebc86c51ae45e681484653b45eec01fc5c3e3a4ea170a6bd38e899bdf22f65b2e980d58cac8c11cfcd
7
- data.tar.gz: 80ebe8f07ef9679c6921233d52b46979a6bfb895e4b63b974672dec193ef52ce08c40454d2a92fd509f12b8f3567065bb7d2dbee33af7bca37a96246e6373381
6
+ metadata.gz: 4b31e94f8071af04f1ae7b1292bb5af91e52ba047949535667cb6765a5ef32c9bbcf855dd92a212aa640b0185f42fbd1bbcf4614f424c596f9c52f62a313a643
7
+ data.tar.gz: 197318ccffd17c9eb60251731bf49f45198e2b5fb5812c22d4fe6d0d07bac94bff638bc5a125d05be2ccec930b16300ccdb83ffdd53bf8cf0c4cd8ad22a34c94
@@ -15,7 +15,6 @@ on:
15
15
 
16
16
  jobs:
17
17
  test:
18
-
19
18
  runs-on: ubuntu-latest
20
19
  strategy:
21
20
  matrix:
data/.gitignore CHANGED
@@ -3,7 +3,6 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
- Gemfile.lock
7
6
  InstalledFiles
8
7
  _yardoc
9
8
  coverage
@@ -15,7 +14,3 @@ spec/reports
15
14
  test/tmp
16
15
  test/version_tmp
17
16
  tmp
18
-
19
- lib/synvert/core/node_query/lexer.rex.rb
20
- lib/synvert/core/node_query/parser.racc.rb
21
- lib/synvert/core/node_query/parser.output
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.6.0 (2022-09-15)
4
+
5
+ * Make use of `NodeQuery` to query nodes
6
+ * Remove `Node#to_hash`
7
+ * Downgrade `activesupport` to < 7.0.0
8
+
9
+ ## 1.5.0 (2022-07-02)
10
+
11
+ * Abstract `node_query`
12
+ * Abstract `node_mutation`
13
+ * Abstract `parser_node_ext`
14
+
3
15
  ## 1.4.0 (2022-05-21)
4
16
 
5
17
  * Drop support `:first-child` and `:last-child`
data/Gemfile CHANGED
@@ -7,9 +7,6 @@ gemspec
7
7
 
8
8
  gem "guard"
9
9
  gem "guard-rspec"
10
- gem "guard-rake"
11
- gem "oedipus_lex"
12
- gem "racc"
13
10
  gem "rake"
14
11
  gem "rspec"
15
12
  gem "rspec-mocks"
data/Gemfile.lock ADDED
@@ -0,0 +1,101 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ synvert-core (1.6.0)
5
+ activesupport (< 7.0.0)
6
+ erubis
7
+ node_mutation
8
+ node_query
9
+ parser
10
+ parser_node_ext
11
+
12
+ GEM
13
+ remote: https://rubygems.org/
14
+ specs:
15
+ activesupport (6.1.7)
16
+ concurrent-ruby (~> 1.0, >= 1.0.2)
17
+ i18n (>= 1.6, < 2)
18
+ minitest (>= 5.1)
19
+ tzinfo (~> 2.0)
20
+ zeitwerk (~> 2.3)
21
+ ast (2.4.2)
22
+ coderay (1.1.3)
23
+ concurrent-ruby (1.1.10)
24
+ diff-lcs (1.5.0)
25
+ erubis (2.7.0)
26
+ ffi (1.15.5)
27
+ formatador (1.1.0)
28
+ guard (2.18.0)
29
+ formatador (>= 0.2.4)
30
+ listen (>= 2.7, < 4.0)
31
+ lumberjack (>= 1.0.12, < 2.0)
32
+ nenv (~> 0.1)
33
+ notiffany (~> 0.0)
34
+ pry (>= 0.13.0)
35
+ shellany (~> 0.0)
36
+ thor (>= 0.18.1)
37
+ guard-compat (1.2.1)
38
+ guard-rspec (4.7.3)
39
+ guard (~> 2.1)
40
+ guard-compat (~> 1.1)
41
+ rspec (>= 2.99.0, < 4.0)
42
+ i18n (1.12.0)
43
+ concurrent-ruby (~> 1.0)
44
+ listen (3.7.1)
45
+ rb-fsevent (~> 0.10, >= 0.10.3)
46
+ rb-inotify (~> 0.9, >= 0.9.10)
47
+ lumberjack (1.2.8)
48
+ method_source (1.0.0)
49
+ minitest (5.16.3)
50
+ nenv (0.3.0)
51
+ node_mutation (1.2.1)
52
+ activesupport
53
+ erubis
54
+ node_query (1.5.0)
55
+ activesupport (< 7.0.0)
56
+ notiffany (0.1.3)
57
+ nenv (~> 0.1)
58
+ shellany (~> 0.0)
59
+ parser (3.1.2.1)
60
+ ast (~> 2.4.1)
61
+ parser_node_ext (0.4.0)
62
+ parser
63
+ pry (0.14.1)
64
+ coderay (~> 1.1)
65
+ method_source (~> 1.0)
66
+ rake (13.0.6)
67
+ rb-fsevent (0.11.1)
68
+ rb-inotify (0.10.1)
69
+ ffi (~> 1.0)
70
+ rspec (3.10.0)
71
+ rspec-core (~> 3.10.0)
72
+ rspec-expectations (~> 3.10.0)
73
+ rspec-mocks (~> 3.10.0)
74
+ rspec-core (3.10.2)
75
+ rspec-support (~> 3.10.0)
76
+ rspec-expectations (3.10.2)
77
+ diff-lcs (>= 1.2.0, < 2.0)
78
+ rspec-support (~> 3.10.0)
79
+ rspec-mocks (3.10.2)
80
+ diff-lcs (>= 1.2.0, < 2.0)
81
+ rspec-support (~> 3.10.0)
82
+ rspec-support (3.10.3)
83
+ shellany (0.0.1)
84
+ thor (1.2.1)
85
+ tzinfo (2.0.5)
86
+ concurrent-ruby (~> 1.0)
87
+ zeitwerk (2.6.0)
88
+
89
+ PLATFORMS
90
+ ruby
91
+
92
+ DEPENDENCIES
93
+ guard
94
+ guard-rspec
95
+ rake
96
+ rspec
97
+ rspec-mocks
98
+ synvert-core!
99
+
100
+ BUNDLED WITH
101
+ 2.3.7
data/Guardfile CHANGED
@@ -3,14 +3,5 @@
3
3
  guard :rspec, cmd: 'bundle exec rspec' do
4
4
  watch(%r{^spec/.+_spec\.rb$})
5
5
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
6
- watch('lib/synvert/core/node_query/lexer.rex.rb') { 'spec/synvert/core/node_query/lexer_spec.rb' }
7
- watch('lib/synvert/core/node_query/compiler.rb') { 'spec/synvert/core/node_query/parser_spec.rb' }
8
- watch(%r{^lib/synvert/core/node_query/compiler/.*\.rb$}) { 'spec/synvert/core/node_query/parser_spec.rb' }
9
- watch('lib/synvert/core/node_query/parser.racc.rb') { 'spec/synvert/core/node_query/parser_spec.rb' }
10
6
  watch('spec/spec_helper.rb') { "spec" }
11
7
  end
12
-
13
- guard :rake, task: 'generate' do
14
- watch('lib/synvert/core/node_query/lexer.rex')
15
- watch('lib/synvert/core/node_query/parser.y')
16
- end
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # synvert-core-ruby
2
2
 
3
- <img src="https://synvert.xinminlabs.com/img/logo_96.png" alt="logo" width="32" height="32" />
3
+ <img src="https://synvert.net/img/logo_96.png" alt="logo" width="32" height="32" />
4
4
 
5
5
  [![AwesomeCode Status for xinminlabs/synvert-core-ruby](https://awesomecode.io/projects/033f7f02-7b22-41c3-a902-fca37f1ec72a/status)](https://awesomecode.io/repos/xinminlabs/synvert-core-ruby)
6
6
  ![Main workflow](https://github.com/xinminlabs/synvert-core-ruby/actions/workflows/main.yml/badge.svg)
@@ -8,29 +8,46 @@
8
8
  Synvert core provides a set of DSLs to rewrite ruby code. e.g.
9
9
 
10
10
  ```ruby
11
- Synvert::Rewriter.new 'ruby', 'map_and_flatten_to_flat_map' do
11
+ Synvert::Rewriter.new 'factory_bot', 'convert_factory_girl_to_factory_bot' do
12
12
  description <<~EOS
13
- It converts `map` and `flatten` to `flat_map`
13
+ It converts FactoryGirl to FactoryBot
14
14
 
15
15
  ```ruby
16
- enum.map do
17
- # do something
18
- end.flatten
16
+ require 'factory_girl'
17
+ require 'factory_girl_rails'
19
18
  ```
20
19
 
21
20
  =>
22
21
 
23
22
  ```ruby
24
- enum.flat_map do
25
- # do something
26
- end
23
+ require 'factory_bot'
24
+ require 'factory_bot_rails'
25
+ ```
26
+
27
+ ```ruby
28
+ FactoryGirl.create(:user)
29
+ FactoryGirl.build(:user)
30
+ ```
31
+
32
+ =>
33
+
34
+ ```ruby
35
+ FactoryBot.create(:user)
36
+ FactoryBot.build(:user)
27
37
  ```
28
38
  EOS
29
39
 
30
- within_files Synvert::ALL_RUBY_FILES do
31
- with_node type: 'send', receiver: { type: 'block', caller: { type: 'send', message: 'map' } }, message: 'flatten', arguments: { size: 0 } do
32
- delete :message, :dot
33
- replace 'receiver.caller.message', with: 'flat_map'
40
+ within_files Synvert::RAILS_TEST_FILES do
41
+ find_node '.const[name=FactoryGirl]' do
42
+ replace_with 'FactoryBot'
43
+ end
44
+
45
+ find_node ".send[receiver=nil][message=require][arguments.size=1][arguments.first='factory_girl']" do
46
+ replace :arguments, with: "'factory_bot'"
47
+ end
48
+
49
+ with_node type: 'send', receiver: nil, message: 'require', arguments: { size: 1, first: "'factory_girl_rails'" } do
50
+ replace :arguments, with: "'factory_bot_rails'"
34
51
  end
35
52
  end
36
53
  end
@@ -56,6 +73,7 @@ DSLs are as follows
56
73
 
57
74
  Scopes:
58
75
 
76
+ * [find_node](./Synvert/Core/Rewriter/Instance.html#find_node-instance_method) - recursively find matching ast nodes by node query language
59
77
  * [within_node](./Synvert/Core/Rewriter/Instance.html#within_node-instance_method) - recursively find matching ast nodes
60
78
  * [with_node](./Synvert/Core/Rewriter/Instance.html#with_node-instance_method) - alias to within_node
61
79
  * [goto_node](./Synvert/Core/Rewriter/Instance.html#goto_node-instance_method) - go to a child node
data/Rakefile CHANGED
@@ -2,21 +2,7 @@
2
2
 
3
3
  require "bundler/gem_tasks"
4
4
  require 'rspec/core/rake_task'
5
- RSpec::Core::RakeTask.new(:spec)
6
- require 'oedipus_lex'
7
- Rake.application.rake_require "oedipus_lex"
8
-
9
- file "lib/synvert/core/node_query/lexer.rex.rb" => "lib/synvert/core/node_query/lexer.rex"
10
- file "lib/synvert/core/node_query/parser.racc.rb" => "lib/synvert/core/node_query/parser.y"
11
5
 
12
- task :lexer => "lib/synvert/core/node_query/lexer.rex.rb"
13
- task :parser => "lib/synvert/core/node_query/parser.racc.rb"
14
- task :generate => [:lexer, :parser]
15
-
16
- rule '.racc.rb' => '.y' do |t|
17
- cmd = "bundle exec racc -l -v -o #{t.name} #{t.source}"
18
- sh cmd
19
- end
6
+ RSpec::Core::RakeTask.new(:spec)
20
7
 
21
8
  task :default => :spec
22
- task :spec => :generate
@@ -7,7 +7,7 @@ module Synvert::Core
7
7
  ERUBY_EXPR_SPLITTER = '; ;'
8
8
  ERUBY_STMT_SPLITTER = '; ;'
9
9
 
10
- class ERB
10
+ class Erb
11
11
  class << self
12
12
  # convert erb to ruby code.
13
13
  #
@@ -3,6 +3,6 @@
3
3
  module Synvert::Core
4
4
  # Engine defines how to encode / decode other files (like erb).
5
5
  module Engine
6
- autoload :ERB, 'synvert/core/engine/erb'
6
+ autoload :Erb, 'synvert/core/engine/erb'
7
7
  end
8
8
  end