ruby-next-core 0.10.0 → 0.10.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,34 +11,106 @@ module RubyNext
11
11
  def on_rasgn(node)
12
12
  context.track! self
13
13
 
14
+ node = super(node)
15
+
14
16
  val_node, asgn_node = *node
15
17
 
16
18
  remove(val_node.loc.expression.end.join(asgn_node.loc.expression))
17
19
  insert_before(val_node.loc.expression, "#{asgn_node.loc.expression.source} = ")
18
20
 
19
- process(
20
- asgn_node.updated(
21
- nil,
22
- asgn_node.children + [val_node]
23
- )
21
+ asgn_node.updated(
22
+ nil,
23
+ asgn_node.children + [val_node]
24
24
  )
25
25
  end
26
26
 
27
+ def on_vasgn(node)
28
+ return super(node) unless rightward?(node)
29
+
30
+ context.track! self
31
+
32
+ name, val_node = *node
33
+
34
+ remove(val_node.loc.expression.end.join(node.loc.name))
35
+ insert_before(val_node.loc.expression, "#{name} = ")
36
+
37
+ super(node)
38
+ end
39
+
40
+ def on_casgn(node)
41
+ return super(node) unless rightward?(node)
42
+
43
+ context.track! self
44
+
45
+ scope_node, name, val_node = *node
46
+
47
+ if scope_node
48
+ scope = scope_node.type == :cbase ? scope_node.loc.expression.source : "#{scope_node.loc.expression.source}::"
49
+ name = "#{scope}#{name}"
50
+ end
51
+
52
+ remove(val_node.loc.expression.end.join(node.loc.name))
53
+ insert_before(val_node.loc.expression, "#{name} = ")
54
+
55
+ super(node)
56
+ end
57
+
27
58
  def on_mrasgn(node)
28
59
  context.track! self
29
60
 
61
+ node = super(node)
62
+
30
63
  lhs, rhs = *node
31
64
 
32
65
  replace(lhs.loc.expression.end.join(rhs.loc.expression), ")")
33
66
  insert_before(lhs.loc.expression, "#{rhs.loc.expression.source} = (")
34
67
 
35
- process(
36
- node.updated(
37
- :masgn,
38
- [rhs, lhs]
39
- )
68
+ node.updated(
69
+ :masgn,
70
+ [rhs, lhs]
71
+ )
72
+ end
73
+
74
+ def on_masgn(node)
75
+ return super(node) unless rightward?(node)
76
+
77
+ context.track! self
78
+
79
+ rhs, lhs = *node
80
+
81
+ replace(lhs.loc.expression.end.join(rhs.loc.expression), ")")
82
+ insert_before(lhs.loc.expression, "#{rhs.loc.expression.source} = (")
83
+
84
+ node = super(node)
85
+
86
+ lhs, rhs = *node
87
+
88
+ node.updated(
89
+ nil,
90
+ [
91
+ lhs,
92
+ s(:begin, rhs)
93
+ ]
40
94
  )
41
95
  end
96
+
97
+ private
98
+
99
+ def rightward?(node)
100
+ # Location could be empty for node built by rewriters
101
+ return false unless node.loc&.operator
102
+
103
+ assignee_loc =
104
+ if node.type == :masgn
105
+ node.children[0].loc.expression
106
+ else
107
+ node.loc.name
108
+ end
109
+
110
+ return false unless assignee_loc
111
+
112
+ assignee_loc.begin_pos > node.loc.operator.end_pos
113
+ end
42
114
  end
43
115
  end
44
116
  end
@@ -15,13 +15,14 @@ module RubyNext
15
15
 
16
16
  receiver, *args = *node
17
17
 
18
- new_node = node.updated(
19
- :and,
20
- [
21
- process(safe_navigation(receiver)),
22
- s(:send, decsendize(receiver), *args)
23
- ]
24
- )
18
+ new_node = s(:begin,
19
+ node.updated(
20
+ :and,
21
+ [
22
+ process(safe_navigation(receiver)),
23
+ s(:send, decsendize(receiver), *args)
24
+ ]
25
+ ))
25
26
 
26
27
  replace(node.loc.expression, new_node)
27
28
 
@@ -33,13 +34,14 @@ module RubyNext
33
34
 
34
35
  context.track!(self)
35
36
 
36
- new_node = super(node.updated(
37
- :and,
38
- [
39
- process(safe_navigation(node.children[0].children[0])),
40
- process(node.updated(nil, node.children.map(&method(:decsendize))))
41
- ]
42
- ))
37
+ new_node = s(:begin,
38
+ super(node.updated(
39
+ :and,
40
+ [
41
+ process(safe_navigation(node.children[0].children[0])),
42
+ process(node.updated(nil, node.children.map(&method(:decsendize))))
43
+ ]
44
+ )))
43
45
 
44
46
  replace(node.loc.expression, new_node)
45
47
 
@@ -51,13 +53,14 @@ module RubyNext
51
53
 
52
54
  context.track!(self)
53
55
 
54
- new_node = super(node.updated(
55
- :and,
56
- [
57
- process(safe_navigation(node.children[0].children[0])),
58
- process(node.updated(nil, node.children.map(&method(:decsendize))))
59
- ]
60
- ))
56
+ new_node = s(:begin,
57
+ super(node.updated(
58
+ :and,
59
+ [
60
+ process(safe_navigation(node.children[0].children[0])),
61
+ process(node.updated(nil, node.children.map(&method(:decsendize))))
62
+ ]
63
+ )))
61
64
 
62
65
  replace(node.loc.expression, new_node)
63
66
 
@@ -75,11 +78,12 @@ module RubyNext
75
78
  # Transform: x&.y -> (!x.nil? && x.y) || nil
76
79
  # This allows us to handle `false&.to_s == "false"`
77
80
  def safe_navigation(node)
78
- s(:or,
79
- s(:send,
80
- s(:send, node, :nil?),
81
- :!),
82
- s(:nil))
81
+ s(:begin,
82
+ s(:or,
83
+ s(:send,
84
+ s(:send, node, :nil?),
85
+ :!),
86
+ s(:nil)))
83
87
  end
84
88
  end
85
89
  end
@@ -117,5 +117,81 @@ module RuboCop
117
117
  end
118
118
  end
119
119
  end
120
+
121
+ module Layout
122
+ require "rubocop/cop/layout/assignment_indentation"
123
+ AssignmentIndentation.prepend(Module.new do
124
+ POTENTIAL_RIGHT_TYPES = %i[ivasgn lvasgn cvasgn gvasgn casgn masgn].freeze
125
+
126
+ def check_assignment(node, *)
127
+ return if rightward?(node)
128
+ super
129
+ end
130
+
131
+ private
132
+
133
+ def rightward?(node)
134
+ return unless POTENTIAL_RIGHT_TYPES.include?(node.type)
135
+
136
+ return unless node.loc.operator
137
+
138
+ assignee_loc =
139
+ if node.type == :masgn
140
+ node.children[0].loc.expression
141
+ else
142
+ node.loc.name
143
+ end
144
+
145
+ return false unless assignee_loc
146
+
147
+ assignee_loc.begin_pos > node.loc.operator.end_pos
148
+ end
149
+ end)
150
+
151
+ require "rubocop/cop/layout/empty_line_between_defs"
152
+ EmptyLineBetweenDefs.prepend(Module.new do
153
+ def def_end(node)
154
+ return super unless node.loc.end.nil?
155
+
156
+ node.loc.expression.line
157
+ end
158
+ end)
159
+ end
160
+
161
+ module Style
162
+ require "rubocop/cop/style/single_line_methods"
163
+ SingleLineMethods.prepend(Module.new do
164
+ def on_def(node)
165
+ return if node.loc.end.nil?
166
+ super
167
+ end
168
+
169
+ def on_defs(node)
170
+ return if node.loc.end.nil?
171
+ super
172
+ end
173
+ end)
174
+
175
+ require "rubocop/cop/style/def_with_parentheses"
176
+ DefWithParentheses.prepend(Module.new do
177
+ def on_def(node)
178
+ return if node.loc.end.nil?
179
+ super
180
+ end
181
+
182
+ def on_defs(node)
183
+ return if node.loc.end.nil?
184
+ super
185
+ end
186
+ end)
187
+
188
+ require "rubocop/cop/style/trailing_method_end_statement"
189
+ TrailingMethodEndStatement.prepend(Module.new do
190
+ def on_def(node)
191
+ return if node.loc.end.nil?
192
+ super
193
+ end
194
+ end)
195
+ end
120
196
  end
121
197
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyNext
4
- VERSION = "0.10.0"
4
+ VERSION = "0.10.5"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-next-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.10.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dementyev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-02 00:00:00.000000000 Z
11
+ date: 2020-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-next-parser
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 3.0.0.0
19
+ version: 3.0.0.1
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 3.0.0.0
26
+ version: 3.0.0.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: unparser
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -31,6 +31,9 @@ dependencies:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.4.8
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: 0.6.0
34
37
  type: :development
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -38,6 +41,9 @@ dependencies:
38
41
  - - ">="
39
42
  - !ruby/object:Gem::Version
40
43
  version: 0.4.8
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: 0.6.0
41
47
  description: "\n Ruby Next Core is a zero deps version of Ruby Next meant to be
42
48
  used\n as as dependency in your gems.\n\n It contains all the polyfills and
43
49
  utility files but doesn't require transpiler\n dependencies to be install.\n
@@ -53,6 +59,7 @@ files:
53
59
  - LICENSE.txt
54
60
  - README.md
55
61
  - bin/parse
62
+ - bin/reparse
56
63
  - bin/ruby-next
57
64
  - bin/transform
58
65
  - lib/.rbnext/2.3/ruby-next/commands/core_ext.rb
@@ -61,6 +68,7 @@ files:
61
68
  - lib/.rbnext/2.3/ruby-next/language/rewriters/base.rb
62
69
  - lib/.rbnext/2.3/ruby-next/language/rewriters/endless_range.rb
63
70
  - lib/.rbnext/2.3/ruby-next/language/rewriters/pattern_matching.rb
71
+ - lib/.rbnext/2.3/ruby-next/language/rewriters/right_hand_assignment.rb
64
72
  - lib/.rbnext/2.3/ruby-next/utils.rb
65
73
  - lib/ruby-next.rb
66
74
  - lib/ruby-next/cli.rb