synvert-core 0.32.0 → 0.35.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: eb6c6b0b57d35fa8d3f850685ccda616f56f19fe55fee0b766302574b2cc577e
4
- data.tar.gz: fac77a466b7691c8b74c5a3bb4f2b00ef31be69dfdb0db93fb07593e8553702e
3
+ metadata.gz: 2cebe11ac19bf86abe8809a2b95401dca2dd4d75285cb3e342c1d6a81c3fc4fb
4
+ data.tar.gz: 300d59aded93c156a78fffe02147ab3a74adc6c9c6e0449433b5a19881b64363
5
5
  SHA512:
6
- metadata.gz: 6ce9c70f4892ed3e65cb4669e0e623b745d8edce13e06fbc758c33adce27870934b6e5ea78dcf0eca480c421b96b9afa6de666599094819fd6e5cb6f4ba3b056
7
- data.tar.gz: '0800aedc7b404a04f4605e2586f123faed17152f7ebe81bd430f48834f760c8189efe7fb348f41d15f2285370bdd2d08c31badb6e99df064c5b50dd98801ea88'
6
+ metadata.gz: 7b03da68bbb3c5be3d275c922da6f1e8b0671ec1666b004897d60f142095c555eab5f4ac1eb386981b18e7fd60d0ed3d746b65883bfa63c3f3954b015ed1b2c8
7
+ data.tar.gz: 57c1ce9cb9d250b3a418a0587eac7e1b21b2e8125dc1d4924e390bc07a6ede2d15eb82059e0e7acf3a029c0733608475c0478da93875ceff03cfa5889b55860b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.35.0 (2021-05-17)
4
+
5
+ * Add `contain` rule
6
+
7
+ ## 0.34.0 (2021-05-16)
8
+
9
+ * `child_node_name` supports [:def, :parentheses] and [:defs, :parentheses]
10
+ * Rename `pipe` to `pipes`
11
+
12
+ ## 0.33.0 (2021-05-10)
13
+
14
+ * Add `body` for `class` node
15
+
3
16
  ## 0.32.0 (2021-05-07)
4
17
 
5
18
  * Remove `ArgumentsNode`
@@ -110,7 +110,7 @@ module Parser::AST
110
110
  case type
111
111
  when :begin
112
112
  children
113
- when :def, :block
113
+ when :def, :block, :class
114
114
  return [] if children[2].nil?
115
115
 
116
116
  :begin == children[2].type ? children[2].body : children[2..-1]
@@ -329,20 +329,16 @@ 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
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]
336
+ when %i[class name], %i[def name], %i[defs name]
341
337
  loc.name
342
338
  when %i[defs dot]
343
339
  loc.operator
344
340
  when %i[defs self]
345
- Parser::Source::Range.new('(string)', loc.operator.begin_pos - 4, loc.operator.begin_pos)
341
+ Parser::Source::Range.new('(string)', loc.operator.begin_pos - 'self'.length, loc.operator.begin_pos)
346
342
  when %i[send dot]
347
343
  loc.dot
348
344
  when %i[send message]
@@ -403,7 +399,7 @@ module Parser::AST
403
399
  def match?(rules)
404
400
  flat_hash(rules).keys.all? do |multi_keys|
405
401
  case multi_keys.last
406
- when :any
402
+ when :any, :contain
407
403
  actual_values = actual_value(self, multi_keys[0...-1])
408
404
  expected = expected_value(rules, multi_keys)
409
405
  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.32.0'
5
+ VERSION = '0.35.1'
6
6
  end
7
7
  end
@@ -146,6 +146,21 @@ describe Parser::AST::Node do
146
146
  expect(node.body).to eq [parse('include EmailSpec::Helpers'), parse('include EmailSpec::Matchers')]
147
147
  end
148
148
 
149
+ it 'gets empty for class node' do
150
+ node = parse('class User; end')
151
+ expect(node.body).to be_empty
152
+ end
153
+
154
+ it 'gets one line for class node' do
155
+ node = parse('class User; attr_accessor :email; end')
156
+ expect(node.body).to eq [parse('attr_accessor :email')]
157
+ end
158
+
159
+ it 'gets one line for class node' do
160
+ node = parse('class User; attr_accessor :email; attr_accessor :username; end')
161
+ expect(node.body).to eq [parse('attr_accessor :email'), parse('attr_accessor :username')]
162
+ end
163
+
149
164
  it 'gets for begin node' do
150
165
  node = parse('foo; bar')
151
166
  expect(node.body).to eq [parse('foo'), parse('bar')]
@@ -399,6 +414,12 @@ describe Parser::AST::Node do
399
414
  expect(node).to be_match(type: 'send', arguments: { any: 'Lifo::Cache' })
400
415
  end
401
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
+
402
423
  it 'matches not' do
403
424
  source = 'class Synvert; end'
404
425
  node = parse(source)
@@ -432,9 +453,9 @@ describe Parser::AST::Node do
432
453
  expect(range.to_range).to eq(25...29)
433
454
  end
434
455
 
435
- it 'checks pipe' do
456
+ it 'checks pipes' do
436
457
  node = parse('Factory.define :user do |user|; end')
437
- range = node.child_node_range(:pipe)
458
+ range = node.child_node_range(:pipes)
438
459
  expect(range.to_range).to eq(24...30)
439
460
  end
440
461
  end
@@ -469,6 +490,12 @@ describe Parser::AST::Node do
469
490
  range = node.child_node_range(:arguments)
470
491
  expect(range.to_range).to eq(8...11)
471
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
472
499
  end
473
500
 
474
501
  context 'defs node' do
@@ -495,6 +522,12 @@ describe Parser::AST::Node do
495
522
  range = node.child_node_range(:arguments)
496
523
  expect(range.to_range).to eq(13...16)
497
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
498
531
  end
499
532
 
500
533
  context 'send node' do
@@ -8,16 +8,15 @@ 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
20
18
  let(:node) { Parser::CurrentRuby.parse(source) }
19
+
21
20
  before do
22
21
  Rewriter::Instance.reset
23
22
  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.32.0
4
+ version: 0.35.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: 2021-05-07 00:00:00.000000000 Z
11
+ date: 2021-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport