synvert-core 1.3.0 → 1.3.1

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: 56b98032247ef28e548b34dfd8b2b49bad8744227cd61b4f300c7111b701ff91
4
- data.tar.gz: ea75a1e4f442041665dbd9babdc2f7e4b55c4c78c87facef856e903f2d8c96d2
3
+ metadata.gz: 51aff3b9c1c43ab2e6b3c093b65a42cb97536b900cf0aa8d0081e7e8716346f0
4
+ data.tar.gz: 6902ad17b6fa2d1ab2a5d5294f3bb1f29903a12c7ad8dd15cc7dae56173a440a
5
5
  SHA512:
6
- metadata.gz: 905c1f393a1702df43300432e210784790a30dff9a7bb0c798c742ec372a65ad8487b2097333f57afb1798c566f554ab9096ae92db8cd2541e5bb03769009882
7
- data.tar.gz: bd03f1c285c5b5b42628df0b3c8777d6167d980c8c3e3b2f92badfc040b2bef5fe2bef3b848b5a6a166002a5e68f8f4f287ac6ee8fadc72a3ef6706fe191c821
6
+ metadata.gz: 74cc5bb2cf144fba8bbd8ad647971efeba9473138d1cc5b416b45aa940c22f8929cefdd32b5e692c0dc1a9c9786d49dd8b441f1949a58256cec015a9697f2a43
7
+ data.tar.gz: c08abee0bf9fd0cba7cd5248f9020c4c30dadc25c06c5b358a122ccb09e7171878eae85cd498a0fb788aa2987fcf0302916c49cca0f9eaabc77b55e3a43d6a3a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.3.1 (2022-05-14)
4
+
5
+ * Add `add_comma` option to remove extra comma
6
+
3
7
  ## 1.3.0 (2022-05-12)
4
8
 
5
9
  * Support `*=`, `^=` and `$=` operators
@@ -1,3 +1,4 @@
1
+ # typed: false
1
2
  # frozen_string_literal: true
2
3
  # encoding: UTF-8
3
4
  #--
@@ -1,3 +1,4 @@
1
+ # typed: true
1
2
  #
2
3
  # DO NOT MODIFY!!!!
3
4
  # This file is automatically generated by Racc 1.6.0
@@ -7,9 +7,11 @@ module Synvert::Core
7
7
  #
8
8
  # @param instance [Synvert::Core::Rewriter::Instance]
9
9
  # @param selectors [Array<Symbol, String>] used to select child nodes
10
- def initialize(instance, *selectors)
10
+ # @option and_comma [Boolean] delete extra comma.
11
+ def initialize(instance, *selectors, and_comma: false)
11
12
  super(instance, nil)
12
13
  @selectors = selectors
14
+ @and_comma = and_comma
13
15
  end
14
16
 
15
17
  # The rewritten code, always empty string.
@@ -26,7 +28,7 @@ module Synvert::Core
26
28
  @end_pos = @selectors.map { |selector| @node.child_node_range(selector) }
27
29
  .compact.map(&:end_pos).max
28
30
  squeeze_spaces
29
- remove_comma
31
+ remove_comma if @and_comma
30
32
  end
31
33
  end
32
34
  end
@@ -6,8 +6,11 @@ module Synvert::Core
6
6
  # Initialize a RemoveAction.
7
7
  #
8
8
  # @param instance [Synvert::Core::Rewriter::RemoveAction]
9
- def initialize(instance)
9
+ # @param options [Hash] options.
10
+ # @option and_comma [Boolean] delete extra comma.
11
+ def initialize(instance, and_comma: false)
10
12
  super(instance, nil)
13
+ @and_comma = and_comma
11
14
  end
12
15
 
13
16
  # The rewritten code, always empty string.
@@ -27,7 +30,7 @@ module Synvert::Core
27
30
  @begin_pos = @node.loc.expression.begin_pos
28
31
  @end_pos = @node.loc.expression.end_pos
29
32
  squeeze_spaces
30
- remove_comma
33
+ remove_comma if @and_command
31
34
  end
32
35
  end
33
36
 
@@ -333,8 +333,10 @@ module Synvert::Core
333
333
  # with_node type: 'send', message: { in: %w[puts p] } do
334
334
  # remove
335
335
  # end
336
- def remove
337
- @actions << Rewriter::RemoveAction.new(self).process
336
+ # @param options [Hash] options.
337
+ # @option and_comma [Boolean] delete extra comma.
338
+ def remove(**options)
339
+ @actions << Rewriter::RemoveAction.new(self, **options).process
338
340
  end
339
341
 
340
342
  # Parse +delete+ dsl, it creates a {Synvert::Core::Rewriter::DeleteAction} to delete child nodes.
@@ -346,8 +348,10 @@ module Synvert::Core
346
348
  # delete :receiver, :dot
347
349
  # end
348
350
  # @param selectors [Array<Symbol>] selector names of child node.
349
- def delete(*selectors)
350
- @actions << Rewriter::DeleteAction.new(self, *selectors).process
351
+ # @param options [Hash]
352
+ # @option and_comma [Boolean] delete extra comma.
353
+ def delete(*selectors, **options)
354
+ @actions << Rewriter::DeleteAction.new(self, *selectors, **options).process
351
355
  end
352
356
 
353
357
  # Parse +wrap+ dsl, it creates a {Synvert::Core::Rewriter::WrapAction} to
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Synvert
4
4
  module Core
5
- VERSION = '1.3.0'
5
+ VERSION = '1.3.1'
6
6
  end
7
7
  end
@@ -167,16 +167,21 @@ module Synvert::Core
167
167
 
168
168
  it 'parses remove' do
169
169
  action = double
170
- expect(Rewriter::RemoveAction).to receive(:new).with(instance).and_return(action)
170
+ expect(Rewriter::RemoveAction).to receive(:new).with(instance, { and_comma: true }).and_return(action)
171
171
  expect(action).to receive(:process)
172
- instance.remove
172
+ instance.remove and_comma: true
173
173
  end
174
174
 
175
175
  it 'parses remove' do
176
176
  action = double
177
- expect(Rewriter::DeleteAction).to receive(:new).with(instance, :dot, :message).and_return(action)
177
+ expect(Rewriter::DeleteAction).to receive(:new).with(
178
+ instance,
179
+ :dot,
180
+ :message,
181
+ { and_comma: true }
182
+ ).and_return(action)
178
183
  expect(action).to receive(:process)
179
- instance.delete :dot, :message
184
+ instance.delete :dot, :message, and_comma: true
180
185
  end
181
186
 
182
187
  it 'parses wrap with' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synvert-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-12 00:00:00.000000000 Z
11
+ date: 2022-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport