synvert-core 0.44.0 → 0.45.2

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: f858973b7f9b7bcfd9260bf3149cb76d841279e45302c52905164b2ae464e2f1
4
- data.tar.gz: df45fb62ee7cf5c6aed86bc7e78a2c610b328b124e97a6ef6e009fdcc500d263
3
+ metadata.gz: 425514bc071364c9908b0eff57e626c19fecf611ce3504dd51875af747969aea
4
+ data.tar.gz: 2120c05146eab24a6f6c36c9213fcce70ed3102862b1f572d2ba208659b8053a
5
5
  SHA512:
6
- metadata.gz: cc6cbfa30627b61cf345834fd736e3795fbc6c4a6e063758459245f53cfc1954d5bbc477dc6a262f8a8754e0dbcd0f089d2196ef7edc7ce7e04b6141a374808e
7
- data.tar.gz: 5bb7b3ad077e71753a4025416f62ee2c2979b8048466d34043c267b26ec92bf50ab850d57abaffd8f32013dab1d314ced834ed0b2f0e1bedbf70cb3c61d34fc9
6
+ metadata.gz: 65ff93235c9c5a437017f59a4e63fc6ef0a569b4b4f9de6cf23cbb0bf8203c796ea8cdd564ee4a434b87fb4346b0569140f4b75e94ebacfea1dc3cb3e54168f2
7
+ data.tar.gz: 5902bcfda3dfe77f362df46e1e8dcad4c269ff5057827936279ebfb8dcd82b19fe6b01e6e52db190d1a7b8d40233a8b15b03864191070e8ef2da8deeb0161ca3
@@ -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,12 +1,25 @@
1
1
  # CHANGELOG
2
2
 
3
- # 0.44.0 (2021-07-19)
3
+ ## 0.45.2 (2021-07-24)
4
+
5
+ * Simplify symbol `match_value?`
6
+
7
+ ## 0.45.1 (2021-07-24)
8
+
9
+ * Unwrap quote when matching string value
10
+
11
+ ## 0.45.0 (2021-07-22)
12
+
13
+ * Handle `nil` child node for `begin_pos` and `end_pos`
14
+ * Remove `Rewriter::Instance` options
15
+
16
+ ## 0.44.0 (2021-07-19)
4
17
 
5
18
  * Return rewrtier after executing snippet
6
19
  * `left_value` and `right_value` support `or_asgn` node
7
20
  * `child_node_range` supports send `parentheses`
8
21
 
9
- # 0.42.0 (2021-07-11)
22
+ ## 0.42.0 (2021-07-11)
10
23
 
11
24
  * Match string with quote
12
25
  * `match_value?` returns true if actual and expected are the same
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Synvert::Core
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/xinminlabs/synvert-core.png)](http://travis-ci.org/xinminlabs/synvert-core)
3
+ ![Main workflow](https://github.com/xinminlabs/synvert-core/actions/workflows/main.yml/badge.svg)
4
4
  [![Coverage Status](https://coveralls.io/repos/xinminlabs/synvert-core/badge.png?branch=master)](https://coveralls.io/r/xinminlabs/synvert-core)
5
5
  [![Gem Version](https://badge.fury.io/rb/synvert-core.png)](http://badge.fury.io/rb/synvert-core)
6
6
 
@@ -365,8 +365,6 @@ module Parser::AST
365
365
  when %i[send parentheses]
366
366
  if loc.begin && loc.end
367
367
  Parser::Source::Range.new('(string)', loc.begin.begin_pos, loc.end.end_pos)
368
- else
369
- nil
370
368
  end
371
369
  else
372
370
  if respond_to?(child_name)
@@ -506,15 +504,14 @@ module Parser::AST
506
504
  case expected
507
505
  when Symbol
508
506
  if actual.is_a?(Parser::AST::Node)
509
- actual.to_source == ":#{expected}"
507
+ actual.to_value == expected
510
508
  else
511
509
  actual.to_sym == expected
512
510
  end
513
511
  when String
514
512
  if actual.is_a?(Parser::AST::Node)
515
- return true if (Parser::CurrentRuby.parse(expected) == actual rescue nil)
516
- actual.to_source == expected || (actual.to_source[0] == ':' && actual.to_source[1..-1] == expected) ||
517
- actual.to_source[1...-1] == expected
513
+ actual.to_source == expected || actual.to_value == expected ||
514
+ actual.to_source == unwrap_quote(expected) || actual.to_value == unwrap_quote(expected)
518
515
  else
519
516
  actual.to_s == expected || wrap_quote(actual.to_s) == expected
520
517
  end
@@ -593,5 +590,13 @@ module Parser::AST
593
590
  "'#{string}'"
594
591
  end
595
592
  end
593
+
594
+ def unwrap_quote(string)
595
+ if (string[0] == '"' && string[-1] == '"') || (string[0] == "'" && string[-1] == "'")
596
+ string[1...-1]
597
+ else
598
+ string
599
+ end
600
+ end
596
601
  end
597
602
  end
@@ -245,13 +245,12 @@ module Synvert::Core
245
245
  # It creates a [Synvert::Core::Rewriter::Instance] to rewrite code.
246
246
  #
247
247
  # @param file_pattern [String] pattern to find files, e.g. spec/**/*_spec.rb
248
- # @param options [Hash] instance options.
249
248
  # @param block [Block] the block to rewrite code in the matching files.
250
- def within_files(file_pattern, options = {}, &block)
249
+ def within_files(file_pattern, &block)
251
250
  return if @sandbox
252
251
 
253
252
  if (!@ruby_version || @ruby_version.match?) && (!@gem_spec || @gem_spec.match?)
254
- Rewriter::Instance.new(self, file_pattern, options, &block).process
253
+ Rewriter::Instance.new(self, file_pattern, &block).process
255
254
  end
256
255
  end
257
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).begin_pos }.min
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).end_pos }.max
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, options = {}, &block)
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.send(@options[:sort_by]) }
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Synvert
4
4
  module Core
5
- VERSION = '0.44.0'
5
+ VERSION = '0.45.2'
6
6
  end
7
7
  end
@@ -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
- GEM
10
- remote: https://rubygems.org/
11
- specs:
12
- ast (1.1.0)
13
- parser (2.1.7)
14
- ast (~> 1.1)
15
- slop (~> 3.4, >= 3.4.5)
16
- rake (10.1.1)
17
- slop (3.4.7)
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.44.0
4
+ version: 0.45.2
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-18 00:00:00.000000000 Z
11
+ date: 2021-07-24 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
data/.travis.yml DELETED
@@ -1,8 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.3
4
- - 2.4
5
- - 2.5
6
- - 2.6
7
- - 2.7
8
- - 3.0