synvert-core 1.30.1 → 1.30.3

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: a5923465a97b00d151c7877fb725f5f74c63975c9683d926a4bf14e2feae8fc8
4
- data.tar.gz: 94ed7f17447b0d501243b6074f9b4c2e57b09c5954b013727dc052933ac5e8fc
3
+ metadata.gz: 2c2557aab985fb34048581b6b768d40c012a8f4e2403987a43350c837890d991
4
+ data.tar.gz: 2f9d14d1c0632282d9d5d259dc21a25db4f245b4aa44302baabfa63e14a4f25a
5
5
  SHA512:
6
- metadata.gz: c0614ad3287376170341654f290599a0f3541dd26562124935c208d77be666a1073a439090731a42efe62806f4aac91238c0a5eaf79ce971515719ee34384863
7
- data.tar.gz: 1335bdfaaa06f1d8f8cca811d3e0fd4a9d40ca1f1ac0597a42b110555be59976e299cf9147c785c8c8d4ad418251a7fa0c7f2de7967ef71d77c46cbf86548076
6
+ metadata.gz: dbe85c0e46b4eff9be065c257105a4d22f15d1ee14ebacb0a3b6a638c8727862f984358e4204b3551ea567323eab784f35e1274f50c9ab8b2cad3417cbcdc299
7
+ data.tar.gz: 0a8ffa195df715505e6fdd5e7aa2694b9a34aba1ea4ba0e34256fca5763a4d9a722fdb16e2a417a28eb9fa197e3b3e597708103bb2bc9989773dfe2d9f15ca89
@@ -11,7 +11,7 @@ jobs:
11
11
  runs-on: ubuntu-latest
12
12
  strategy:
13
13
  matrix:
14
- ruby-version: ['2.7', '3.0', '3.1', '3.2']
14
+ ruby-version: ['2.7', '3.0', '3.1', '3.2', '3.3']
15
15
 
16
16
  steps:
17
17
  - uses: actions/checkout@v3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.30.3 (2024-01-13)
4
+
5
+ * Add `Configuration.test_result` option
6
+
7
+ ## 1.30.2 (2024-01-09)
8
+
9
+ * Add `Configuration.strict` option
10
+
3
11
  ## 1.30.1 (2023-12-01)
4
12
 
5
13
  * It is `parser` option instead of `adapter`
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- synvert-core (1.30.1)
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.20.0)
51
+ minitest (5.21.1)
52
52
  nenv (0.3.0)
53
- node_mutation (1.22.0)
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.23.0)
59
- parser (3.2.2.4)
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
- attr_writer :root_path, :skip_paths, :only_paths, :show_run_process, :number_of_workers, :single_quote, :tab_width
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, :current_node
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 adapter.
107
+ # Get rewriter's parser.
108
108
  #
109
- # @return [String] adapter
109
+ # @return [String] parser
110
110
  def parser
111
111
  @rewriter.parser
112
112
  end
113
113
 
114
- # Gent current_mutation's adapter.
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'))
@@ -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, __FILE__, __LINE__ + 1)
11
+ eval(load_snippet(snippet_name), binding, "(eval #{snippet_name})")
12
12
  end
13
13
 
14
14
  def load_snippet(snippet_name)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Synvert
4
4
  module Core
5
- VERSION = '1.30.1'
5
+ VERSION = '1.30.3'
6
6
  end
7
7
  end
@@ -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 afected' do
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 = true }
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
- expect(File).to receive(:exist?).with('./.ruby-version').and_return(true)
9
- expect(File).to receive(:read).with('./.ruby-version').and_return('3.0.0')
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.1
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: 2023-12-01 00:00:00.000000000 Z
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.4.20
210
+ rubygems_version: 3.5.3
211
211
  signing_key:
212
212
  specification_version: 4
213
213
  summary: convert ruby code to better syntax.