synvert-core 0.42.0 → 0.45.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 +4 -4
- data/.github/workflows/main.yml +32 -0
- data/CHANGELOG.md +11 -0
- data/README.md +1 -1
- data/lib/synvert/core/node_ext.rb +7 -1
- data/lib/synvert/core/rewriter.rb +5 -4
- data/lib/synvert/core/rewriter/action/delete_action.rb +2 -2
- data/lib/synvert/core/rewriter/instance.rb +2 -6
- data/lib/synvert/core/version.rb +1 -1
- data/spec/synvert/core/node_ext_spec.rb +24 -0
- data/spec/synvert/core/rewriter/gem_spec_spec.rb +12 -13
- metadata +3 -3
- data/.travis.yml +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79cd6bc1c9d3e69d97ee47a276165412326be82a0d87f4527742c6d6c2acdca8
|
4
|
+
data.tar.gz: efa16f88a2a075aa33b3dc5aba653e8c188317840a5a0af75dfba87878a4c7d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51115212e46d96e19fc611a565535246e0fa25d43b8ad6d8830c7e149571b0ff682621ba9525a2d9ab0250d1a98afde7f02d5d8f414457d00fcbbd5bf5352372
|
7
|
+
data.tar.gz: a6b3c930b1183abd25ee03e5c371a5a937f22e686e975f8de48afb882ff82deb8b43432ada7ff85254c2f04e7be1081bca8b7cd4af475cc94ad1250fd8c02846
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: CI
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ master ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ master ]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
|
19
|
+
runs-on: ubuntu-latest
|
20
|
+
strategy:
|
21
|
+
matrix:
|
22
|
+
ruby-version: ['2.5', '2.6', '2.7', '3.0']
|
23
|
+
|
24
|
+
steps:
|
25
|
+
- uses: actions/checkout@v2
|
26
|
+
- name: Set up Ruby
|
27
|
+
uses: ruby/setup-ruby@v1
|
28
|
+
with:
|
29
|
+
ruby-version: ${{ matrix.ruby-version }}
|
30
|
+
bundler-cache: true
|
31
|
+
- name: Run tests
|
32
|
+
run: bundle exec rake
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
# 0.45.0 (2021-07-22)
|
4
|
+
|
5
|
+
* Handle `nil` child node for `begin_pos` and `end_pos`
|
6
|
+
* Remove `Rewriter::Instance` options
|
7
|
+
|
8
|
+
# 0.44.0 (2021-07-19)
|
9
|
+
|
10
|
+
* Return rewrtier after executing snippet
|
11
|
+
* `left_value` and `right_value` support `or_asgn` node
|
12
|
+
* `child_node_range` supports send `parentheses`
|
13
|
+
|
3
14
|
# 0.42.0 (2021-07-11)
|
4
15
|
|
5
16
|
* Match string with quote
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Synvert::Core
|
2
2
|
|
3
|
-
|
3
|
+

|
4
4
|
[](https://coveralls.io/r/xinminlabs/synvert-core)
|
5
5
|
[](http://badge.fury.io/rb/synvert-core)
|
6
6
|
|
@@ -217,6 +217,8 @@ module Parser::AST
|
|
217
217
|
def left_value
|
218
218
|
if %i[masgn lvasgn ivasgn].include? type
|
219
219
|
children[0]
|
220
|
+
elsif :or_asgn == type
|
221
|
+
children[0].children[0]
|
220
222
|
else
|
221
223
|
raise Synvert::Core::MethodNotSupported, "left_value is not handled for #{debug_info}"
|
222
224
|
end
|
@@ -227,7 +229,7 @@ module Parser::AST
|
|
227
229
|
# @return [Array<Parser::AST::Node>] variable nodes.
|
228
230
|
# @raise [Synvert::Core::MethodNotSupported] if calls on other node.
|
229
231
|
def right_value
|
230
|
-
if %i[masgn lvasgn ivasgn].include? type
|
232
|
+
if %i[masgn lvasgn ivasgn or_asgn].include? type
|
231
233
|
children[1]
|
232
234
|
else
|
233
235
|
raise Synvert::Core::MethodNotSupported, "right_value is not handled for #{debug_info}"
|
@@ -360,6 +362,10 @@ module Parser::AST
|
|
360
362
|
else
|
361
363
|
loc.selector
|
362
364
|
end
|
365
|
+
when %i[send parentheses]
|
366
|
+
if loc.begin && loc.end
|
367
|
+
Parser::Source::Range.new('(string)', loc.begin.begin_pos, loc.end.end_pos)
|
368
|
+
end
|
363
369
|
else
|
364
370
|
if respond_to?(child_name)
|
365
371
|
child_node = send(child_name)
|
@@ -52,7 +52,9 @@ module Synvert::Core
|
|
52
52
|
#
|
53
53
|
# @param block [Block] a block defines the behaviors of the rewriter.
|
54
54
|
def execute(&block)
|
55
|
-
Rewriter.new('', '', &block)
|
55
|
+
rewriter = Rewriter.new('', '', &block)
|
56
|
+
rewriter.process
|
57
|
+
rewriter
|
56
58
|
end
|
57
59
|
|
58
60
|
# Register a rewriter with its group and name.
|
@@ -243,13 +245,12 @@ module Synvert::Core
|
|
243
245
|
# It creates a [Synvert::Core::Rewriter::Instance] to rewrite code.
|
244
246
|
#
|
245
247
|
# @param file_pattern [String] pattern to find files, e.g. spec/**/*_spec.rb
|
246
|
-
# @param options [Hash] instance options.
|
247
248
|
# @param block [Block] the block to rewrite code in the matching files.
|
248
|
-
def within_files(file_pattern,
|
249
|
+
def within_files(file_pattern, &block)
|
249
250
|
return if @sandbox
|
250
251
|
|
251
252
|
if (!@ruby_version || @ruby_version.match?) && (!@gem_spec || @gem_spec.match?)
|
252
|
-
Rewriter::Instance.new(self, file_pattern,
|
253
|
+
Rewriter::Instance.new(self, file_pattern, &block).process
|
253
254
|
end
|
254
255
|
end
|
255
256
|
|
@@ -12,14 +12,14 @@ module Synvert::Core
|
|
12
12
|
#
|
13
13
|
# @return [Integer] begin position.
|
14
14
|
def begin_pos
|
15
|
-
@selectors.map { |selector| @node.child_node_range(selector)
|
15
|
+
@selectors.map { |selector| @node.child_node_range(selector) }.compact.map(&:begin_pos).min
|
16
16
|
end
|
17
17
|
|
18
18
|
# End position of code to replace.
|
19
19
|
#
|
20
20
|
# @return [Integer] end position.
|
21
21
|
def end_pos
|
22
|
-
@selectors.map { |selector| @node.child_node_range(selector)
|
22
|
+
@selectors.map { |selector| @node.child_node_range(selector) }.compact.map(&:end_pos).max
|
23
23
|
end
|
24
24
|
|
25
25
|
# The rewritten code, always empty string.
|
@@ -64,20 +64,16 @@ module Synvert::Core
|
|
64
64
|
# @return current filename
|
65
65
|
attr_accessor :current_node, :current_file
|
66
66
|
|
67
|
-
DEFAULT_OPTIONS = { sort_by: 'begin_pos' }.freeze
|
68
|
-
|
69
67
|
# Initialize an instance.
|
70
68
|
#
|
71
69
|
# @param rewriter [Synvert::Core::Rewriter]
|
72
70
|
# @param file_pattern [String] pattern to find files, e.g. spec/**/*_spec.rb
|
73
|
-
# @param options [Hash] instance options, it includes :sort_by.
|
74
71
|
# @param block [Block] block code to find nodes, match conditions and rewrite code.
|
75
72
|
# @return [Synvert::Core::Rewriter::Instance]
|
76
|
-
def initialize(rewriter, file_pattern,
|
73
|
+
def initialize(rewriter, file_pattern, &block)
|
77
74
|
@rewriter = rewriter
|
78
75
|
@actions = []
|
79
76
|
@file_pattern = file_pattern
|
80
|
-
@options = DEFAULT_OPTIONS.merge(options)
|
81
77
|
@block = block
|
82
78
|
rewriter.helpers.each { |helper| singleton_class.send(:define_method, helper[:name], &helper[:block]) }
|
83
79
|
end
|
@@ -107,7 +103,7 @@ module Synvert::Core
|
|
107
103
|
end
|
108
104
|
|
109
105
|
if @actions.length > 0
|
110
|
-
@actions.sort_by! { |action| action.
|
106
|
+
@actions.sort_by! { |action| [action.begin_pos, action.end_pos] }
|
111
107
|
conflict_actions = get_conflict_actions
|
112
108
|
@actions.reverse_each do |action|
|
113
109
|
source[action.begin_pos...action.end_pos] = action.rewritten_code
|
data/lib/synvert/core/version.rb
CHANGED
@@ -261,6 +261,11 @@ describe Parser::AST::Node do
|
|
261
261
|
node = parse('@a = 1')
|
262
262
|
expect(node.left_value).to eq :@a
|
263
263
|
end
|
264
|
+
|
265
|
+
it 'gets for or_asgn' do
|
266
|
+
node = parse('a ||= 1')
|
267
|
+
expect(node.left_value).to eq :a
|
268
|
+
end
|
264
269
|
end
|
265
270
|
|
266
271
|
describe '#right_value' do
|
@@ -283,6 +288,11 @@ describe Parser::AST::Node do
|
|
283
288
|
node = parse('@a = 1')
|
284
289
|
expect(node.right_value).to eq parse('1')
|
285
290
|
end
|
291
|
+
|
292
|
+
it 'gets for or_asgn' do
|
293
|
+
node = parse('a ||= 1')
|
294
|
+
expect(node.right_value).to eq parse('1')
|
295
|
+
end
|
286
296
|
end
|
287
297
|
|
288
298
|
describe '#to_value' do
|
@@ -614,6 +624,20 @@ describe Parser::AST::Node do
|
|
614
624
|
range = node.child_node_range(:arguments)
|
615
625
|
expect(range).to be_nil
|
616
626
|
end
|
627
|
+
|
628
|
+
it 'checks parentheses' do
|
629
|
+
node = parse('foo.bar(test)')
|
630
|
+
range = node.child_node_range(:parentheses)
|
631
|
+
expect(range.to_range).to eq(7...13)
|
632
|
+
|
633
|
+
node = parse('foobar(test)')
|
634
|
+
range = node.child_node_range(:parentheses)
|
635
|
+
expect(range.to_range).to eq(6...12)
|
636
|
+
|
637
|
+
node = parse('foo.bar')
|
638
|
+
range = node.child_node_range(:parentheses)
|
639
|
+
expect(range).to be_nil
|
640
|
+
end
|
617
641
|
end
|
618
642
|
end
|
619
643
|
|
@@ -4,19 +4,18 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
module Synvert::Core
|
6
6
|
describe Rewriter::GemSpec do
|
7
|
-
let(:gemfile_lock_content) {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
'
|
19
|
-
}
|
7
|
+
let(:gemfile_lock_content) { <<~EOS }
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ast (1.1.0)
|
12
|
+
parser (2.1.7)
|
13
|
+
ast (~> 1.1)
|
14
|
+
slop (~> 3.4, >= 3.4.5)
|
15
|
+
rake (10.1.1)
|
16
|
+
slop (3.4.7)
|
17
|
+
EOS
|
18
|
+
before { allow(File).to receive(:exist?).with(File.join(ENV['HOME'], '.gem/specs')).and_return(false) }
|
20
19
|
|
21
20
|
it 'returns true if version in Gemfile.lock is greater than definition' do
|
22
21
|
expect(File).to receive(:exist?).with('./Gemfile.lock').and_return(true)
|
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.45.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-07-
|
11
|
+
date: 2021-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -129,9 +129,9 @@ executables: []
|
|
129
129
|
extensions: []
|
130
130
|
extra_rdoc_files: []
|
131
131
|
files:
|
132
|
+
- ".github/workflows/main.yml"
|
132
133
|
- ".gitignore"
|
133
134
|
- ".rspec"
|
134
|
-
- ".travis.yml"
|
135
135
|
- CHANGELOG.md
|
136
136
|
- Gemfile
|
137
137
|
- Guardfile
|