synvert-core 0.33.0 → 0.36.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/lib/synvert/core.rb +1 -0
- data/lib/synvert/core/node_ext.rb +8 -8
- data/lib/synvert/core/rewriter/instance.rb +1 -1
- data/lib/synvert/core/rewriter/scope/within_scope.rb +12 -3
- data/lib/synvert/core/version.rb +1 -1
- data/spec/synvert/core/node_ext_spec.rb +20 -2
- data/spec/synvert/core/rewriter/scope/within_scope.rb +9 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c655af17df02f43f106cc3653955acbe13eb2348b5d5be0f8fe7003936c88cd8
|
4
|
+
data.tar.gz: 93ecf8e0645716448b308e76dc14bbc873a79b773bf2722edeb7dea31e092aba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
@@ -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
|
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(
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
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) }
|
@@ -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
|
-
|
41
|
-
|
42
|
-
|
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
|
data/lib/synvert/core/version.rb
CHANGED
@@ -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
|
456
|
+
it 'checks pipes' do
|
451
457
|
node = parse('Factory.define :user do |user|; end')
|
452
|
-
range = node.child_node_range(:
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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.
|
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-
|
11
|
+
date: 2021-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|