node_mutation 1.3.2 → 1.4.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 +10 -1
- data/Gemfile.lock +1 -1
- data/README.md +2 -0
- data/lib/node_mutation/action/noop_action.rb +24 -0
- data/lib/node_mutation/action.rb +0 -4
- data/lib/node_mutation/result.rb +6 -2
- data/lib/node_mutation/version.rb +1 -1
- data/lib/node_mutation.rb +6 -1
- data/sig/node_mutation/result.rbs +4 -0
- data/sig/node_mutation.rbs +2 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14bd090b6d48eddaf61babaf018060fd90c923fa6011c354060f916bdd67dc69
|
4
|
+
data.tar.gz: 19318b49488ccc6bc4db47fda0c78cdcd88b2df7f9a27acf27887772108e3470
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a73fe4094b0d71a06ddb12480c9f71e8fd3c49d845d8648a78e77c89eb59b4feeea963ba4ebbd58252135b32f5271a335f46942ed232be571b77b35ae8390d6b
|
7
|
+
data.tar.gz: 40588082698b6e0c8f3a891cd281e5bc9f571a43d1c3de71e63a8ae7489825329a236de14fb8eed1237c9d94840db00dd72671b6b5505adbe77165f65e7f5916
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
# NodeMutation
|
2
2
|
|
3
|
-
## 1.
|
3
|
+
## 1.4.0 (2022-09-20)
|
4
|
+
|
5
|
+
* Add `NoopAction`
|
6
|
+
|
7
|
+
## 1.3.3 (2022-09-16)
|
8
|
+
|
9
|
+
* Format `actions` in test result
|
10
|
+
* Add `file_path` attribute to `NodeMutation::Result`
|
11
|
+
|
12
|
+
## 1.3.2 (2022-09-15)
|
4
13
|
|
5
14
|
* Add `NodeMutation::Action.to_hash`
|
6
15
|
* Add `NodeMutation::Result.to_hash`
|
data/Gemfile.lock
CHANGED
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
|
data/lib/node_mutation/action.rb
CHANGED
data/lib/node_mutation/result.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class NodeMutation::Result
|
4
|
+
attr_accessor :file_path
|
5
|
+
|
4
6
|
def initialize(options)
|
5
7
|
@options = options
|
6
8
|
end
|
@@ -22,8 +24,10 @@ class NodeMutation::Result
|
|
22
24
|
end
|
23
25
|
|
24
26
|
def to_hash
|
25
|
-
|
26
|
-
|
27
|
+
hash = { file_path: file_path }
|
28
|
+
@options.each do |key, value|
|
29
|
+
hash[key] = value.is_a?(Array) ? value.map { |action| action.to_h } : value
|
27
30
|
end
|
31
|
+
hash
|
28
32
|
end
|
29
33
|
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
|
@@ -257,7 +258,7 @@ class NodeMutation
|
|
257
258
|
NodeMutation::Result.new(
|
258
259
|
affected: true,
|
259
260
|
conflicted: !conflict_actions.empty?,
|
260
|
-
actions: @actions
|
261
|
+
actions: format_actions(@actions)
|
261
262
|
)
|
262
263
|
end
|
263
264
|
|
@@ -283,4 +284,8 @@ class NodeMutation
|
|
283
284
|
end
|
284
285
|
conflict_actions
|
285
286
|
end
|
287
|
+
|
288
|
+
def format_actions(actions)
|
289
|
+
actions.map { |action| OpenStruct.new(start: action.start, end: action.end, new_code: action.new_code ) }
|
290
|
+
end
|
286
291
|
end
|
@@ -1,4 +1,6 @@
|
|
1
1
|
class NodeMutation::Result
|
2
|
+
attr_accessor file_path (): String
|
3
|
+
|
2
4
|
def initialize: (source: String) -> NodeMutation::Result
|
3
5
|
|
4
6
|
def affected?: () -> bool
|
@@ -6,4 +8,6 @@ class NodeMutation::Result
|
|
6
8
|
def conflicted?: () -> bool
|
7
9
|
|
8
10
|
def new_source: () -> String
|
11
|
+
|
12
|
+
def actions: () -> Array[Hash]
|
9
13
|
end
|
data/sig/node_mutation.rbs
CHANGED
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.
|
4
|
+
version: 1.4.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-09-
|
11
|
+
date: 2022-09-20 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
|