synvert-core 0.62.1 → 0.64.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -1
- data/Gemfile +0 -2
- data/README.md +73 -33
- data/lib/synvert/core/configuration.rb +12 -0
- data/lib/synvert/core/exceptions.rb +0 -4
- data/lib/synvert/core/node_ext.rb +206 -103
- data/lib/synvert/core/rewriter/action/append_action.rb +4 -3
- data/lib/synvert/core/rewriter/action/delete_action.rb +13 -6
- data/lib/synvert/core/rewriter/action/insert_action.rb +16 -7
- data/lib/synvert/core/rewriter/action/insert_after_action.rb +3 -2
- data/lib/synvert/core/rewriter/action/prepend_action.rb +3 -2
- data/lib/synvert/core/rewriter/action/remove_action.rb +16 -10
- data/lib/synvert/core/rewriter/action/replace_action.rb +13 -5
- data/lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb +18 -11
- data/lib/synvert/core/rewriter/action/replace_with_action.rb +6 -5
- data/lib/synvert/core/rewriter/action/wrap_action.rb +13 -5
- data/lib/synvert/core/rewriter/action.rb +20 -9
- data/lib/synvert/core/rewriter/any_value.rb +1 -0
- data/lib/synvert/core/rewriter/condition/if_exist_condition.rb +4 -0
- data/lib/synvert/core/rewriter/condition/if_only_exist_condition.rb +4 -0
- data/lib/synvert/core/rewriter/condition/unless_exist_condition.rb +4 -0
- data/lib/synvert/core/rewriter/condition.rb +11 -3
- data/lib/synvert/core/rewriter/gem_spec.rb +7 -4
- data/lib/synvert/core/rewriter/helper.rb +2 -2
- data/lib/synvert/core/rewriter/instance.rb +195 -94
- data/lib/synvert/core/rewriter/ruby_version.rb +4 -4
- data/lib/synvert/core/rewriter/scope/goto_scope.rb +5 -6
- data/lib/synvert/core/rewriter/scope/within_scope.rb +9 -4
- data/lib/synvert/core/rewriter/scope.rb +8 -0
- data/lib/synvert/core/rewriter/warning.rb +1 -1
- data/lib/synvert/core/rewriter.rb +90 -43
- data/lib/synvert/core/version.rb +1 -1
- data/lib/synvert/core.rb +0 -1
- data/spec/spec_helper.rb +0 -3
- data/spec/synvert/core/node_ext_spec.rb +28 -7
- data/spec/synvert/core/rewriter/action_spec.rb +0 -4
- data/spec/synvert/core/rewriter/gem_spec_spec.rb +11 -10
- data/spec/synvert/core/rewriter/instance_spec.rb +7 -17
- data/synvert-core-ruby.gemspec +2 -1
- metadata +21 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea27da2bceb8ec0f2dd837e5aa80135860a2539c7e49170b2bd46af227d1043e
|
4
|
+
data.tar.gz: a901be4a294000eecfbbbf407416015cd9b38499ebc24c744147aebdeba5388f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9d0451d59718fe04e23d48a90e7e705fb455592d2636055064d9c5d7f6a1db20980ff1a38b147d77b16fdc8b059b95a8a95848c183a4115ddb1730541bf0757
|
7
|
+
data.tar.gz: 63246572cc0d9c3d44d7bb12f6d716e11b15fd1978376588e235a4c2f9b5e7849962ed4a81e38bd1a9f74c2cb877325148c486c9f3045ebf8c0aa80459d9b6aa
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,16 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
-
## 0.
|
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
data/README.md
CHANGED
@@ -5,36 +5,76 @@
|
|
5
5
|

|
6
6
|
[](http://badge.fury.io/rb/synvert-core)
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
[
|
40
|
-
|
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
|