unparser 0.4.9 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/bin/unparser +1 -1
  3. data/lib/unparser.rb +98 -61
  4. data/lib/unparser/ast.rb +0 -1
  5. data/lib/unparser/ast/local_variable_scope.rb +6 -76
  6. data/lib/unparser/buffer.rb +19 -16
  7. data/lib/unparser/cli.rb +26 -39
  8. data/lib/unparser/color.rb +0 -3
  9. data/lib/unparser/comments.rb +0 -26
  10. data/lib/unparser/constants.rb +4 -53
  11. data/lib/unparser/diff.rb +0 -17
  12. data/lib/unparser/dsl.rb +0 -32
  13. data/lib/unparser/emitter.rb +23 -425
  14. data/lib/unparser/emitter/alias.rb +2 -8
  15. data/lib/unparser/emitter/args.rb +45 -0
  16. data/lib/unparser/emitter/argument.rb +8 -166
  17. data/lib/unparser/emitter/array.rb +27 -0
  18. data/lib/unparser/emitter/array_pattern.rb +29 -0
  19. data/lib/unparser/emitter/assignment.rb +36 -127
  20. data/lib/unparser/emitter/begin.rb +9 -84
  21. data/lib/unparser/emitter/binary.rb +7 -20
  22. data/lib/unparser/emitter/block.rb +57 -41
  23. data/lib/unparser/emitter/case.rb +6 -48
  24. data/lib/unparser/emitter/case_guard.rb +27 -0
  25. data/lib/unparser/emitter/case_match.rb +40 -0
  26. data/lib/unparser/emitter/cbase.rb +1 -3
  27. data/lib/unparser/emitter/class.rb +6 -26
  28. data/lib/unparser/emitter/const_pattern.rb +24 -0
  29. data/lib/unparser/emitter/def.rb +7 -51
  30. data/lib/unparser/emitter/defined.rb +2 -12
  31. data/lib/unparser/emitter/dstr.rb +22 -0
  32. data/lib/unparser/emitter/dsym.rb +41 -0
  33. data/lib/unparser/emitter/flipflop.rb +11 -10
  34. data/lib/unparser/emitter/float.rb +29 -0
  35. data/lib/unparser/emitter/flow_modifier.rb +8 -55
  36. data/lib/unparser/emitter/for.rb +5 -19
  37. data/lib/unparser/emitter/hash.rb +74 -0
  38. data/lib/unparser/emitter/hash_pattern.rb +67 -0
  39. data/lib/unparser/emitter/hookexe.rb +5 -11
  40. data/lib/unparser/emitter/if.rb +9 -73
  41. data/lib/unparser/emitter/in_match.rb +21 -0
  42. data/lib/unparser/emitter/in_pattern.rb +34 -0
  43. data/lib/unparser/emitter/index.rb +21 -88
  44. data/lib/unparser/emitter/kwbegin.rb +31 -0
  45. data/lib/unparser/emitter/lambda.rb +0 -8
  46. data/lib/unparser/emitter/masgn.rb +20 -0
  47. data/lib/unparser/emitter/match.rb +3 -17
  48. data/lib/unparser/emitter/match_alt.rb +23 -0
  49. data/lib/unparser/emitter/match_as.rb +21 -0
  50. data/lib/unparser/emitter/match_rest.rb +26 -0
  51. data/lib/unparser/emitter/match_var.rb +19 -0
  52. data/lib/unparser/emitter/mlhs.rb +40 -0
  53. data/lib/unparser/emitter/module.rb +3 -9
  54. data/lib/unparser/emitter/op_assign.rb +12 -27
  55. data/lib/unparser/emitter/pin.rb +19 -0
  56. data/lib/unparser/emitter/primitive.rb +93 -0
  57. data/lib/unparser/emitter/range.rb +35 -0
  58. data/lib/unparser/emitter/regexp.rb +35 -0
  59. data/lib/unparser/emitter/repetition.rb +17 -57
  60. data/lib/unparser/emitter/rescue.rb +1 -97
  61. data/lib/unparser/emitter/root.rb +17 -1
  62. data/lib/unparser/emitter/send.rb +10 -219
  63. data/lib/unparser/emitter/simple.rb +33 -0
  64. data/lib/unparser/emitter/splat.rb +2 -18
  65. data/lib/unparser/emitter/super.rb +1 -29
  66. data/lib/unparser/emitter/undef.rb +1 -9
  67. data/lib/unparser/emitter/variable.rb +1 -31
  68. data/lib/unparser/emitter/xstr.rb +72 -0
  69. data/lib/unparser/emitter/yield.rb +1 -9
  70. data/lib/unparser/generation.rb +250 -0
  71. data/lib/unparser/node_details.rb +21 -0
  72. data/lib/unparser/node_details/send.rb +62 -0
  73. data/lib/unparser/node_helpers.rb +45 -6
  74. data/lib/unparser/validation.rb +37 -35
  75. data/lib/unparser/writer.rb +15 -0
  76. data/lib/unparser/writer/binary.rb +99 -0
  77. data/lib/unparser/writer/dynamic_string.rb +229 -0
  78. data/lib/unparser/writer/resbody.rb +40 -0
  79. data/lib/unparser/writer/rescue.rb +39 -0
  80. data/lib/unparser/writer/send.rb +124 -0
  81. data/lib/unparser/{emitter → writer}/send/attribute_assignment.rb +11 -26
  82. data/lib/unparser/writer/send/binary.rb +27 -0
  83. data/lib/unparser/writer/send/conditional.rb +25 -0
  84. data/lib/unparser/writer/send/regular.rb +33 -0
  85. data/lib/unparser/{emitter → writer}/send/unary.rb +10 -17
  86. metadata +63 -31
  87. data/lib/unparser/emitter/empty.rb +0 -23
  88. data/lib/unparser/emitter/ensure.rb +0 -37
  89. data/lib/unparser/emitter/literal.rb +0 -10
  90. data/lib/unparser/emitter/literal/array.rb +0 -29
  91. data/lib/unparser/emitter/literal/dynamic.rb +0 -53
  92. data/lib/unparser/emitter/literal/dynamic_body.rb +0 -132
  93. data/lib/unparser/emitter/literal/execute_string.rb +0 -38
  94. data/lib/unparser/emitter/literal/hash.rb +0 -156
  95. data/lib/unparser/emitter/literal/primitive.rb +0 -145
  96. data/lib/unparser/emitter/literal/range.rb +0 -36
  97. data/lib/unparser/emitter/literal/regexp.rb +0 -114
  98. data/lib/unparser/emitter/literal/singleton.rb +0 -26
  99. data/lib/unparser/emitter/meta.rb +0 -16
  100. data/lib/unparser/emitter/redo.rb +0 -25
  101. data/lib/unparser/emitter/resbody.rb +0 -76
  102. data/lib/unparser/emitter/retry.rb +0 -25
  103. data/lib/unparser/emitter/send/binary.rb +0 -57
  104. data/lib/unparser/emitter/send/conditional.rb +0 -40
  105. data/lib/unparser/emitter/send/regular.rb +0 -40
  106. data/lib/unparser/preprocessor.rb +0 -159
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 10fe213bc822f4da69795458d89fc34693b5c57f1add6e910a77f8f456f5cff4
4
- data.tar.gz: a1333c5af931e182f3fe0c5586d010f306f5b51d5e8f5204beb2bd47cce8a9d2
3
+ metadata.gz: c326e601dd3bcfdc7363e456e07d1b15ef323ae095e39026e094205de5206119
4
+ data.tar.gz: a839f69163fab291b893a7e0702771848fc4632161414dff4b4528ad12568573
5
5
  SHA512:
6
- metadata.gz: aa4d72074d1f1aeeafaf7f87cc53f5a6754dcb06ae99d1c73191b776bb10c9b58db0be2fdd8c9487e61e0cfdc1918e78aac35adccc7b706ea2b9b5b4101faaaf
7
- data.tar.gz: 336938a288a1ada6f33db990535b7d487d618a4f60725101b282c5654fd8e1c953c412c5b8dc9cad9afb936c64ddafd65b5fa0797016022c0a8ce52df35c3ec7
6
+ metadata.gz: b6821013d903d32988111efbea734cc1daaeb02d5fc4b3073c215365f365fd86d52a40c4b495175610d30c30a467670ea2c37357acbb8191623940673119cfae
7
+ data.tar.gz: 924afece12fe65ab3c4783420ca6ce200db08249830eb0a0cdd16b69ddb05f7377dc0900e832abd0957c97b0d4fe259eaa0c320c67e714d9daeed033575bd235
@@ -5,6 +5,6 @@ trap('INT') do |status|
5
5
  exit! 128 + status
6
6
  end
7
7
 
8
- require 'unparser/cli'
8
+ require 'unparser'
9
9
 
10
10
  exit Unparser::CLI.run(ARGV)
@@ -6,6 +6,7 @@ require 'concord'
6
6
  require 'diff/lcs'
7
7
  require 'diff/lcs/hunk'
8
8
  require 'mprelude'
9
+ require 'optparse'
9
10
  require 'parser/current'
10
11
  require 'procto'
11
12
  require 'set'
@@ -15,6 +16,12 @@ module Unparser
15
16
  # Unparser specific AST builder defaulting to modern AST format
16
17
  class Builder < Parser::Builders::Default
17
18
  modernize
19
+
20
+ def initialize
21
+ super
22
+
23
+ self.emit_file_line_as_literals = false
24
+ end
18
25
  end
19
26
 
20
27
  EMPTY_STRING = ''.freeze
@@ -32,12 +39,27 @@ module Unparser
32
39
  # @api private
33
40
  #
34
41
  def self.unparse(node, comment_array = [])
35
- node = Preprocessor.run(node)
36
- buffer = Buffer.new
37
- comments = Comments.new(comment_array)
38
- root = Emitter::Root.new(Parser::AST::Node.new(:root, [node]), buffer, comments)
39
- Emitter.emitter(node, root).write_to_buffer
40
- buffer.content
42
+ return '' if node.nil?
43
+
44
+ Buffer.new.tap do |buffer|
45
+ Emitter::Root.new(
46
+ buffer,
47
+ node,
48
+ Comments.new(comment_array)
49
+ ).write_to_buffer
50
+ end.content
51
+ end
52
+
53
+ # Unparse capturing errors
54
+ #
55
+ # This is mostly useful for writing testing tools against unparser.
56
+ #
57
+ # @param [Parser::AST::Node, nil] node
58
+ #
59
+ # @return [Either<Exception, String>]
60
+ def self.unparse_either(node)
61
+ MPrelude::Either
62
+ .wrap_error(Exception) { unparse(node) }
41
63
  end
42
64
 
43
65
  # Parse string into AST
@@ -74,8 +96,6 @@ module Unparser
74
96
  # @return [Parser::Base]
75
97
  #
76
98
  # @api private
77
- #
78
- # ignore :reek:NestedIterators
79
99
  def self.parser
80
100
  Parser::CurrentRuby.new(Builder.new).tap do |parser|
81
101
  parser.diagnostics.tap do |diagnostics|
@@ -100,75 +120,92 @@ module Unparser
100
120
  # @param [String] source
101
121
  #
102
122
  # @return [Parser::Source::Buffer]
103
- def self.buffer(source)
104
- Parser::Source::Buffer.new('(string)').tap do |buffer|
105
- buffer.source = source
106
- end
123
+ def self.buffer(source, identification = '(string)')
124
+ Parser::Source::Buffer.new(identification, source: source)
107
125
  end
108
126
  end # Unparser
109
127
 
110
- require 'unparser/buffer'
111
128
  require 'unparser/node_helpers'
112
- require 'unparser/preprocessor'
113
- require 'unparser/comments'
114
- require 'unparser/constants'
115
- require 'unparser/dsl'
116
129
  require 'unparser/ast'
117
130
  require 'unparser/ast/local_variable_scope'
118
- require 'unparser/diff'
131
+ require 'unparser/buffer'
132
+ require 'unparser/generation'
119
133
  require 'unparser/color'
134
+ require 'unparser/comments'
135
+ require 'unparser/constants'
136
+ require 'unparser/diff'
137
+ require 'unparser/dsl'
120
138
  require 'unparser/emitter'
121
- require 'unparser/emitter/literal'
122
- require 'unparser/emitter/literal/primitive'
123
- require 'unparser/emitter/literal/singleton'
124
- require 'unparser/emitter/literal/dynamic'
125
- require 'unparser/emitter/literal/regexp'
126
- require 'unparser/emitter/literal/array'
127
- require 'unparser/emitter/literal/hash'
128
- require 'unparser/emitter/literal/range'
129
- require 'unparser/emitter/literal/dynamic_body'
130
- require 'unparser/emitter/literal/execute_string'
131
- require 'unparser/emitter/meta'
132
- require 'unparser/emitter/send'
133
- require 'unparser/emitter/send/unary'
134
- require 'unparser/emitter/send/binary'
135
- require 'unparser/emitter/send/regular'
136
- require 'unparser/emitter/send/conditional'
137
- require 'unparser/emitter/send/attribute_assignment'
138
- require 'unparser/emitter/block'
139
- require 'unparser/emitter/assignment'
140
- require 'unparser/emitter/variable'
141
- require 'unparser/emitter/splat'
142
- require 'unparser/emitter/cbase'
139
+ require 'unparser/emitter/alias'
140
+ require 'unparser/emitter/args'
143
141
  require 'unparser/emitter/argument'
142
+ require 'unparser/emitter/array'
143
+ require 'unparser/emitter/array_pattern'
144
+ require 'unparser/emitter/assignment'
144
145
  require 'unparser/emitter/begin'
145
- require 'unparser/emitter/flow_modifier'
146
- require 'unparser/emitter/undef'
147
- require 'unparser/emitter/def'
146
+ require 'unparser/emitter/binary'
147
+ require 'unparser/emitter/block'
148
+ require 'unparser/emitter/case'
149
+ require 'unparser/emitter/case_guard'
150
+ require 'unparser/emitter/case_match'
151
+ require 'unparser/emitter/cbase'
148
152
  require 'unparser/emitter/class'
149
- require 'unparser/emitter/module'
150
- require 'unparser/emitter/op_assign'
153
+ require 'unparser/emitter/const_pattern'
154
+ require 'unparser/emitter/def'
151
155
  require 'unparser/emitter/defined'
156
+ require 'unparser/emitter/dstr'
157
+ require 'unparser/emitter/dsym'
158
+ require 'unparser/emitter/flipflop'
159
+ require 'unparser/emitter/float'
160
+ require 'unparser/emitter/flow_modifier'
161
+ require 'unparser/emitter/for'
162
+ require 'unparser/emitter/hash'
163
+ require 'unparser/emitter/hash_pattern'
152
164
  require 'unparser/emitter/hookexe'
153
- require 'unparser/emitter/super'
154
- require 'unparser/emitter/retry'
155
- require 'unparser/emitter/redo'
156
165
  require 'unparser/emitter/if'
157
- require 'unparser/emitter/alias'
158
- require 'unparser/emitter/yield'
159
- require 'unparser/emitter/binary'
160
- require 'unparser/emitter/case'
161
- require 'unparser/emitter/for'
162
- require 'unparser/emitter/repetition'
163
- require 'unparser/emitter/root'
164
- require 'unparser/emitter/match'
165
- require 'unparser/emitter/empty'
166
- require 'unparser/emitter/flipflop'
167
- require 'unparser/emitter/rescue'
168
- require 'unparser/emitter/resbody'
169
- require 'unparser/emitter/ensure'
166
+ require 'unparser/emitter/in_match'
167
+ require 'unparser/emitter/in_pattern'
170
168
  require 'unparser/emitter/index'
169
+ require 'unparser/emitter/kwbegin'
171
170
  require 'unparser/emitter/lambda'
171
+ require 'unparser/emitter/masgn'
172
+ require 'unparser/emitter/match'
173
+ require 'unparser/emitter/match_alt'
174
+ require 'unparser/emitter/match_as'
175
+ require 'unparser/emitter/match_rest'
176
+ require 'unparser/emitter/match_var'
177
+ require 'unparser/emitter/mlhs'
178
+ require 'unparser/emitter/module'
179
+ require 'unparser/emitter/op_assign'
180
+ require 'unparser/emitter/pin'
181
+ require 'unparser/emitter/primitive'
182
+ require 'unparser/emitter/range'
183
+ require 'unparser/emitter/regexp'
184
+ require 'unparser/emitter/repetition'
185
+ require 'unparser/emitter/rescue'
186
+ require 'unparser/emitter/root'
187
+ require 'unparser/emitter/send'
188
+ require 'unparser/emitter/simple'
189
+ require 'unparser/emitter/splat'
190
+ require 'unparser/emitter/super'
191
+ require 'unparser/emitter/undef'
192
+ require 'unparser/emitter/variable'
193
+ require 'unparser/emitter/xstr'
194
+ require 'unparser/emitter/yield'
195
+ require 'unparser/writer'
196
+ require 'unparser/writer/binary'
197
+ require 'unparser/writer/dynamic_string'
198
+ require 'unparser/writer/resbody'
199
+ require 'unparser/writer/rescue'
200
+ require 'unparser/writer/send'
201
+ require 'unparser/writer/send/attribute_assignment'
202
+ require 'unparser/writer/send/binary'
203
+ require 'unparser/writer/send/regular'
204
+ require 'unparser/writer/send/unary'
205
+ require 'unparser/node_details'
206
+ require 'unparser/node_details/send'
207
+ require 'unparser/cli'
208
+
172
209
  require 'unparser/validation'
173
210
  # make it easy for zombie
174
211
  require 'unparser/finalize'
@@ -2,7 +2,6 @@
2
2
 
3
3
  module Unparser
4
4
  # Namespace for AST processing tools
5
- # :reek:TooManyConstants
6
5
  module AST
7
6
 
8
7
  FIRST_CHILD = ->(node) { node.children.first }.freeze
@@ -61,35 +61,22 @@ module Unparser
61
61
  #
62
62
  # @api private
63
63
  #
64
- def first_assignment_in_body_and_used_in_condition?(body, condition)
65
- condition_reads = AST.local_variable_reads(condition)
64
+ def first_assignment_in?(left, right)
65
+ condition_reads = AST.local_variable_reads(right)
66
66
 
67
- candidates = AST.local_variable_assignments(body).select do |node|
68
- name = node.children.first
69
- condition_reads.include?(name)
67
+ candidates = AST.local_variable_assignments(left).select do |node|
68
+ condition_reads.include?(node.children.first)
70
69
  end
71
70
 
72
- candidates.any? do |node|
73
- first_assignment?(node)
74
- end
71
+ candidates.any?(&public_method(:first_assignment?))
75
72
  end
76
73
 
77
74
  private
78
75
 
79
- # Match node
80
- #
81
- # @param [Parser::AST::Node] needle
82
- # if block given
83
- #
84
- # @return [Boolean]
85
- #
86
- # @api private
87
- #
88
76
  def match(needle)
89
77
  @items.each do |node, current, before|
90
78
  return yield(current, before) if node.equal?(needle)
91
79
  end
92
- false
93
80
  end
94
81
 
95
82
  end # LocalVariableScope
@@ -137,25 +124,10 @@ module Unparser
137
124
 
138
125
  private
139
126
 
140
- # Return current set of local variables
141
- #
142
- # @return [Set<Symbol>]
143
- #
144
- # @api private
145
- #
146
127
  def current
147
128
  @stack.last
148
129
  end
149
130
 
150
- # Visit node and record local variable state
151
- #
152
- # @param [Parser::AST::Node] node
153
- #
154
- # @return [undefined]
155
- #
156
- # @api private
157
- #
158
- # ignore :reek:LongYieldList
159
131
  def visit(node, &block)
160
132
  before = current.dup
161
133
  enter(node)
@@ -166,75 +138,33 @@ module Unparser
166
138
  leave(node)
167
139
  end
168
140
 
169
- # Record local variable state
170
- #
171
- # @param [Parser::AST::Node] node
172
- #
173
- # @return [undefined]
174
- #
175
- # @api private
176
- #
177
141
  def enter(node)
178
142
  case node.type
179
143
  when *RESET_NODES
180
144
  push_reset
181
- when *ASSIGN_NODES
145
+ when ASSIGN_NODES
182
146
  define(node.children.first)
183
147
  when *INHERIT_NODES
184
148
  push_inherit
185
149
  end
186
150
  end
187
151
 
188
- # Pop from local variable state
189
- #
190
- # @param [Parser::AST::Node] node
191
- #
192
- # @return [undefined]
193
- #
194
- # @api private
195
- #
196
152
  def leave(node)
197
153
  pop if CLOSE_NODES.include?(node.type)
198
154
  end
199
155
 
200
- # Define a local variable on current stack
201
- #
202
- # @param [Symbol] name
203
- #
204
- # @return [undefined]
205
- #
206
- # @api private
207
- #
208
156
  def define(name)
209
157
  current << name
210
158
  end
211
159
 
212
- # Push reset scope on stack
213
- #
214
- # @return [undefined]
215
- #
216
- # @api private
217
- #
218
160
  def push_reset
219
161
  @stack << Set.new
220
162
  end
221
163
 
222
- # Push inherited lvar scope on stack
223
- #
224
- # @return [undefined]
225
- #
226
- # @api private
227
- #
228
164
  def push_inherit
229
165
  @stack << current.dup
230
166
  end
231
167
 
232
- # Pop lvar scope from stack
233
- #
234
- # @return [undefined]
235
- #
236
- # @api private
237
- #
238
168
  def pop
239
169
  @stack.pop
240
170
  end
@@ -3,8 +3,6 @@
3
3
  module Unparser
4
4
 
5
5
  # Buffer used to emit into
6
- #
7
- # ignore :reek:TooManyMethods
8
6
  class Buffer
9
7
 
10
8
  NL = "\n".freeze
@@ -82,6 +80,13 @@ module Unparser
82
80
  self
83
81
  end
84
82
 
83
+ def root_indent
84
+ before = @indent
85
+ @indent = 0
86
+ yield
87
+ @indent = before
88
+ end
89
+
85
90
  # Test for a fresh line
86
91
  #
87
92
  # @return [Boolean]
@@ -114,26 +119,24 @@ module Unparser
114
119
  @content[size_before..-1]
115
120
  end
116
121
 
117
- private
118
-
119
- INDENT_SPACE = ' '.freeze
120
-
121
- # Write prefix
122
- #
123
- # @return [String]
122
+ # Write raw fragment to buffer
124
123
  #
125
- # @api private
126
- #
127
- def prefix
128
- write(INDENT_SPACE * @indent)
129
- end
130
-
131
- # Write to content buffer
124
+ # Does not do indentation logic.
132
125
  #
133
126
  # @param [String] fragment
134
127
  #
128
+ # @return [self]
135
129
  def write(fragment)
136
130
  @content << fragment
131
+ self
132
+ end
133
+
134
+ private
135
+
136
+ INDENT_SPACE = ' '.freeze
137
+
138
+ def prefix
139
+ write(INDENT_SPACE * @indent)
137
140
  end
138
141
 
139
142
  end # Buffer
@@ -1,13 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'unparser'
4
- require 'optparse'
5
-
6
3
  module Unparser
7
4
  # Unparser CLI implementation
8
- #
9
- # :reek:InstanceVariableAssumption
10
- # :reek:TooManyInstanceVariables
11
5
  class CLI
12
6
 
13
7
  EXIT_SUCCESS = 0
@@ -26,6 +20,13 @@ module Unparser
26
20
  def validation
27
21
  Validation.from_path(path)
28
22
  end
23
+
24
+ # Literal for this target
25
+ #
26
+ # @return [Validation]
27
+ def literal_validation
28
+ Validation::Literal.from_path(path)
29
+ end
29
30
  end
30
31
 
31
32
  # String target
@@ -38,6 +39,13 @@ module Unparser
38
39
  def validation
39
40
  Validation.from_string(string)
40
41
  end
42
+
43
+ # Literal for this target
44
+ #
45
+ # @return [Validation]
46
+ def literal_validation
47
+ Validation::Literal.from_string(path)
48
+ end
41
49
  end # String
42
50
  end # Target
43
51
 
@@ -47,7 +55,7 @@ module Unparser
47
55
  #
48
56
  # @param [Array<String>] arguments
49
57
  #
50
- # @return [Fixnum]
58
+ # @return [Integer]
51
59
  # the exit status
52
60
  #
53
61
  # @api private
@@ -63,15 +71,14 @@ module Unparser
63
71
  # @return [undefined]
64
72
  #
65
73
  # @api private
66
- #
67
- # ignore :reek:TooManyStatements
68
74
  def initialize(arguments)
69
75
  @ignore = Set.new
70
76
  @targets = []
71
77
 
72
- @success = true
73
- @fail_fast = false
74
- @verbose = false
78
+ @fail_fast = false
79
+ @success = true
80
+ @validation = :validation
81
+ @verbose = false
75
82
 
76
83
  opts = OptionParser.new do |builder|
77
84
  add_options(builder)
@@ -90,7 +97,7 @@ module Unparser
90
97
  #
91
98
  # @api private
92
99
  #
93
- # ignore :reek:TooManyStatements
100
+ # rubocop:disable Metrics/MethodLength
94
101
  def add_options(builder)
95
102
  builder.banner = 'usage: unparse [options] FILE [FILE]'
96
103
  builder.separator('')
@@ -103,6 +110,9 @@ module Unparser
103
110
  builder.on('-v', '--verbose') do
104
111
  @verbose = true
105
112
  end
113
+ builder.on('-l', '--literal') do
114
+ @validation = :literal_validation
115
+ end
106
116
  builder.on('--ignore FILE') do |file|
107
117
  @ignore.merge(targets(file))
108
118
  end
@@ -110,10 +120,11 @@ module Unparser
110
120
  @fail_fast = true
111
121
  end
112
122
  end
123
+ # rubocop:enable Metrics/MethodLength
113
124
 
114
125
  # Return exit status
115
126
  #
116
- # @return [Fixnum]
127
+ # @return [Integer]
117
128
  #
118
129
  # @api private
119
130
  #
@@ -128,16 +139,8 @@ module Unparser
128
139
 
129
140
  private
130
141
 
131
- # Process target
132
- #
133
- # @param [Target] target
134
- #
135
- # @return [undefined]
136
- #
137
- # @api private
138
- #
139
142
  def process_target(target)
140
- validation = target.validation
143
+ validation = target.public_send(@validation)
141
144
  if validation.success?
142
145
  puts validation.report if @verbose
143
146
  puts "Success: #{validation.identification}"
@@ -148,12 +151,6 @@ module Unparser
148
151
  end
149
152
  end
150
153
 
151
- # Return effective targets
152
- #
153
- # @return [Enumerable<Target>]
154
- #
155
- # @api private
156
- #
157
154
  def effective_targets
158
155
  if @start_with
159
156
  reject = true
@@ -169,15 +166,6 @@ module Unparser
169
166
  end.reject(&@ignore.method(:include?))
170
167
  end
171
168
 
172
- # Return targets for file name
173
- #
174
- # @param [String] file_name
175
- #
176
- # @return [Enumerable<Target>]
177
- #
178
- # @api private
179
- #
180
- # ignore :reek:UtilityFunction
181
169
  def targets(file_name)
182
170
  if File.directory?(file_name)
183
171
  Dir.glob(File.join(file_name, '**/*.rb')).sort
@@ -187,6 +175,5 @@ module Unparser
187
175
  Dir.glob(file_name).sort
188
176
  end.map { |file| Target::Path.new(Pathname.new(file)) }
189
177
  end
190
-
191
178
  end # CLI
192
179
  end # Unparser