node_mutation 1.18.1 → 1.18.3

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: 402162b36464bad6b051c2d55da7e59cae24f3f92963bed6ae3610ab8529c52b
4
- data.tar.gz: e0a9fc2d5a8af6d700daf7d4a1a134c17e30ad34e079386360caef12c93633cf
3
+ metadata.gz: f841956c32adce81a0124670b81a180dc1a5c607946de843ee4ffb18df46eb59
4
+ data.tar.gz: 1f962b025780338e39f674d1a130a42ab85b7ed499630e77151ffb8cf8fcfbdc
5
5
  SHA512:
6
- metadata.gz: aa89ffef035a9d5aca4cc2e8b68c6e2179ac6d228fd06e0805395f5a3cd447c49a249ba96a7910438a9b1a5faf5bb3a9f325126db87f8f4cd45dcac43cdbdc60
7
- data.tar.gz: d303b85ef1f0b884e8b88f8fa9cb7547e9bf7bd3d619f5587e793affd68509447dddc6323f7a090cbaa55fbe7be8535df9fec2462aa6b43499eee868a3a53fbf
6
+ metadata.gz: a67239ac105f6ba64aa52a67c228310e4b13a8b2f0076343f006faf562c0a4cf00d3eb83212fdd75d3c63421c8763a67a1afb2c067dceaf9e1fcd25d8fb935e5
7
+ data.tar.gz: 0b6c56d6114b997743a33e96c19976ceb9cdc15c0e1b515acf092e1275149c5ddb93359707700cca9b274decf1e73690ed12b23c8280eccda1500e9a5e88ccf4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # NodeMutation
2
2
 
3
+ ## 1.18.3 (2023-06-03)
4
+
5
+ * Fix rbs syntax
6
+
7
+ ## 1.18.2 (2023-05-21)
8
+
9
+ * Use `rindex` to calculate "do" index
10
+
3
11
  ## 1.18.1 (2023-05-20)
4
12
 
5
13
  * Support block/class/def/defs/module `body` in `child_node_range`
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- node_mutation (1.18.1)
4
+ node_mutation (1.18.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -17,7 +17,8 @@ class NodeMutation::IndentAction < NodeMutation::Action
17
17
  # @return [String] rewritten code.
18
18
  def new_code
19
19
  source = NodeMutation.adapter.get_source(@node)
20
- source.each_line.map { |line| ' ' * NodeMutation.tab_width * @tab_size + line }.join
20
+ source.each_line.map { |line| (' ' * NodeMutation.tab_width * @tab_size) + line }
21
+ .join
21
22
  end
22
23
 
23
24
  private
@@ -9,14 +9,12 @@ class NodeMutation::PrependAction < NodeMutation::Action
9
9
 
10
10
  private
11
11
 
12
- DO_LENGTH = ' do'.length
13
-
14
12
  # Calculate the begin and end positions.
15
13
  def calculate_position
16
14
  node_start = NodeMutation.adapter.get_start(@node)
17
15
  node_source = NodeMutation.adapter.get_source(@node)
18
16
  first_line = node_source.split("\n").first
19
- @start = first_line.end_with?("do") ? node_start + first_line.index("do") + "do".length : node_start + first_line.length
17
+ @start = first_line.end_with?("do") ? node_start + first_line.rindex("do") + "do".length : node_start + first_line.length
20
18
  @end = @start
21
19
  end
22
20
 
@@ -106,7 +106,9 @@ class NodeMutation::ParserAdapter < NodeMutation::Adapter
106
106
  node.body.last.loc.expression.end_pos
107
107
  )
108
108
  end
109
- when %i[class name], %i[const name], %i[cvar name], %i[def name], %i[defs name], %i[gvar name], %i[ivar name], %i[lvar name]
109
+ when %i[class name], %i[const name], %i[cvar name], %i[def name], %i[defs name],
110
+ %i[gvar name], %i[ivar name], %i[lvar name]
111
+
110
112
  NodeMutation::Struct::Range.new(node.loc.name.begin_pos, node.loc.name.end_pos)
111
113
  when %i[const double_colon]
112
114
  NodeMutation::Struct::Range.new(node.loc.double_colon.begin_pos, node.loc.double_colon.end_pos)
@@ -19,7 +19,10 @@ class NodeMutation::Result
19
19
  end
20
20
 
21
21
  def actions=(actions)
22
- @actions = actions.map { |action| NodeMutation::Struct::Action.new(action.type, action.start, action.end, action.new_code) }
22
+ @actions =
23
+ actions.map { |action|
24
+ NodeMutation::Struct::Action.new(action.type, action.start, action.end, action.new_code)
25
+ }
23
26
  end
24
27
 
25
28
  def to_json(*args)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class NodeMutation
4
- VERSION = "1.18.1"
4
+ VERSION = "1.18.3"
5
5
  end
data/lib/node_mutation.rb CHANGED
@@ -208,8 +208,8 @@ class NodeMutation
208
208
  def wrap(node, prefix:, suffix:, newline: false)
209
209
  if newline
210
210
  indentation = NodeMutation.adapter.get_start_loc(node).column
211
- @actions << InsertAction.new(node, prefix + "\n" + ' ' * indentation, at: 'beginning').process
212
- @actions << InsertAction.new(node, "\n" + ' ' * indentation + suffix, at: 'end').process
211
+ @actions << InsertAction.new(node, prefix + "\n" + (' ' * indentation), at: 'beginning').process
212
+ @actions << InsertAction.new(node, "\n" + (' ' * indentation) + suffix, at: 'end').process
213
213
  @actions << IndentAction.new(node).process
214
214
  else
215
215
  @actions << InsertAction.new(node, prefix, at: 'beginning').process
@@ -1,18 +1,18 @@
1
1
  class NodeMutation::Struct
2
2
  class Action < ::Struct
3
- prop :type, Symbol
4
- prop :start, Integer
5
- prop :end, Integer
6
- prop :new_code, String
3
+ atr_accessor type (): Symbol
4
+ atr_accessor start (): Integer
5
+ atr_accessor end (): Integer
6
+ atr_accessor new_code (): String
7
7
  end
8
8
 
9
9
  class Location < ::Struct
10
- prop :line, Integer
11
- prop :column, Integer
10
+ atr_accessor line (): Integer
11
+ atr_accessor column (): Integer
12
12
  end
13
13
 
14
14
  class Range < ::Struct
15
- prop :start, Integer
16
- prop :end, Integer
15
+ atr_accessor start (): Integer
16
+ atr_accessor end (): Integer
17
17
  end
18
18
  end
@@ -21,7 +21,7 @@ module NodeMutation[T]
21
21
 
22
22
  def append: (node: T, code: String) -> void
23
23
 
24
- def delete: (node: T, *selectors: Array[String], **options: { and_comma: bool }) -> void
24
+ def delete: (node: T, selectors: Array[String], and_comma: bool) -> void
25
25
 
26
26
  def indent: (node: T, ?tab_size: Integer) -> void
27
27
 
@@ -29,9 +29,9 @@ module NodeMutation[T]
29
29
 
30
30
  def prepend: (node: T, code: String) -> void
31
31
 
32
- def remove: (node: T, **options: { and_comma: bool }) -> void
32
+ def remove: (node: T, and_comma: bool) -> void
33
33
 
34
- def replace: (node: T, *selectors: Array[String], with: String) -> void
34
+ def replace: (node: T, selectors: Array[String], with: String) -> void
35
35
 
36
36
  def replace_with: (node: T, code: String) -> void
37
37
 
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.18.1
4
+ version: 1.18.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-20 00:00:00.000000000 Z
11
+ date: 2023-06-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ast node mutation apis
14
14
  email: