synvert-core 0.31.0 → 0.32.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf20c3a501940025291f9e0ae6f306d1613fb4db8ee5d5cf649d0ad7da4d1c5a
4
- data.tar.gz: 425f42f736ec76ca6ade1f881ab252bfa6659f0e2cc8f3b55dd31153a4d8853a
3
+ metadata.gz: eb6c6b0b57d35fa8d3f850685ccda616f56f19fe55fee0b766302574b2cc577e
4
+ data.tar.gz: fac77a466b7691c8b74c5a3bb4f2b00ef31be69dfdb0db93fb07593e8553702e
5
5
  SHA512:
6
- metadata.gz: 52c43ad9b8986c68a4c77200e84b9cf7497fec7c46f0beb74fa695ed13d986f38519c167a3242d870dca79a0e09844fe6b564d6a54c258801801d4920be2f9da
7
- data.tar.gz: 20aeb9c56536f335d8181e307bcf96ad8b3cbc7c02471077657a1ec0fa23db6c6f10269a4477aef3007ffc0b1dd07f3bb522289ecfed2c5f8f581abd49b3ee8b
6
+ metadata.gz: 6ce9c70f4892ed3e65cb4669e0e623b745d8edce13e06fbc758c33adce27870934b6e5ea78dcf0eca480c421b96b9afa6de666599094819fd6e5cb6f4ba3b056
7
+ data.tar.gz: '0800aedc7b404a04f4605e2586f123faed17152f7ebe81bd430f48834f760c8189efe7fb348f41d15f2285370bdd2d08c31badb6e99df064c5b50dd98801ea88'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.32.0 (2021-05-07)
4
+
5
+ * Remove `ArgumentsNode`
6
+
3
7
  ## 0.31.0 (2021-04-27)
4
8
 
5
9
  * Add `in` and `not_in` rules
@@ -1,29 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Parser::AST
4
- # ArgumentsNode allows to handle all args as one node or handle all args as an array.
5
- class ArgumentsNode
6
- # Initialize
7
- #
8
- # @param node [Parser::AST::Node] args node.
9
- def initialize(node)
10
- @node = node
11
- end
12
-
13
- # If args node responds method itself, call method on args node.
14
- # If args children (array) responds method, call method on args children.
15
- # Otherwise raise method missing error.
16
- def method_missing(meth, *args, &block)
17
- if @node.respond_to?(meth)
18
- @node.send meth, *args, &block
19
- elsif @node.children.respond_to?(meth)
20
- @node.children.send meth, *args, &block
21
- else
22
- super
23
- end
24
- end
25
- end
26
-
27
4
  # Parser::AST::Node monkey patch.
28
5
  class Node
29
6
  # Get name node of :class, :module, :const, :mlhs, :def and :defs node.
@@ -101,9 +78,9 @@ module Parser::AST
101
78
  def arguments
102
79
  case type
103
80
  when :def, :block
104
- ArgumentsNode.new(children[1])
81
+ children[1]
105
82
  when :defs
106
- ArgumentsNode.new(children[2])
83
+ children[2]
107
84
  when :send
108
85
  children[2..-1]
109
86
  when :defined?
@@ -285,7 +262,9 @@ module Parser::AST
285
262
  # Current node is s(:hash, s(:pair, s(:sym, :number), s(:int, 10)))
286
263
  # node.number_value is 10
287
264
  def method_missing(method_name, *args, &block)
288
- if :hash == type && method_name.to_s.include?('_value')
265
+ if :args == type && children.respond_to?(method_name)
266
+ return children.send(method_name, *args, &block)
267
+ elsif :hash == type && method_name.to_s.include?('_value')
289
268
  key = method_name.to_s.sub('_value', '')
290
269
  return hash_value(key.to_sym)&.to_value if key?(key.to_sym)
291
270
  return hash_value(key.to_s)&.to_value if key?(key.to_s)
@@ -297,7 +276,9 @@ module Parser::AST
297
276
  end
298
277
 
299
278
  def respond_to_missing?(method_name, *args)
300
- if :hash == type && method_name.to_s.include?('_value')
279
+ if :args == type && children.respond_to?(method_name)
280
+ return true
281
+ elsif :hash == type && method_name.to_s.include?('_value')
301
282
  key = method_name.to_s.sub('_value', '')
302
283
  return true if key?(key.to_sym) || key?(key.to_s)
303
284
  end
@@ -350,6 +331,8 @@ module Parser::AST
350
331
  case [type, child_name]
351
332
  when %i[block pipe]
352
333
  Parser::Source::Range.new('(string)', arguments.loc.expression.begin_pos, arguments.loc.expression.end_pos)
334
+ when %i[block arguments], %i[def arguments], %i[defs arguments]
335
+ Parser::Source::Range.new('(string)', arguments.first.loc.expression.begin_pos, arguments.last.loc.expression.end_pos)
353
336
  when %i[class name]
354
337
  loc.name
355
338
  when %i[def name]
@@ -458,8 +441,12 @@ module Parser::AST
458
441
  evaluated = instance_eval old_code
459
442
  case evaluated
460
443
  when Parser::AST::Node
461
- evaluated.loc.expression.source
462
- when Array, ArgumentsNode
444
+ if evaluated.type == :args
445
+ evaluated.loc.expression.source[1...-1]
446
+ else
447
+ evaluated.loc.expression.source
448
+ end
449
+ when Array
463
450
  if evaluated.size > 0
464
451
  file_source = evaluated.first.loc.expression.source_buffer.source
465
452
  source = file_source[evaluated.first.loc.expression.begin_pos...evaluated.last.loc.expression.end_pos]
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Synvert
4
4
  module Core
5
- VERSION = '0.31.0'
5
+ VERSION = '0.32.0'
6
6
  end
7
7
  end
@@ -104,17 +104,17 @@ describe Parser::AST::Node do
104
104
  describe '#arguments' do
105
105
  it 'gets for def node' do
106
106
  node = parse('def test(foo, bar); foo + bar; end')
107
- expect(node.arguments.map { |argument| argument.to_source }).to eq %w[foo bar]
107
+ expect(node.arguments.type).to eq :args
108
108
  end
109
109
 
110
110
  it 'gets for defs node' do
111
111
  node = parse('def self.test(foo, bar); foo + bar; end')
112
- expect(node.arguments.map { |argument| argument.to_source }).to eq %w[foo bar]
112
+ expect(node.arguments.type).to eq :args
113
113
  end
114
114
 
115
115
  it 'gets for block node' do
116
116
  node = parse('RSpec.configure do |config|; end')
117
- expect(node.arguments.map { |argument| argument.to_source }).to eq ['config']
117
+ expect(node.arguments.type).to eq :args
118
118
  end
119
119
 
120
120
  it 'gets for send node' do
@@ -408,13 +408,13 @@ describe Parser::AST::Node do
408
408
  it 'matches in' do
409
409
  source = 'FactoryBot.create(:user)'
410
410
  node = parse(source)
411
- expect(node).to be_match(type: 'send', message: { in: [:create, :build] })
411
+ expect(node).to be_match(type: 'send', message: { in: %i[create build] })
412
412
  end
413
413
 
414
414
  it 'matches not_in' do
415
415
  source = 'FactoryBot.create(:user)'
416
416
  node = parse(source)
417
- expect(node).not_to be_match(type: 'send', message: { not_in: [:create, :build] })
417
+ expect(node).not_to be_match(type: 'send', message: { not_in: %i[create build] })
418
418
  end
419
419
  end
420
420
 
@@ -566,7 +566,7 @@ describe Parser::AST::Node do
566
566
  expect(node.rewritten_source('{{name}}')).to eq 'Synvert'
567
567
  end
568
568
 
569
- it 'rewrites for ArgumentsNode' do
569
+ it 'rewrites for arguments' do
570
570
  source = 'test { |a, b| }'
571
571
  node = parse(source)
572
572
  expect(node.rewritten_source('{{arguments}}')).to eq 'a, b'
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: 0.31.0
4
+ version: 0.32.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-27 00:00:00.000000000 Z
11
+ date: 2021-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport