synvert-core 0.62.1 → 0.64.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -1
  3. data/Gemfile +0 -2
  4. data/README.md +73 -33
  5. data/lib/synvert/core/configuration.rb +12 -0
  6. data/lib/synvert/core/exceptions.rb +0 -4
  7. data/lib/synvert/core/node_ext.rb +206 -103
  8. data/lib/synvert/core/rewriter/action/append_action.rb +4 -3
  9. data/lib/synvert/core/rewriter/action/delete_action.rb +13 -6
  10. data/lib/synvert/core/rewriter/action/insert_action.rb +16 -7
  11. data/lib/synvert/core/rewriter/action/insert_after_action.rb +3 -2
  12. data/lib/synvert/core/rewriter/action/prepend_action.rb +3 -2
  13. data/lib/synvert/core/rewriter/action/remove_action.rb +16 -10
  14. data/lib/synvert/core/rewriter/action/replace_action.rb +13 -5
  15. data/lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb +18 -11
  16. data/lib/synvert/core/rewriter/action/replace_with_action.rb +6 -5
  17. data/lib/synvert/core/rewriter/action/wrap_action.rb +13 -5
  18. data/lib/synvert/core/rewriter/action.rb +20 -9
  19. data/lib/synvert/core/rewriter/any_value.rb +1 -0
  20. data/lib/synvert/core/rewriter/condition/if_exist_condition.rb +4 -0
  21. data/lib/synvert/core/rewriter/condition/if_only_exist_condition.rb +4 -0
  22. data/lib/synvert/core/rewriter/condition/unless_exist_condition.rb +4 -0
  23. data/lib/synvert/core/rewriter/condition.rb +11 -3
  24. data/lib/synvert/core/rewriter/gem_spec.rb +7 -4
  25. data/lib/synvert/core/rewriter/helper.rb +2 -2
  26. data/lib/synvert/core/rewriter/instance.rb +195 -94
  27. data/lib/synvert/core/rewriter/ruby_version.rb +4 -4
  28. data/lib/synvert/core/rewriter/scope/goto_scope.rb +5 -6
  29. data/lib/synvert/core/rewriter/scope/within_scope.rb +9 -4
  30. data/lib/synvert/core/rewriter/scope.rb +8 -0
  31. data/lib/synvert/core/rewriter/warning.rb +1 -1
  32. data/lib/synvert/core/rewriter.rb +90 -43
  33. data/lib/synvert/core/version.rb +1 -1
  34. data/lib/synvert/core.rb +0 -1
  35. data/spec/spec_helper.rb +0 -3
  36. data/spec/synvert/core/node_ext_spec.rb +28 -7
  37. data/spec/synvert/core/rewriter/action_spec.rb +0 -4
  38. data/spec/synvert/core/rewriter/gem_spec_spec.rb +11 -10
  39. data/spec/synvert/core/rewriter/instance_spec.rb +7 -17
  40. data/synvert-core-ruby.gemspec +2 -1
  41. metadata +21 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79777679e6001f32c8b4bc587e2f007f396eeecd9c0c7e29926e01a3628b4244
4
- data.tar.gz: df4d3eda62e9b2f49ec1cf8da96bd98952d7d5af70fd4d6861b206bbc923cca9
3
+ metadata.gz: ea27da2bceb8ec0f2dd837e5aa80135860a2539c7e49170b2bd46af227d1043e
4
+ data.tar.gz: a901be4a294000eecfbbbf407416015cd9b38499ebc24c744147aebdeba5388f
5
5
  SHA512:
6
- metadata.gz: c9744e62dc972253304018ac041aa1f4cd01efd8a80a207a77145e088d4d69713ef4ec10ade9fe4d251811b6a8166d8e33b575ea91265fbec4f989a9e29ac376
7
- data.tar.gz: cad73e2d256e25370b535a0f623fee47c02f4d5a56e3feaed50f81a798cf3c1dbb0ffd4d6ad04ab167be78fc390703a2a01f0377b79ea621f1674399aa2c7534
6
+ metadata.gz: b9d0451d59718fe04e23d48a90e7e705fb455592d2636055064d9c5d7f6a1db20980ff1a38b147d77b16fdc8b059b95a8a95848c183a4115ddb1730541bf0757
7
+ data.tar.gz: 63246572cc0d9c3d44d7bb12f6d716e11b15fd1978376588e235a4c2f9b5e7849962ed4a81e38bd1a9f74c2cb877325148c486c9f3045ebf8c0aa80459d9b6aa
data/CHANGELOG.md CHANGED
@@ -1,8 +1,16 @@
1
1
  # CHANGELOG
2
2
 
3
- ## 0.62.1 (2022-01-14)
3
+ ## 0.64.0 (2022-04-02)
4
+
5
+ * Read absolute path of Gemfile.lock
6
+ * Remove unused `Node#to_s`
7
+ * Yardoc comments
8
+ * Drop `within_direct_node(rules)`, use `within_node(rules, { direct: true })` instead
9
+
10
+ ## 0.63.0 (2022-02-26)
4
11
 
5
12
  * Add `to` option to `InsertAction`
13
+ * Add `gt`, `gte`, `lt` and `lte` rules
6
14
 
7
15
  ## 0.62.0 (2021-12-24)
8
16
 
data/Gemfile CHANGED
@@ -4,5 +4,3 @@ source 'https://rubygems.org'
4
4
 
5
5
  # Specify your gem's dependencies in synvert.gemspec
6
6
  gemspec
7
-
8
- gem 'coveralls', require: false
data/README.md CHANGED
@@ -5,36 +5,76 @@
5
5
  ![Main workflow](https://github.com/xinminlabs/synvert-core-ruby/actions/workflows/main.yml/badge.svg)
6
6
  [![Gem Version](https://badge.fury.io/rb/synvert-core.png)](http://badge.fury.io/rb/synvert-core)
7
7
 
8
- synvert-core-ruby provides a dsl to convert ruby source code.
9
-
10
- ## Installation
11
-
12
- Add this line to your application's Gemfile:
13
-
14
- gem 'synvert-core'
15
-
16
- And then execute:
17
-
18
- $ bundle
19
-
20
- Or install it yourself as:
21
-
22
- $ gem install synvert-core
23
-
24
-
25
- ## Documentation
26
-
27
- [Website][1]
28
-
29
- [RDoc][2]
30
-
31
- ## Contributing
32
-
33
- 1. Fork it ( https://github.com/[my-github-username]/synvert-core-ruby/fork )
34
- 2. Create your feature branch (`git checkout -b my-new-feature`)
35
- 3. Commit your changes (`git commit -am 'Add some feature'`)
36
- 4. Push to the branch (`git push origin my-new-feature`)
37
- 5. Create a new Pull Request
38
-
39
- [1]: https://synvert.xinminlabs.com
40
- [2]: https://rubydoc.info/github/xinminlabs/synvert-core-ruby/master/frames
8
+ Synvert core provides a set of DSLs to rewrite ruby code. e.g.
9
+
10
+ ```ruby
11
+ Synvert::Rewriter.new 'ruby', 'map_and_flatten_to_flat_map' do
12
+ description <<~EOS
13
+ It converts `map` and `flatten` to `flat_map`
14
+
15
+ ```ruby
16
+ enum.map do
17
+ # do something
18
+ end.flatten
19
+ ```
20
+
21
+ =>
22
+
23
+ ```ruby
24
+ enum.flat_map do
25
+ # do something
26
+ end
27
+ ```
28
+ EOS
29
+
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'
34
+ end
35
+ end
36
+ end
37
+ ```
38
+
39
+ Want to see more examples, check out [synvert-snippets-ruby](https://github.com/xinminlabs/synvert-snippets-ruby).
40
+
41
+ Want to use the CLI, check out [synvert-ruby](https://github.com/xinminlabs/synvert-ruby).
42
+
43
+ DSLs are as follows
44
+
45
+ * [description](./Synvert/Core/Rewriter.html#description-instance_method) - set description of the rewriter
46
+ * [if_ruby](./Synvert/Core/Rewriter.html#if_ruby-instance_method) - check if ruby version is greater than or equal to the specified ruby version
47
+ * [if_gem](./Synvert/Core/Rewriter.html#if_gem-instance_method) - compare version of specified gem
48
+ * [within_files](./Synvert/Core/Rewriter.html#within_files-instance_method) - find specified files
49
+ * [within_file](./Synvert/Core/Rewriter.html#within_file-instance_method) - alias to within_files
50
+ * [add_file](./Synvert/Core/Rewriter.html#add_file-instance_method) - add a new file
51
+ * [remove_file](./Synvert/Core/Rewriter.html#remove_file-instance_method) - remove a file
52
+ * [helper_method](./Synvert/Core/Rewriter.html#helper_method-instance_method) - define a helper method
53
+ * [add_snippet](./Synvert/Core/Rewriter.html#add_snippet-instance_method) - call another rewriter
54
+ * [todo](./Synvert/Core/Rewriter.html#todo-instance_method) - set todo
55
+ * [redo_until_no_change](./Synvert/Core/Rewriter.html#redo_until_no_change-instance_method) - run the snippet until no change
56
+
57
+ Scopes:
58
+
59
+ * [within_node](./Synvert/Core/Rewriter/Instance.html#within_node-instance_method) - recursively find matching ast nodes
60
+ * [with_node](./Synvert/Core/Rewriter/Instance.html#with_node-instance_method) - alias to within_node
61
+ * [goto_node](./Synvert/Core/Rewriter/Instance.html#goto_node-instance_method) - go to a child node
62
+
63
+ Conditions:
64
+
65
+ * [if_exist_node](./Synvert/Core/Rewriter/Instance.html#if_exist_node-instance_method) - check if matching node exist in the child nodes
66
+ * [unless_exist_node](./Synvert/Core/Rewriter/Instance.html#unless_exist_node-instance_method) - check if matching node doesn't exist in the child nodes
67
+ * [if_only_exist_node](./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 rules
68
+
69
+ Actions:
70
+
71
+ * [append](./Synvert/Core/Rewriter/Instance.html#append-instance_method) - append the code to the bottom of current node body
72
+ * [prepend](./Synvert/Core/Rewriter/Instance.html#prepend-instance_method) - prepend the code to the bottom of current node body
73
+ * [insert](./Synvert/Core/Rewriter/Instance.html#insert-instance_method) - insert code
74
+ * [insert_after](./Synvert/Core/Rewriter/Instance.html#insert_after-instance_method) - insert the code next to the current node
75
+ * [replace](./Synvert/Core/Rewriter/Instance.html#replace-instance_method) - replace the code of specified child nodes
76
+ * [delete](./Synvert/Core/Rewriter/Instance.html#delete-instance_method) - delete the code specified child nodes
77
+ * [wrap](./Synvert/Core/Rewriter/Instance.html#wrap-instance_method) - wrap the current node with code
78
+ * [replace_with](./Synvert/Core/Rewriter/Instance.html#replace_with-instance_method) - replace the whole code of current node
79
+ * [warn](./Synvert/Core/Rewriter/Instance.html#warn-instance_method) - warn message
80
+ * [replace_erb_stmt_with_expr](./Synvert/Core/Rewriter/Instance.html#replace_erb_stmt_with_expr-instance_method) - replace erb stmt code to expr code
@@ -4,16 +4,28 @@ module Synvert::Core
4
4
  # Synvert global configuration.
5
5
  class Configuration
6
6
  class << self
7
+ # @!attribute [w] path
8
+ # @!attribute [w] skip_files
9
+ # @!attribute [w] show_run_process
7
10
  attr_writer :path, :skip_files, :show_run_process
8
11
 
12
+ # Get the path.
13
+ #
14
+ # @return [String] default is '.'
9
15
  def path
10
16
  @path || '.'
11
17
  end
12
18
 
19
+ # Get a list of skip files.
20
+ #
21
+ # @return [Array<String>] default is [].
13
22
  def skip_files
14
23
  @skip_files || []
15
24
  end
16
25
 
26
+ # Check if show run process.
27
+ #
28
+ # @return [Boolean] default is false
17
29
  def show_run_process
18
30
  @show_run_process || false
19
31
  end
@@ -5,10 +5,6 @@ module Synvert::Core
5
5
  class RewriterNotFound < RuntimeError
6
6
  end
7
7
 
8
- # Gemfile.lock not found exception.
9
- class GemfileLockNotFound < RuntimeError
10
- end
11
-
12
8
  # Method not supported exception.
13
9
  class MethodNotSupported < RuntimeError
14
10
  end