node_mutation 1.8.1 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e468a837b5ab1417a0675f92ae5848b87b66cfe9605a3ce56142f58859ba7036
4
- data.tar.gz: 898a9e080a406c84027b3ea84bf76826c8deb2ea36c406a767774c7610809dea
3
+ metadata.gz: 36b238099da8793f4d2e9df6c5e679ba4d4f7da2254c020606d73dfd93f3baf8
4
+ data.tar.gz: b44fbf6192513de334c03580a04b8fe30602697a2d8f7fc39a96f5776c046739
5
5
  SHA512:
6
- metadata.gz: 40498dd85e42e77268ed72851692c906221e2ea167765867155a30c0e992b6e4a8c4e89cfee7295743dd94f6d3405dcaeabeb845be3a3dc1a7cb473983ba6bf2
7
- data.tar.gz: f99ba22c58428b002285e9dd6e959b993725216265457d2df8a4b7fd934537861ca04ce6955bedc8dea0fb29efb0174e44a53a7ae6e07c9aad2e68daa2dab154
6
+ metadata.gz: cbfb8d677df7896754afddf23e3fa880f6d6f16d646c9a93881b4e216c1a2adf83c4ba45a96dd4827aeb9800ea375ba5dd992a815bf2794e1b5d11206b956415
7
+ data.tar.gz: 3a0c2217d7b51a90bd2818a036e07b76f2e2df82295f5bed462e075198855325285513e344d97cc70ac0179b1fa6a77ca13f25558f12f0db982903cc52a65318
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # NodeMutation
2
2
 
3
+ ## 1.9.0 (2023-02-08)
4
+
5
+ * Configure `tab_width`
6
+ * Make use of `NodeMutation.tab_width`
7
+
8
+ ## 1.8.2 (2023-01-17)
9
+
10
+ * Drop `activesupport`
11
+
3
12
  ## 1.8.1 (2022-12-26)
4
13
 
5
14
  * `child_node_by_name` index starts from `0`
data/Gemfile.lock CHANGED
@@ -1,22 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- node_mutation (1.8.1)
5
- activesupport (< 7.0.0)
4
+ node_mutation (1.9.0)
6
5
  erubis
7
6
 
8
7
  GEM
9
8
  remote: https://rubygems.org/
10
9
  specs:
11
- activesupport (6.1.7)
12
- concurrent-ruby (~> 1.0, >= 1.0.2)
13
- i18n (>= 1.6, < 2)
14
- minitest (>= 5.1)
15
- tzinfo (~> 2.0)
16
- zeitwerk (~> 2.3)
17
10
  ast (2.4.2)
18
11
  coderay (1.1.3)
19
- concurrent-ruby (1.1.10)
20
12
  diff-lcs (1.5.0)
21
13
  erubis (2.7.0)
22
14
  ffi (1.15.5)
@@ -35,14 +27,11 @@ GEM
35
27
  guard (~> 2.1)
36
28
  guard-compat (~> 1.1)
37
29
  rspec (>= 2.99.0, < 4.0)
38
- i18n (1.12.0)
39
- concurrent-ruby (~> 1.0)
40
30
  listen (3.7.1)
41
31
  rb-fsevent (~> 0.10, >= 0.10.3)
42
32
  rb-inotify (~> 0.9, >= 0.9.10)
43
33
  lumberjack (1.2.8)
44
34
  method_source (1.0.0)
45
- minitest (5.16.3)
46
35
  nenv (0.3.0)
47
36
  notiffany (0.1.3)
48
37
  nenv (~> 0.1)
@@ -73,9 +62,6 @@ GEM
73
62
  rspec-support (3.11.0)
74
63
  shellany (0.0.1)
75
64
  thor (1.2.1)
76
- tzinfo (2.0.5)
77
- concurrent-ruby (~> 1.0)
78
- zeitwerk (2.6.6)
79
65
 
80
66
  PLATFORMS
81
67
  x86_64-darwin-21
data/README.md CHANGED
@@ -63,14 +63,34 @@ result.conflicted
63
63
  result.new_source
64
64
  ```
65
65
 
66
- ## Write Adapter
66
+ ## Configuration
67
+
68
+ ### adapter
67
69
 
68
70
  Different parsers, like parse and ripper, will generate different AST nodes, to make NodeMutation work for them all,
69
71
  we define an [Adapter](https://github.com/xinminlabs/node-mutation-ruby/blob/main/lib/node_mutation/adapter.rb) interface,
70
72
  if you implement the Adapter interface, you can set it as NodeMutation's adapter.
71
73
 
72
- ```typescript
73
- NodeMutation.configure({ adapter: ParserAdapter.new })
74
+ ```ruby
75
+ NodeMutation.configure(adapter: ParserAdapter.new) // default is ParserAdapter
76
+ ```
77
+
78
+ ### strategy
79
+
80
+ It provides 3 strategies to handle conflicts when processing actions:
81
+
82
+ 1. `Strategy.KEEP_RUNNING`: keep running and ignore the conflict action.
83
+ 2. `Strategy.THROW_ERROR`: throw error when conflict action is found.
84
+ 3. `Strategy.ALLOW_INSERT_AT_SAME_POSITION`: allow insert action at the same position.
85
+
86
+ ```ruby
87
+ NodeMutation.configure(strategy: Strategy.KEEP_RUNNING | Strategy.ALLOW_INSERT_AT_SAME_POSITION); // default is Strategy.THROW_ERROR
88
+ ```
89
+
90
+ ### tab_width
91
+
92
+ ```ruby
93
+ NodeMutation.configure(tab_width: 4); // default is 2
74
94
  ```
75
95
 
76
96
  ## Development
@@ -17,6 +17,6 @@ class NodeMutation::AppendAction < NodeMutation::Action
17
17
  # @param node [Parser::AST::Node]
18
18
  # @return [String] n times whitesphace
19
19
  def indent(node)
20
- ' ' * (NodeMutation.adapter.get_start_loc(node).column + DEFAULT_INDENT)
20
+ ' ' * (NodeMutation.adapter.get_start_loc(node).column + NodeMutation.tab_width)
21
21
  end
22
22
  end
@@ -20,6 +20,6 @@ class NodeMutation::PrependAction < NodeMutation::Action
20
20
  # @param node [Parser::AST::Node]
21
21
  # @return [String] n times whitesphace
22
22
  def indent(node)
23
- ' ' * (NodeMutation.adapter.get_start_loc(node).column + DEFAULT_INDENT)
23
+ ' ' * (NodeMutation.adapter.get_start_loc(node).column + NodeMutation.tab_width)
24
24
  end
25
25
  end
@@ -2,8 +2,6 @@
2
2
 
3
3
  # Action defines rewriter action, insert, replace or delete code.
4
4
  class NodeMutation::Action
5
- DEFAULT_INDENT = 2
6
-
7
5
  # @!attribute [r] start
8
6
  # @return [Integer] start position
9
7
  # @!attribute [r] end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class NodeMutation
4
- VERSION = "1.8.1"
4
+ VERSION = "1.9.0"
5
5
  end
data/lib/node_mutation.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'ostruct'
4
- require 'active_support/core_ext/array'
5
4
 
6
5
  require_relative "node_mutation/version"
7
6
 
@@ -26,29 +25,42 @@ class NodeMutation
26
25
 
27
26
  attr_reader :actions
28
27
 
29
- # Configure NodeMutation
30
- # @param [Hash] options options to configure
31
- # @option options [NodeMutation::Adapter] :adapter the adpater
32
- def self.configure(options)
33
- if options[:adapter]
34
- @adapter = options[:adapter]
28
+ class <<self
29
+ # Configure NodeMutation
30
+ # @param [Hash] options options to configure
31
+ # @option options [NodeMutation::Adapter] :adapter the adpater
32
+ # @option options [NodeMutation::Strategy] :strategy the strategy
33
+ # @option options [Integer] :tab_width the tab width
34
+ def configure(options)
35
+ if options[:adapter]
36
+ @adapter = options[:adapter]
37
+ end
38
+ if options[:strategy]
39
+ @strategy = options[:strategy]
40
+ end
41
+ if options[:tab_width]
42
+ @tab_width = options[:tab_width]
43
+ end
35
44
  end
36
- if options[:strategy]
37
- @strategy = options[:strategy]
45
+
46
+ # Get the adapter
47
+ # @return [NodeMutation::Adapter] current adapter, by default is {NodeMutation::ParserAdapter}
48
+ def adapter
49
+ @adapter ||= ParserAdapter.new
38
50
  end
39
- end
40
51
 
41
- # Get the adapter
42
- # @return [NodeMutation::Adapter] current adapter, by default is {NodeMutation::ParserAdapter}
43
- def self.adapter
44
- @adapter ||= ParserAdapter.new
45
- end
52
+ # Get the strategy
53
+ # @return [Integer] current strategy, could be {NodeMutation::Strategy::KEEP_RUNNING} or {NodeMutation::Strategy::THROW_ERROR},
54
+ # by default is {NodeMutation::Strategy::KEEP_RUNNING}
55
+ def strategy
56
+ @strategy ||= Strategy::KEEP_RUNNING
57
+ end
46
58
 
47
- # Get the strategy
48
- # @return [Integer] current strategy, could be {NodeMutation::Strategy::KEEP_RUNNING} or {NodeMutation::Strategy::THROW_ERROR},
49
- # by default is {NodeMutation::Strategy::KEEP_RUNNING}
50
- def self.strategy
51
- @strategy ||= Strategy::KEEP_RUNNING
59
+ # Get tab width
60
+ # @return [Integer] tab width, by default is 2
61
+ def tab_width
62
+ @tab_width ||= 2
63
+ end
52
64
  end
53
65
 
54
66
  # Initialize a NodeMutation.
@@ -29,7 +29,6 @@ Gem::Specification.new do |spec|
29
29
  spec.require_paths = ["lib"]
30
30
 
31
31
  # Uncomment to register a new dependency of your gem
32
- spec.add_dependency "activesupport", "< 7.0.0"
33
32
  spec.add_dependency "erubis"
34
33
 
35
34
  # For more information and examples about making a new gem, check out our
@@ -13,12 +13,14 @@ module NodeMutation[T]
13
13
 
14
14
  attr_reader actions: Array[NodeMutation::Action]
15
15
 
16
- def self.configure: (options: { adapter: NodeMutation::Adapter, strategy: Integer }) -> void
16
+ def self.configure: (options: { adapter: NodeMutation::Adapter, strategy: Integer, tab_width: Integer }) -> void
17
17
 
18
18
  def self.adapter: () -> NodeMutation::Adapter
19
19
 
20
20
  def self.strategy: () -> Integer
21
21
 
22
+ def self.tab_width: () -> Integer
23
+
22
24
  def initialize: (source: String) -> NodeMutation
23
25
 
24
26
  def append: (node: T, code: String) -> void
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: node_mutation
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.1
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-26 00:00:00.000000000 Z
11
+ date: 2023-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: activesupport
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "<"
18
- - !ruby/object:Gem::Version
19
- version: 7.0.0
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "<"
25
- - !ruby/object:Gem::Version
26
- version: 7.0.0
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: erubis
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -96,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
82
  - !ruby/object:Gem::Version
97
83
  version: '0'
98
84
  requirements: []
99
- rubygems_version: 3.3.26
85
+ rubygems_version: 3.4.1
100
86
  signing_key:
101
87
  specification_version: 4
102
88
  summary: ast node mutation apis