node_mutation 1.3.3 → 1.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 544ec86ce71f51dab3347896a749a64d1d18f97a5d353f1e870c0396ff825dee
4
- data.tar.gz: e366ae9c9eb0786111839a38bb27552bdf5177d6bfcf5b097900eb096553be2a
3
+ metadata.gz: c039ce434de2c9f04450657464f649b1005851b3beaacc83be674833a0756ffa
4
+ data.tar.gz: e2e64db507b3099dc2f8709b0c6eb5f0cfb990ad1f5c2061eab8666212306a3a
5
5
  SHA512:
6
- metadata.gz: d5a2d40616eb991bcd38aef704ba656408659acb7460c33417bfa994e7f070d2863ad71ae6c8ebc72958f90dec1dbe3703ac9d2c42f9ba96001bc1a4a0b0a891
7
- data.tar.gz: 308f7faedca3bab04cd0866b1f862aad144fd580042ee82fe0ad8773bbe5f2e7a2adaa2cfcd0f8d29e4d0f221238ae655e5c37f7a282cb9edc9f78d5fb28e1eb
6
+ metadata.gz: ff18089505355b7527c220ce0ed22ba84f7bef3e4789deb656a9dfe49b962c984e313bc1ade369bcf6ba01006ff2dd102f38e319a06b77a38522fecc5b2dba22
7
+ data.tar.gz: 8feb7df10f01fffa63af2b913f129a95c55ba81af0446aaeea6a1282e1c1f1ee6648f812acce635b09cf2905def86227c42dbc92bc0b8e80fa7f54cc5e04530b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # NodeMutation
2
2
 
3
+ ## 1.4.1 (2022-09-23)
4
+
5
+ * Add `NodeMutation#noop`
6
+
7
+ ## 1.4.0 (2022-09-20)
8
+
9
+ * Add `NoopAction`
10
+
3
11
  ## 1.3.3 (2022-09-16)
4
12
 
5
13
  * Format `actions` in test result
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- node_mutation (1.3.3)
4
+ node_mutation (1.4.1)
5
5
  activesupport (< 7.0.0)
6
6
  erubis
7
7
 
data/README.md CHANGED
@@ -49,6 +49,8 @@ mutation.replace node, :message, with: 'test'
49
49
  mutation.replace_with node, 'create {{arguments}}'
50
50
  # wrap node within a block, class or module
51
51
  mutation.wrap node, with: 'module Foo'
52
+ # no operation
53
+ mutation.noop
52
54
  ```
53
55
 
54
56
  3. process actions and write the new source code to file:
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # NoopAction to do no operation.
4
+ class NodeMutation::NoopAction < NodeMutation::Action
5
+ # Create a NoopAction
6
+ def initialize(node)
7
+ super(node, nil)
8
+ end
9
+
10
+ # The rewritten source code with proper indent.
11
+ #
12
+ # @return [String] rewritten code.
13
+ def new_code
14
+ return nil
15
+ end
16
+
17
+ private
18
+
19
+ # Calculate the begin the end positions.
20
+ def calculate_position
21
+ @start = NodeMutation.adapter.get_start(@node)
22
+ @end = NodeMutation.adapter.get_end(@node)
23
+ end
24
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class NodeMutation
4
- VERSION = "1.3.3"
4
+ VERSION = "1.4.1"
5
5
  end
data/lib/node_mutation.rb CHANGED
@@ -24,6 +24,7 @@ class NodeMutation
24
24
  autoload :ReplaceAction, 'node_mutation/action/replace_action'
25
25
  autoload :ReplaceWithAction, 'node_mutation/action/replace_with_action'
26
26
  autoload :WrapAction, 'node_mutation/action/wrap_action'
27
+ autoload :NoopAction, 'node_mutation/action/noop_action'
27
28
  autoload :Result, 'node_mutation/result'
28
29
 
29
30
  attr_reader :actions
@@ -207,6 +208,12 @@ class NodeMutation
207
208
  @actions << WrapAction.new(node, with: with).process
208
209
  end
209
210
 
211
+ # No operation.
212
+ # @param node [Node] ast node
213
+ def noop(node)
214
+ @actions << NoopAction.new(node).process
215
+ end
216
+
210
217
  # Process actions and return the new source.
211
218
  #
212
219
  # If there's an action range conflict,
@@ -39,6 +39,8 @@ module NodeMutation[T]
39
39
 
40
40
  def wrap: (node: T, with: String) -> void
41
41
 
42
+ def noop: (node: T) -> void
43
+
42
44
  def process: () -> NodeMutation::Result
43
45
 
44
46
  def test: () -> NodeMutation::Result
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: node_mutation
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 1.4.1
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-09-16 00:00:00.000000000 Z
11
+ date: 2022-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -59,6 +59,7 @@ files:
59
59
  - lib/node_mutation/action/delete_action.rb
60
60
  - lib/node_mutation/action/insert_action.rb
61
61
  - lib/node_mutation/action/insert_after_action.rb
62
+ - lib/node_mutation/action/noop_action.rb
62
63
  - lib/node_mutation/action/prepend_action.rb
63
64
  - lib/node_mutation/action/remove_action.rb
64
65
  - lib/node_mutation/action/replace_action.rb