synvert-core 1.30.1 → 1.30.3
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 +1 -1
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +5 -5
- data/lib/synvert/core/configuration.rb +34 -1
- data/lib/synvert/core/rewriter/gem_spec.rb +2 -0
- data/lib/synvert/core/rewriter/instance.rb +5 -5
- data/lib/synvert/core/rewriter/ruby_version.rb +2 -0
- data/lib/synvert/core/utils.rb +1 -1
- data/lib/synvert/core/version.rb +1 -1
- data/spec/synvert/core/rewriter/gem_spec_spec.rb +7 -0
- data/spec/synvert/core/rewriter/instance_spec.rb +33 -2
- data/spec/synvert/core/rewriter/ruby_version_spec.rb +9 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c2557aab985fb34048581b6b768d40c012a8f4e2403987a43350c837890d991
|
4
|
+
data.tar.gz: 2f9d14d1c0632282d9d5d259dc21a25db4f245b4aa44302baabfa63e14a4f25a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbe85c0e46b4eff9be065c257105a4d22f15d1ee14ebacb0a3b6a638c8727862f984358e4204b3551ea567323eab784f35e1274f50c9ab8b2cad3417cbcdc299
|
7
|
+
data.tar.gz: 0a8ffa195df715505e6fdd5e7aa2694b9a34aba1ea4ba0e34256fca5763a4d9a722fdb16e2a417a28eb9fa197e3b3e597708103bb2bc9989773dfe2d9f15ca89
|
data/.github/workflows/main.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
synvert-core (1.30.
|
4
|
+
synvert-core (1.30.3)
|
5
5
|
activesupport (< 7.0.0)
|
6
6
|
node_mutation (>= 1.21.6)
|
7
7
|
node_query (>= 1.13.12)
|
@@ -48,15 +48,15 @@ GEM
|
|
48
48
|
rb-inotify (~> 0.9, >= 0.9.10)
|
49
49
|
lumberjack (1.2.8)
|
50
50
|
method_source (1.0.0)
|
51
|
-
minitest (5.
|
51
|
+
minitest (5.21.1)
|
52
52
|
nenv (0.3.0)
|
53
|
-
node_mutation (1.22.
|
53
|
+
node_mutation (1.22.2)
|
54
54
|
node_query (1.14.1)
|
55
55
|
notiffany (0.1.3)
|
56
56
|
nenv (~> 0.1)
|
57
57
|
shellany (~> 0.0)
|
58
|
-
parallel (1.
|
59
|
-
parser (3.
|
58
|
+
parallel (1.24.0)
|
59
|
+
parser (3.3.0.3)
|
60
60
|
ast (~> 2.4.1)
|
61
61
|
racc
|
62
62
|
parser_node_ext (1.2.1)
|
@@ -11,7 +11,17 @@ module Synvert::Core
|
|
11
11
|
# @!attribute [w] number_of_workers
|
12
12
|
# @!attribute [w] single_quote
|
13
13
|
# @!attribute [w] tab_width
|
14
|
-
|
14
|
+
# @!attribute [w] strict, if strict is false, it will ignore ruby version and gem version check.
|
15
|
+
# @!attribute [w] test_result, default is 'actions', it can be 'actions' or 'new_source'.
|
16
|
+
attr_writer :root_path,
|
17
|
+
:skip_paths,
|
18
|
+
:only_paths,
|
19
|
+
:show_run_process,
|
20
|
+
:number_of_workers,
|
21
|
+
:single_quote,
|
22
|
+
:tab_width,
|
23
|
+
:strict,
|
24
|
+
:test_result
|
15
25
|
|
16
26
|
# Get the path.
|
17
27
|
#
|
@@ -55,9 +65,32 @@ module Synvert::Core
|
|
55
65
|
@single_quote.nil? ? true : @single_quote
|
56
66
|
end
|
57
67
|
|
68
|
+
# Returns the tab width used for indentation.
|
69
|
+
#
|
70
|
+
# If the tab width is not explicitly set, it defaults to 2.
|
71
|
+
#
|
72
|
+
# @return [Integer] The tab width.
|
58
73
|
def tab_width
|
59
74
|
@tab_width || 2
|
60
75
|
end
|
76
|
+
|
77
|
+
# Returns the value of the strict flag.
|
78
|
+
#
|
79
|
+
# If the strict flag is not set, it returns true by default.
|
80
|
+
#
|
81
|
+
# @return [Boolean] the value of the strict flag
|
82
|
+
def strict
|
83
|
+
@strict.nil? ? true : @strict
|
84
|
+
end
|
85
|
+
|
86
|
+
# Returns the value of the test_result flag.
|
87
|
+
#
|
88
|
+
# If the test_result flag is not set, it returns 'actions' by default.
|
89
|
+
#
|
90
|
+
# @return [String] the value of the test_result flag
|
91
|
+
def test_result
|
92
|
+
@test_result || 'actions'
|
93
|
+
end
|
61
94
|
end
|
62
95
|
end
|
63
96
|
end
|
@@ -24,6 +24,8 @@ module Synvert::Core
|
|
24
24
|
#
|
25
25
|
# @return [Boolean] true if matches, otherwise false.
|
26
26
|
def match?
|
27
|
+
return true unless Configuration.strict
|
28
|
+
|
27
29
|
gemfile_lock_path = File.expand_path(File.join(Configuration.root_path, 'Gemfile.lock'))
|
28
30
|
|
29
31
|
# if Gemfile.lock does not exist, just ignore this check
|
@@ -35,7 +35,7 @@ module Synvert::Core
|
|
35
35
|
# @return file path
|
36
36
|
# @!attribute [rw] current_node
|
37
37
|
# @return current ast node
|
38
|
-
attr_reader :file_path
|
38
|
+
attr_reader :file_path
|
39
39
|
attr_accessor :current_node
|
40
40
|
|
41
41
|
# Process the instance.
|
@@ -88,7 +88,7 @@ module Synvert::Core
|
|
88
88
|
instance_eval(&@block)
|
89
89
|
end
|
90
90
|
|
91
|
-
result = @current_mutation.test
|
91
|
+
result = Configuration.test_result == 'new_source' ? @current_mutation.process : @current_mutation.test
|
92
92
|
result.file_path = file_path
|
93
93
|
result
|
94
94
|
rescue Parser::SyntaxError => e
|
@@ -104,14 +104,14 @@ module Synvert::Core
|
|
104
104
|
@current_node
|
105
105
|
end
|
106
106
|
|
107
|
-
# Get rewriter's
|
107
|
+
# Get rewriter's parser.
|
108
108
|
#
|
109
|
-
# @return [String]
|
109
|
+
# @return [String] parser
|
110
110
|
def parser
|
111
111
|
@rewriter.parser
|
112
112
|
end
|
113
113
|
|
114
|
-
#
|
114
|
+
# Get current_mutation's adapter.
|
115
115
|
#
|
116
116
|
# @return [NodeMutation::Adapter]
|
117
117
|
def mutation_adapter
|
@@ -16,6 +16,8 @@ module Synvert::Core
|
|
16
16
|
#
|
17
17
|
# @return [Boolean] true if matches, otherwise false.
|
18
18
|
def match?
|
19
|
+
return true unless Configuration.strict
|
20
|
+
|
19
21
|
if File.exist?(File.join(Configuration.root_path, '.ruby-version'))
|
20
22
|
version_file = '.ruby-version'
|
21
23
|
elsif File.exist?(File.join(Configuration.root_path, '.rvmrc'))
|
data/lib/synvert/core/utils.rb
CHANGED
@@ -8,7 +8,7 @@ module Synvert::Core
|
|
8
8
|
class Utils
|
9
9
|
class << self
|
10
10
|
def eval_snippet(snippet_name)
|
11
|
-
eval(load_snippet(snippet_name), binding,
|
11
|
+
eval(load_snippet(snippet_name), binding, "(eval #{snippet_name})")
|
12
12
|
end
|
13
13
|
|
14
14
|
def load_snippet(snippet_name)
|
data/lib/synvert/core/version.rb
CHANGED
@@ -51,5 +51,12 @@ module Synvert::Core
|
|
51
51
|
gem_spec = Rewriter::GemSpec.new('ast', '1.1.0')
|
52
52
|
expect(gem_spec).to be_match
|
53
53
|
end
|
54
|
+
|
55
|
+
it 'returns true if Configuration.strict is false' do
|
56
|
+
Configuration.strict = false
|
57
|
+
gem_spec = Rewriter::GemSpec.new('synvert', '1.0.0')
|
58
|
+
expect(gem_spec).to be_match
|
59
|
+
Configuration.strict = true
|
60
|
+
end
|
54
61
|
end
|
55
62
|
end
|
@@ -429,7 +429,7 @@ module Synvert::Core
|
|
429
429
|
describe '#test' do
|
430
430
|
let(:rewriter) { Rewriter.new('foo', 'bar') }
|
431
431
|
|
432
|
-
it 'gets actions if
|
432
|
+
it 'gets actions if affected' do
|
433
433
|
instance =
|
434
434
|
Rewriter::Instance.new rewriter, 'spec/models/post_spec.rb' do
|
435
435
|
with_node type: 'send', receiver: 'FactoryGirl', message: 'create' do
|
@@ -452,6 +452,37 @@ module Synvert::Core
|
|
452
452
|
]
|
453
453
|
end
|
454
454
|
|
455
|
+
context 'Configuration.test_result is new_source' do
|
456
|
+
before { Configuration.test_result = 'new_source' }
|
457
|
+
after { Configuration.test_result = nil }
|
458
|
+
|
459
|
+
it 'gets new_source if Configuration.test_result is new_source' do
|
460
|
+
instance =
|
461
|
+
Rewriter::Instance.new rewriter, 'spec/models/post_spec.rb' do
|
462
|
+
with_node type: 'send', receiver: 'FactoryGirl', message: 'create' do
|
463
|
+
replace_with 'create {{arguments}}'
|
464
|
+
end
|
465
|
+
end
|
466
|
+
input = <<~EOS
|
467
|
+
it 'uses factory_girl' do
|
468
|
+
user = FactoryGirl.create :user
|
469
|
+
post = FactoryGirl.create :post, user: user
|
470
|
+
assert post.valid?
|
471
|
+
end
|
472
|
+
EOS
|
473
|
+
expect(File).to receive(:read).with('./spec/models/post_spec.rb', encoding: 'UTF-8').and_return(input)
|
474
|
+
results = instance.test
|
475
|
+
expect(results.file_path).to eq 'spec/models/post_spec.rb'
|
476
|
+
expect(results.new_source).to eq <<~EOS
|
477
|
+
it 'uses factory_girl' do
|
478
|
+
user = create :user
|
479
|
+
post = create :post, user: user
|
480
|
+
assert post.valid?
|
481
|
+
end
|
482
|
+
EOS
|
483
|
+
end
|
484
|
+
end
|
485
|
+
|
455
486
|
it 'gets nothing if not affected' do
|
456
487
|
instance =
|
457
488
|
Rewriter::Instance.new rewriter, 'spec/spec_helper.rb' do
|
@@ -591,7 +622,7 @@ module Synvert::Core
|
|
591
622
|
|
592
623
|
context 'Configuration.single_quote = false' do
|
593
624
|
before { Configuration.single_quote = false }
|
594
|
-
after { Configuration.single_quote =
|
625
|
+
after { Configuration.single_quote = nil }
|
595
626
|
|
596
627
|
it 'wraps with double quotes' do
|
597
628
|
expect(instance.wrap_with_quotes('foobar')).to eq '"foobar"'
|
@@ -5,8 +5,8 @@ require 'spec_helper'
|
|
5
5
|
module Synvert::Core
|
6
6
|
describe Rewriter::RubyVersion do
|
7
7
|
before do
|
8
|
-
|
9
|
-
|
8
|
+
allow(File).to receive(:exist?).with('./.ruby-version').and_return(true)
|
9
|
+
allow(File).to receive(:read).with('./.ruby-version').and_return('3.0.0')
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'returns true if ruby version is greater than 1.9' do
|
@@ -18,5 +18,12 @@ module Synvert::Core
|
|
18
18
|
ruby_version = Rewriter::RubyVersion.new('19.0')
|
19
19
|
expect(ruby_version).not_to be_match
|
20
20
|
end
|
21
|
+
|
22
|
+
it 'returns true if strict Configuration is false' do
|
23
|
+
Configuration.strict = false
|
24
|
+
ruby_version = Rewriter::RubyVersion.new('19.0')
|
25
|
+
expect(ruby_version).to be_match
|
26
|
+
Configuration.strict = true
|
27
|
+
end
|
21
28
|
end
|
22
29
|
end
|
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: 1.30.
|
4
|
+
version: 1.30.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -207,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
207
207
|
- !ruby/object:Gem::Version
|
208
208
|
version: '0'
|
209
209
|
requirements: []
|
210
|
-
rubygems_version: 3.
|
210
|
+
rubygems_version: 3.5.3
|
211
211
|
signing_key:
|
212
212
|
specification_version: 4
|
213
213
|
summary: convert ruby code to better syntax.
|