unparser 0.2.8 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +17 -0
- data/.rubocop.yml +1 -0
- data/Changelog.md +4 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +70 -64
- data/Rakefile +1 -0
- data/bin/unparser +2 -0
- data/config/devtools.yml +1 -1
- data/config/flay.yml +1 -1
- data/config/reek.yml +136 -136
- data/config/rubocop.yml +14 -1
- data/lib/unparser.rb +2 -0
- data/lib/unparser/ast.rb +8 -6
- data/lib/unparser/ast/local_variable_scope.rb +3 -1
- data/lib/unparser/buffer.rb +5 -1
- data/lib/unparser/cli.rb +8 -1
- data/lib/unparser/cli/color.rb +2 -0
- data/lib/unparser/cli/differ.rb +2 -0
- data/lib/unparser/cli/source.rb +7 -1
- data/lib/unparser/comments.rb +5 -0
- data/lib/unparser/constants.rb +8 -6
- data/lib/unparser/dsl.rb +2 -0
- data/lib/unparser/emitter.rb +18 -9
- data/lib/unparser/emitter/alias.rb +2 -0
- data/lib/unparser/emitter/argument.rb +3 -0
- data/lib/unparser/emitter/assignment.rb +5 -2
- data/lib/unparser/emitter/begin.rb +3 -1
- data/lib/unparser/emitter/binary.rb +2 -0
- data/lib/unparser/emitter/block.rb +3 -0
- data/lib/unparser/emitter/case.rb +4 -0
- data/lib/unparser/emitter/cbase.rb +2 -0
- data/lib/unparser/emitter/class.rb +3 -0
- data/lib/unparser/emitter/def.rb +3 -0
- data/lib/unparser/emitter/defined.rb +2 -0
- data/lib/unparser/emitter/empty.rb +2 -0
- data/lib/unparser/emitter/ensure.rb +2 -0
- data/lib/unparser/emitter/flipflop.rb +2 -0
- data/lib/unparser/emitter/flow_modifier.rb +3 -1
- data/lib/unparser/emitter/for.rb +2 -0
- data/lib/unparser/emitter/hookexe.rb +2 -0
- data/lib/unparser/emitter/if.rb +5 -0
- data/lib/unparser/emitter/literal.rb +2 -0
- data/lib/unparser/emitter/literal/array.rb +5 -4
- data/lib/unparser/emitter/literal/dynamic.rb +2 -0
- data/lib/unparser/emitter/literal/dynamic_body.rb +2 -0
- data/lib/unparser/emitter/literal/execute_string.rb +2 -0
- data/lib/unparser/emitter/literal/hash.rb +3 -2
- data/lib/unparser/emitter/literal/primitive.rb +3 -1
- data/lib/unparser/emitter/literal/range.rb +2 -0
- data/lib/unparser/emitter/literal/regexp.rb +2 -0
- data/lib/unparser/emitter/literal/singleton.rb +2 -0
- data/lib/unparser/emitter/match.rb +2 -0
- data/lib/unparser/emitter/meta.rb +2 -0
- data/lib/unparser/emitter/module.rb +2 -0
- data/lib/unparser/emitter/op_assign.rb +2 -0
- data/lib/unparser/emitter/redo.rb +2 -0
- data/lib/unparser/emitter/repetition.rb +4 -1
- data/lib/unparser/emitter/resbody.rb +4 -24
- data/lib/unparser/emitter/rescue.rb +5 -2
- data/lib/unparser/emitter/retry.rb +2 -0
- data/lib/unparser/emitter/root.rb +2 -0
- data/lib/unparser/emitter/send.rb +3 -0
- data/lib/unparser/emitter/send/arguments.rb +2 -0
- data/lib/unparser/emitter/send/attribute_assignment.rb +2 -0
- data/lib/unparser/emitter/send/binary.rb +2 -0
- data/lib/unparser/emitter/send/conditional.rb +2 -0
- data/lib/unparser/emitter/send/index.rb +2 -0
- data/lib/unparser/emitter/send/regular.rb +3 -0
- data/lib/unparser/emitter/send/unary.rb +5 -3
- data/lib/unparser/emitter/splat.rb +2 -0
- data/lib/unparser/emitter/super.rb +2 -0
- data/lib/unparser/emitter/undef.rb +2 -0
- data/lib/unparser/emitter/variable.rb +3 -0
- data/lib/unparser/emitter/yield.rb +3 -0
- data/lib/unparser/finalize.rb +2 -0
- data/lib/unparser/node_helpers.rb +6 -0
- data/lib/unparser/preprocessor.rb +3 -0
- data/spec/integrations.yml +3 -1
- data/spec/unit/unparser_spec.rb +3 -7
- data/unparser.gemspec +3 -3
- metadata +6 -6
- data/circle.yml +0 -6
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Unparser
|
2
4
|
class Emitter
|
3
5
|
|
@@ -36,7 +38,7 @@ module Unparser
|
|
36
38
|
children.empty?
|
37
39
|
end
|
38
40
|
|
39
|
-
TERMINATING_PARENT = %i
|
41
|
+
TERMINATING_PARENT = %i[root interpolated dyn_str_body].to_set.freeze
|
40
42
|
|
41
43
|
private
|
42
44
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Unparser
|
2
4
|
class Emitter
|
3
5
|
# Emitter for case nodes
|
@@ -34,6 +36,7 @@ module Unparser
|
|
34
36
|
def emit_else
|
35
37
|
else_branch = children.last
|
36
38
|
return unless else_branch
|
39
|
+
|
37
40
|
write(K_ELSE)
|
38
41
|
visit_indented(else_branch)
|
39
42
|
end
|
@@ -57,6 +60,7 @@ module Unparser
|
|
57
60
|
#
|
58
61
|
def emit_condition
|
59
62
|
return unless condition
|
63
|
+
|
60
64
|
write(WS)
|
61
65
|
visit(condition)
|
62
66
|
end
|
data/lib/unparser/emitter/def.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Unparser
|
2
4
|
class Emitter
|
3
5
|
# Emitter control flow modifiers
|
@@ -50,7 +52,7 @@ module Unparser
|
|
50
52
|
end
|
51
53
|
end
|
52
54
|
|
53
|
-
PARENS = [
|
55
|
+
PARENS = %i[if case begin].to_set.freeze
|
54
56
|
|
55
57
|
# Emit argument
|
56
58
|
#
|
data/lib/unparser/emitter/for.rb
CHANGED
data/lib/unparser/emitter/if.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Unparser
|
2
4
|
class Emitter
|
3
5
|
# Emitter if nodes
|
6
|
+
#
|
7
|
+
# ignore :reek:RepeatedConditional
|
4
8
|
class If < self
|
5
9
|
handle :if
|
6
10
|
|
@@ -122,6 +126,7 @@ module Unparser
|
|
122
126
|
#
|
123
127
|
def emit_else_branch
|
124
128
|
return unless else_branch
|
129
|
+
|
125
130
|
write(K_ELSE) unless unless?
|
126
131
|
visit_indented(else_branch)
|
127
132
|
end
|
@@ -1,12 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Unparser
|
2
4
|
class Emitter
|
3
5
|
class Literal
|
4
6
|
|
5
7
|
# Array literal emitter
|
6
8
|
class Array < self
|
7
|
-
OPEN
|
8
|
-
CLOSE
|
9
|
-
DELIMITER = ', '.freeze
|
9
|
+
OPEN = '['.freeze
|
10
|
+
CLOSE = ']'.freeze
|
10
11
|
|
11
12
|
handle :array
|
12
13
|
|
@@ -20,7 +21,7 @@ module Unparser
|
|
20
21
|
#
|
21
22
|
def dispatch
|
22
23
|
parentheses(OPEN, CLOSE) do
|
23
|
-
delimited(children
|
24
|
+
delimited(children)
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Unparser
|
2
4
|
class Emitter
|
3
5
|
class Literal
|
@@ -70,7 +72,6 @@ module Unparser
|
|
70
72
|
# Emitter for hash bodies
|
71
73
|
class HashBody < self
|
72
74
|
|
73
|
-
DELIMITER = ', '.freeze
|
74
75
|
BAREWORD = /\A[A-Za-z_][A-Za-z_0-9]*[?!]?\z/.freeze
|
75
76
|
|
76
77
|
handle :hash_body
|
@@ -84,7 +85,7 @@ module Unparser
|
|
84
85
|
# @api private
|
85
86
|
#
|
86
87
|
def dispatch
|
87
|
-
delimited(effective_body
|
88
|
+
delimited(effective_body)
|
88
89
|
end
|
89
90
|
|
90
91
|
# Return effective body
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Unparser
|
2
4
|
class Emitter
|
3
5
|
class Literal
|
@@ -131,7 +133,7 @@ module Unparser
|
|
131
133
|
# @api private
|
132
134
|
#
|
133
135
|
def dispatch
|
134
|
-
conditional_parentheses(parent.is_a?(
|
136
|
+
conditional_parentheses(parent.is_a?(Send) && value.negative?) do
|
135
137
|
write(value.inspect)
|
136
138
|
end
|
137
139
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Unparser
|
2
4
|
class Emitter
|
3
5
|
|
@@ -65,7 +67,8 @@ module Unparser
|
|
65
67
|
# @api private
|
66
68
|
#
|
67
69
|
def postcontrol?
|
68
|
-
return
|
70
|
+
return nil unless body # greez from falsyness
|
71
|
+
|
69
72
|
local_variable_scope.first_assignment_in_body_and_used_in_condition?(body, condition)
|
70
73
|
end
|
71
74
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Unparser
|
2
4
|
class Emitter
|
3
5
|
# Emitter for rescue body nodes
|
@@ -20,30 +22,6 @@ module Unparser
|
|
20
22
|
write(K_RESCUE, WS)
|
21
23
|
visit_plain(body)
|
22
24
|
end
|
23
|
-
|
24
|
-
# Emit exception
|
25
|
-
#
|
26
|
-
# @return [undefined]
|
27
|
-
#
|
28
|
-
# @api private
|
29
|
-
#
|
30
|
-
def emit_exception
|
31
|
-
return unless exception
|
32
|
-
ws
|
33
|
-
delimited(exception.children)
|
34
|
-
end
|
35
|
-
|
36
|
-
# Emit assignment
|
37
|
-
#
|
38
|
-
# @return [undefined]
|
39
|
-
#
|
40
|
-
# @api private
|
41
|
-
#
|
42
|
-
def emit_assignment
|
43
|
-
return unless assignment
|
44
|
-
write(WS, T_ASR, WS)
|
45
|
-
visit(assignment)
|
46
|
-
end
|
47
25
|
end
|
48
26
|
|
49
27
|
# Emitter for resbody in keyworkd-embedded form
|
@@ -74,6 +52,7 @@ module Unparser
|
|
74
52
|
#
|
75
53
|
def emit_exception
|
76
54
|
return unless exception
|
55
|
+
|
77
56
|
ws
|
78
57
|
delimited(exception.children)
|
79
58
|
end
|
@@ -86,6 +65,7 @@ module Unparser
|
|
86
65
|
#
|
87
66
|
def emit_assignment
|
88
67
|
return unless assignment
|
68
|
+
|
89
69
|
write(WS, T_ASR, WS)
|
90
70
|
visit(assignment)
|
91
71
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Unparser
|
2
4
|
class Emitter
|
3
5
|
# Emitter for rescue nodes
|
@@ -10,9 +12,9 @@ module Unparser
|
|
10
12
|
|
11
13
|
define_group :rescue_bodies, 1..-2
|
12
14
|
|
13
|
-
EMBEDDED_TYPES = [
|
15
|
+
EMBEDDED_TYPES = %i[def defs kwbegin ensure].to_set.freeze
|
14
16
|
|
15
|
-
NOINDENT_STANDALONE_RESCUE = [
|
17
|
+
NOINDENT_STANDALONE_RESCUE = %i[root begin pair_rocket pair_colon lvasgn ivasgn].to_set.freeze
|
16
18
|
|
17
19
|
private
|
18
20
|
|
@@ -86,6 +88,7 @@ module Unparser
|
|
86
88
|
#
|
87
89
|
def emit_else
|
88
90
|
return unless else_branch
|
91
|
+
|
89
92
|
write(K_ELSE)
|
90
93
|
visit_indented(else_branch)
|
91
94
|
end
|