synvert-core 0.54.1 → 0.56.0

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: dce993d0b27272e83abe3bd3a1ff2a9917a2c9953bb30e57671216aed001292c
4
- data.tar.gz: 0b65093ca670d59065707e122a9964f163fbca2e4201fd75005295b7841e4db1
3
+ metadata.gz: 5d9026b58fc968fd19fb6bcfb02a7235ba90fa2dee89b74c4707191ddbe892e7
4
+ data.tar.gz: 80b9f33e6c34e9b575a1dfac6b89adc8e5362cca7506a0b64b86047e3e27afbf
5
5
  SHA512:
6
- metadata.gz: 4bb49555a37b7778e37216f267b0e2ab938030ac5428f7bbef60d8462fb83597693bad9a5cd12c43c52a80330de48662151abbcc8edebb7572538f1520539bac
7
- data.tar.gz: eaf5690913c21c3b043f5119f2b8b4afe08c16c5a9db8d9d209a42f0a64a72d4f19376da6dee6ed43b04b79d8077f4463a47acb5d18742a6dcb1499b3191db7a
6
+ metadata.gz: 40638d3f2674232745f15810f9f5d12d7f2f5f9b99dc353f7fc568812cad747c24b502aec3c50b1952dfba14db034545719e8f14792658bdd44c7ec7db6e05be
7
+ data.tar.gz: 3d9dc8284d401ec5453c8023a23b0b5096c38d8d9581155dca7069f57c25999315f5a075c1d6eff4b802b8f4d2cc4d8a037ce0c0cf33cd8e2c225781e7790b00
data/CHANGELOG.md CHANGED
@@ -1,7 +1,15 @@
1
1
  # CHANGELOG
2
2
 
3
- ## 0.54.1 (2021-09-08)
3
+ ## 0.56.0 (2021-09-14)
4
4
 
5
+ * Support `name` for `:lvar`, `:ivar`, `:cvar`
6
+ * Delete one more space if two spaces left
7
+
8
+ ## 0.55.0 (2021-09-11)
9
+
10
+ * Add `Configuration.show_run_process`
11
+ * Fix remove action `begin_pos` and `end_pos`
12
+ * Fix `nil` match
5
13
  * Rewrite `remove` action
6
14
 
7
15
  ## 0.54.0 (2021-08-28)
@@ -4,7 +4,7 @@ module Synvert::Core
4
4
  # Synvert global configuration.
5
5
  class Configuration
6
6
  class << self
7
- attr_writer :path, :skip_files
7
+ attr_writer :path, :skip_files, :show_run_process
8
8
 
9
9
  def path
10
10
  @path || '.'
@@ -13,6 +13,10 @@ module Synvert::Core
13
13
  def skip_files
14
14
  @skip_files || []
15
15
  end
16
+
17
+ def show_run_process
18
+ @show_run_process || false
19
+ end
16
20
  end
17
21
  end
18
22
  end
@@ -9,7 +9,7 @@ module Parser::AST
9
9
  # @raise [Synvert::Core::MethodNotSupported] if calls on other node.
10
10
  def name
11
11
  case type
12
- when :class, :module, :def, :arg, :blockarg, :restarg
12
+ when :class, :module, :def, :arg, :blockarg, :restarg, :lvar, :ivar, :cvar
13
13
  children[0]
14
14
  when :defs, :const
15
15
  children[1]
@@ -576,7 +576,11 @@ module Parser::AST
576
576
 
577
577
  actual.zip(expected).all? { |a, e| match_value?(a, e) }
578
578
  when NilClass
579
- actual.nil?
579
+ if actual.is_a?(Parser::AST::Node)
580
+ :nil == actual.type
581
+ else
582
+ actual.nil?
583
+ end
580
584
  when Numeric
581
585
  if actual.is_a?(Parser::AST::Node)
582
586
  actual.children[0] == expected
@@ -12,7 +12,12 @@ 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) }.compact.map(&:begin_pos).min
15
+ pos = @selectors.map { |selector| @node.child_node_range(selector) }.compact.map(&:begin_pos).min
16
+ if @instance.file_source[pos - 1] == ' ' && @instance.file_source[end_pos] == ' '
17
+ pos - 1
18
+ else
19
+ pos
20
+ end
16
21
  end
17
22
 
18
23
  # End position of code to delete.
@@ -41,11 +41,13 @@ module Synvert::Core
41
41
  end
42
42
 
43
43
  def start_index
44
- file_source[0..@node.loc.expression.begin_pos].rindex("\n") + "\n".length
44
+ index = file_source[0..@node.loc.expression.begin_pos].rindex("\n")
45
+ index ? index + "\n".length : @node.loc.expression.begin_pos
45
46
  end
46
47
 
47
48
  def end_index
48
- file_source[@node.loc.expression.end_pos..-1].index("\n") + @node.loc.expression.end_pos + "\n".length
49
+ index = file_source[@node.loc.expression.end_pos..-1].index("\n")
50
+ index ? @node.loc.expression.end_pos + index + "\n".length : @node.loc.expression.end_pos
49
51
  end
50
52
 
51
53
  def file_source
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Synvert::Core
4
- # IfExistCondition checks if node has only one child node and the child node matches rules.
4
+ # IfOnlyExistCondition checks if node has only one child node and the child node matches rules.
5
5
  class Rewriter::IfOnlyExistCondition < Rewriter::Condition
6
6
  # check if only have one child node and the child node matches rules.
7
7
  def match?
@@ -46,7 +46,7 @@ module Synvert::Core
46
46
  # @param source [String] file source
47
47
  def write_file(file_path, source)
48
48
  source = Engine::ERB.decode(source) if /\.erb/.match?(file_path)
49
- File.write file_path, source.gsub(/ +\n/, "\n")
49
+ File.write(file_path, source.gsub(/ +\n/, "\n"))
50
50
  @file_source[file_path] = nil
51
51
  @file_ast[file_path] = nil
52
52
  end
@@ -92,6 +92,7 @@ module Synvert::Core
92
92
  next if Configuration.skip_files.include? file_path
93
93
 
94
94
  begin
95
+ puts file_path if Configuration.show_run_process
95
96
  conflict_actions = []
96
97
  source = +self.class.file_source(file_path)
97
98
  ast = self.class.file_ast(file_path)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Synvert
4
4
  module Core
5
- VERSION = '0.54.1'
5
+ VERSION = '0.56.0'
6
6
  end
7
7
  end
@@ -42,6 +42,21 @@ describe Parser::AST::Node do
42
42
  expect(node.name).to eq :Synvert
43
43
  end
44
44
 
45
+ it 'gets for lvar node' do
46
+ node = parse("foo = 'bar'\nfoo").children[1]
47
+ expect(node.name).to eq :foo
48
+ end
49
+
50
+ it 'gets for ivar node' do
51
+ node = parse("@foo = 'bar'\n@foo").children[1]
52
+ expect(node.name).to eq :@foo
53
+ end
54
+
55
+ it 'gets for cvar node' do
56
+ node = parse("@@foo = 'bar'\n@@foo").children[1]
57
+ expect(node.name).to eq :@@foo
58
+ end
59
+
45
60
  it 'gets for mlhs node' do
46
61
  node = parse('var.each { |(param1, param2)| }')
47
62
  expect(node.arguments.first.name).to eq node.arguments.first
@@ -7,7 +7,7 @@ module Synvert::Core
7
7
  subject {
8
8
  source = 'arr.map {}.flatten'
9
9
  node = Parser::CurrentRuby.parse(source)
10
- instance = double(current_node: node)
10
+ instance = double(current_node: node, file_source: source)
11
11
  Rewriter::DeleteAction.new(instance, :dot, :message)
12
12
  }
13
13
 
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.54.1
4
+ version: 0.56.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-09-08 00:00:00.000000000 Z
11
+ date: 2021-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport