synvert-core 0.33.0 → 0.36.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: f4448b6bf2d17c1128bb6d20732de90a7458019ca33835fa9740e5d6f8102e4a
4
- data.tar.gz: 10df72247c2d5a0e7293481096221e755322218e6031ae6b613470938e1d01c4
3
+ metadata.gz: c655af17df02f43f106cc3653955acbe13eb2348b5d5be0f8fe7003936c88cd8
4
+ data.tar.gz: 93ecf8e0645716448b308e76dc14bbc873a79b773bf2722edeb7dea31e092aba
5
5
  SHA512:
6
- metadata.gz: 949edd01e98bd306456ed368bbb4fe16b9d9d320cb82aafd8ddb1a0f2367ba7b8e18ba5d43143aa51a91a64bb95c5d895ea5a7c07beea5dd6f8faf078709267d
7
- data.tar.gz: 04ba8cfbb5d3c66855f300712417a5ad7476f4ac307d46824d8f02f8b0667c8bfcdf909ae978c8a442fee75d1f46faed15bb50cc81c0a360f8e824333fa321a0
6
+ metadata.gz: 53767e387c4b0a3e7e3a18add1488d830afc78a5e9505d237d111a51614e92eb46274611cde2520510dc6fb1e5bf11bb70e7373f8163b709c0245ef1e408cbd5
7
+ data.tar.gz: 91e279203e9c0fb0d968d7b81a0d25de25b05847891532744f6bb9cf701abedb92c8c51361f21813ef6d279b488c9da5df83611f52ccdc48f3ac38c134bd94c8
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.36.0 (2021-06-21)
4
+
5
+ * Require `active_support/core_ext/array`
6
+
7
+ ## 0.35.0 (2021-05-17)
8
+
9
+ * Add `contain` rule
10
+
11
+ ## 0.34.0 (2021-05-16)
12
+
13
+ * `child_node_name` supports [:def, :parentheses] and [:defs, :parentheses]
14
+ * Rename `pipe` to `pipes`
15
+
3
16
  ## 0.33.0 (2021-05-10)
4
17
 
5
18
  * Add `body` for `class` node
data/lib/synvert/core.rb CHANGED
@@ -6,6 +6,7 @@ require 'parser'
6
6
  require 'parser/current'
7
7
  require 'ast'
8
8
  require 'active_support/core_ext/object'
9
+ require 'active_support/core_ext/array'
9
10
  require 'erubis'
10
11
  require 'set'
11
12
  require 'synvert/core/node_ext'
@@ -329,15 +329,15 @@ module Parser::AST
329
329
  # @return [Parser::Source::Range] source range of child node.
330
330
  def child_node_range(child_name)
331
331
  case [type, child_name]
332
- when %i[block pipe]
332
+ when %i[block pipes], %i[def parentheses], %i[defs parentheses]
333
333
  Parser::Source::Range.new('(string)', arguments.loc.expression.begin_pos, arguments.loc.expression.end_pos)
334
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)
336
- when %i[class name]
337
- loc.name
338
- when %i[def name]
339
- loc.name
340
- when %i[defs name]
335
+ Parser::Source::Range.new(
336
+ '(string)',
337
+ arguments.first.loc.expression.begin_pos,
338
+ arguments.last.loc.expression.end_pos
339
+ )
340
+ when %i[class name], %i[def name], %i[defs name]
341
341
  loc.name
342
342
  when %i[defs dot]
343
343
  loc.operator
@@ -403,7 +403,7 @@ module Parser::AST
403
403
  def match?(rules)
404
404
  flat_hash(rules).keys.all? do |multi_keys|
405
405
  case multi_keys.last
406
- when :any
406
+ when :any, :contain
407
407
  actual_values = actual_value(self, multi_keys[0...-1])
408
408
  expected = expected_value(rules, multi_keys)
409
409
  actual_values.any? { |actual| match_value?(actual, expected) }
@@ -302,7 +302,7 @@ module Synvert::Core
302
302
 
303
303
  begin_pos = @actions[i].begin_pos
304
304
  while j > -1
305
- if begin_pos <= @actions[j].end_pos
305
+ if begin_pos < @actions[j].end_pos
306
306
  conflict_actions << @actions.delete_at(j)
307
307
  else
308
308
  i = j
@@ -37,9 +37,18 @@ module Synvert::Core
37
37
  def find_matching_nodes(current_node)
38
38
  matching_nodes = []
39
39
  if @options[:recursive]
40
- matching_nodes << current_node if current_node.match? @rules
41
- current_node.recursive_children do |child_node|
42
- matching_nodes << child_node if child_node.match? @rules
40
+ if current_node.is_a?(Parser::AST::Node)
41
+ matching_nodes << current_node if current_node.match? @rules
42
+ current_node.recursive_children do |child_node|
43
+ matching_nodes << child_node if child_node.match? @rules
44
+ end
45
+ else
46
+ current_node.each do |node|
47
+ matching_nodes << node if node.match? @rules
48
+ node.recursive_children do |child_node|
49
+ matching_nodes << child_node if child_node.match? @rules
50
+ end
51
+ end
43
52
  end
44
53
  elsif current_node.is_a?(Parser::AST::Node)
45
54
  if current_node.type == :begin
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Synvert
4
4
  module Core
5
- VERSION = '0.33.0'
5
+ VERSION = '0.36.0'
6
6
  end
7
7
  end
@@ -414,6 +414,12 @@ describe Parser::AST::Node do
414
414
  expect(node).to be_match(type: 'send', arguments: { any: 'Lifo::Cache' })
415
415
  end
416
416
 
417
+ it 'matches arguments contain' do
418
+ source = 'def slow(foo, bar, &block); end'
419
+ node = parse(source)
420
+ expect(node).to be_match(type: 'def', arguments: { contain: '&block' })
421
+ end
422
+
417
423
  it 'matches not' do
418
424
  source = 'class Synvert; end'
419
425
  node = parse(source)
@@ -447,9 +453,9 @@ describe Parser::AST::Node do
447
453
  expect(range.to_range).to eq(25...29)
448
454
  end
449
455
 
450
- it 'checks pipe' do
456
+ it 'checks pipes' do
451
457
  node = parse('Factory.define :user do |user|; end')
452
- range = node.child_node_range(:pipe)
458
+ range = node.child_node_range(:pipes)
453
459
  expect(range.to_range).to eq(24...30)
454
460
  end
455
461
  end
@@ -484,6 +490,12 @@ describe Parser::AST::Node do
484
490
  range = node.child_node_range(:arguments)
485
491
  expect(range.to_range).to eq(8...11)
486
492
  end
493
+
494
+ it 'checks parentheses' do
495
+ node = parse('def foo(bar); end')
496
+ range = node.child_node_range(:parentheses)
497
+ expect(range.to_range).to eq(7...12)
498
+ end
487
499
  end
488
500
 
489
501
  context 'defs node' do
@@ -510,6 +522,12 @@ describe Parser::AST::Node do
510
522
  range = node.child_node_range(:arguments)
511
523
  expect(range.to_range).to eq(13...16)
512
524
  end
525
+
526
+ it 'checks parentheses' do
527
+ node = parse('def self.foo(bar); end')
528
+ range = node.child_node_range(:parentheses)
529
+ expect(range.to_range).to eq(12...17)
530
+ end
513
531
  end
514
532
 
515
533
  context 'send node' do
@@ -8,16 +8,16 @@ module Synvert::Core
8
8
  rewriter = Rewriter.new('foo', 'bar')
9
9
  Rewriter::Instance.new(rewriter, 'file pattern')
10
10
  }
11
- let(:source) {
12
- "
13
- describe Post do
14
- it 'gets post' do
15
- FactoryGirl.create :post
16
- end
17
- end
18
- "
19
- }
11
+ let(:source) { <<~EOS }
12
+ describe Post do
13
+ it 'gets post' do
14
+ FactoryGirl.create :post
15
+ end
16
+ end
17
+ EOS
18
+
20
19
  let(:node) { Parser::CurrentRuby.parse(source) }
20
+
21
21
  before do
22
22
  Rewriter::Instance.reset
23
23
  instance.current_node = node
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.33.0
4
+ version: 0.36.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-05-10 00:00:00.000000000 Z
11
+ date: 2021-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport