unparser 0.4.8 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +20 -5
  3. data/bin/unparser +1 -1
  4. data/lib/unparser.rb +115 -61
  5. data/lib/unparser/ast.rb +0 -1
  6. data/lib/unparser/ast/local_variable_scope.rb +6 -76
  7. data/lib/unparser/buffer.rb +19 -16
  8. data/lib/unparser/cli.rb +26 -39
  9. data/lib/unparser/color.rb +0 -3
  10. data/lib/unparser/comments.rb +0 -26
  11. data/lib/unparser/constants.rb +4 -53
  12. data/lib/unparser/diff.rb +0 -17
  13. data/lib/unparser/dsl.rb +0 -32
  14. data/lib/unparser/emitter.rb +23 -425
  15. data/lib/unparser/emitter/alias.rb +2 -8
  16. data/lib/unparser/emitter/args.rb +45 -0
  17. data/lib/unparser/emitter/argument.rb +8 -166
  18. data/lib/unparser/emitter/array.rb +27 -0
  19. data/lib/unparser/emitter/array_pattern.rb +29 -0
  20. data/lib/unparser/emitter/assignment.rb +36 -127
  21. data/lib/unparser/emitter/begin.rb +9 -84
  22. data/lib/unparser/emitter/binary.rb +7 -20
  23. data/lib/unparser/emitter/block.rb +57 -41
  24. data/lib/unparser/emitter/case.rb +6 -48
  25. data/lib/unparser/emitter/case_guard.rb +27 -0
  26. data/lib/unparser/emitter/case_match.rb +40 -0
  27. data/lib/unparser/emitter/cbase.rb +1 -3
  28. data/lib/unparser/emitter/class.rb +6 -26
  29. data/lib/unparser/emitter/const_pattern.rb +24 -0
  30. data/lib/unparser/emitter/def.rb +7 -51
  31. data/lib/unparser/emitter/defined.rb +2 -12
  32. data/lib/unparser/emitter/dstr.rb +22 -0
  33. data/lib/unparser/emitter/dsym.rb +41 -0
  34. data/lib/unparser/emitter/flipflop.rb +11 -10
  35. data/lib/unparser/emitter/float.rb +29 -0
  36. data/lib/unparser/emitter/flow_modifier.rb +8 -55
  37. data/lib/unparser/emitter/for.rb +5 -19
  38. data/lib/unparser/emitter/hash.rb +74 -0
  39. data/lib/unparser/emitter/hash_pattern.rb +67 -0
  40. data/lib/unparser/emitter/hookexe.rb +5 -11
  41. data/lib/unparser/emitter/if.rb +9 -73
  42. data/lib/unparser/emitter/in_match.rb +21 -0
  43. data/lib/unparser/emitter/in_pattern.rb +34 -0
  44. data/lib/unparser/emitter/index.rb +21 -88
  45. data/lib/unparser/emitter/kwbegin.rb +31 -0
  46. data/lib/unparser/emitter/lambda.rb +0 -8
  47. data/lib/unparser/emitter/masgn.rb +20 -0
  48. data/lib/unparser/emitter/match.rb +3 -17
  49. data/lib/unparser/emitter/match_alt.rb +23 -0
  50. data/lib/unparser/emitter/match_as.rb +21 -0
  51. data/lib/unparser/emitter/match_rest.rb +26 -0
  52. data/lib/unparser/emitter/match_var.rb +19 -0
  53. data/lib/unparser/emitter/mlhs.rb +40 -0
  54. data/lib/unparser/emitter/module.rb +3 -9
  55. data/lib/unparser/emitter/op_assign.rb +12 -27
  56. data/lib/unparser/emitter/pin.rb +19 -0
  57. data/lib/unparser/emitter/primitive.rb +93 -0
  58. data/lib/unparser/emitter/range.rb +35 -0
  59. data/lib/unparser/emitter/regexp.rb +35 -0
  60. data/lib/unparser/emitter/repetition.rb +17 -57
  61. data/lib/unparser/emitter/rescue.rb +1 -97
  62. data/lib/unparser/emitter/root.rb +17 -1
  63. data/lib/unparser/emitter/send.rb +10 -219
  64. data/lib/unparser/emitter/simple.rb +33 -0
  65. data/lib/unparser/emitter/splat.rb +2 -18
  66. data/lib/unparser/emitter/super.rb +1 -29
  67. data/lib/unparser/emitter/undef.rb +1 -9
  68. data/lib/unparser/emitter/variable.rb +1 -31
  69. data/lib/unparser/emitter/xstr.rb +72 -0
  70. data/lib/unparser/emitter/yield.rb +1 -9
  71. data/lib/unparser/generation.rb +250 -0
  72. data/lib/unparser/node_details.rb +21 -0
  73. data/lib/unparser/node_details/send.rb +62 -0
  74. data/lib/unparser/node_helpers.rb +45 -6
  75. data/lib/unparser/validation.rb +58 -35
  76. data/lib/unparser/writer.rb +15 -0
  77. data/lib/unparser/writer/binary.rb +99 -0
  78. data/lib/unparser/writer/dynamic_string.rb +233 -0
  79. data/lib/unparser/writer/resbody.rb +40 -0
  80. data/lib/unparser/writer/rescue.rb +39 -0
  81. data/lib/unparser/writer/send.rb +124 -0
  82. data/lib/unparser/{emitter → writer}/send/attribute_assignment.rb +11 -26
  83. data/lib/unparser/writer/send/binary.rb +27 -0
  84. data/lib/unparser/writer/send/conditional.rb +25 -0
  85. data/lib/unparser/writer/send/regular.rb +33 -0
  86. data/lib/unparser/{emitter → writer}/send/unary.rb +10 -17
  87. metadata +65 -89
  88. data/.github/workflows/ci.yml +0 -90
  89. data/.gitignore +0 -37
  90. data/.rspec +0 -4
  91. data/.rubocop.yml +0 -126
  92. data/Changelog.md +0 -162
  93. data/Gemfile +0 -9
  94. data/Gemfile.lock +0 -111
  95. data/LICENSE +0 -20
  96. data/Rakefile +0 -22
  97. data/config/devtools.yml +0 -2
  98. data/config/flay.yml +0 -3
  99. data/config/flog.yml +0 -2
  100. data/config/mutant.yml +0 -6
  101. data/config/reek.yml +0 -98
  102. data/config/yardstick.yml +0 -2
  103. data/lib/unparser/emitter/empty.rb +0 -23
  104. data/lib/unparser/emitter/ensure.rb +0 -37
  105. data/lib/unparser/emitter/literal.rb +0 -10
  106. data/lib/unparser/emitter/literal/array.rb +0 -29
  107. data/lib/unparser/emitter/literal/dynamic.rb +0 -53
  108. data/lib/unparser/emitter/literal/dynamic_body.rb +0 -132
  109. data/lib/unparser/emitter/literal/execute_string.rb +0 -38
  110. data/lib/unparser/emitter/literal/hash.rb +0 -156
  111. data/lib/unparser/emitter/literal/primitive.rb +0 -145
  112. data/lib/unparser/emitter/literal/range.rb +0 -36
  113. data/lib/unparser/emitter/literal/regexp.rb +0 -114
  114. data/lib/unparser/emitter/literal/singleton.rb +0 -26
  115. data/lib/unparser/emitter/meta.rb +0 -16
  116. data/lib/unparser/emitter/redo.rb +0 -25
  117. data/lib/unparser/emitter/resbody.rb +0 -76
  118. data/lib/unparser/emitter/retry.rb +0 -25
  119. data/lib/unparser/emitter/send/binary.rb +0 -57
  120. data/lib/unparser/emitter/send/conditional.rb +0 -40
  121. data/lib/unparser/emitter/send/regular.rb +0 -40
  122. data/lib/unparser/preprocessor.rb +0 -159
  123. data/spec/integration/unparser/corpus_spec.rb +0 -125
  124. data/spec/integrations.yml +0 -92
  125. data/spec/spec_helper.rb +0 -42
  126. data/spec/unit/unparser/buffer/append_spec.rb +0 -24
  127. data/spec/unit/unparser/buffer/append_without_prefix_spec.rb +0 -23
  128. data/spec/unit/unparser/buffer/capture_content_spec.rb +0 -17
  129. data/spec/unit/unparser/buffer/content_spec.rb +0 -38
  130. data/spec/unit/unparser/buffer/fresh_line_spec.rb +0 -20
  131. data/spec/unit/unparser/buffer/indent_spec.rb +0 -20
  132. data/spec/unit/unparser/buffer/nl_spec.rb +0 -16
  133. data/spec/unit/unparser/buffer/unindent_spec.rb +0 -20
  134. data/spec/unit/unparser/color_spec.rb +0 -40
  135. data/spec/unit/unparser/comments/consume_spec.rb +0 -22
  136. data/spec/unit/unparser/comments/take_all_spec.rb +0 -19
  137. data/spec/unit/unparser/comments/take_before_spec.rb +0 -46
  138. data/spec/unit/unparser/comments/take_eol_comments_spec.rb +0 -32
  139. data/spec/unit/unparser/diff_spec.rb +0 -189
  140. data/spec/unit/unparser/emitter/class_methods/handle_spec.rb +0 -17
  141. data/spec/unit/unparser/validation_spec.rb +0 -327
  142. data/spec/unit/unparser_spec.rb +0 -1920
  143. data/unparser.gemspec +0 -35
data/LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright (c) 2013 Markus Schirp
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile DELETED
@@ -1,22 +0,0 @@
1
- require 'devtools'
2
- Devtools.init_rake_tasks
3
-
4
- Rake.application.load_imports
5
- task('metrics:mutant').clear
6
-
7
- namespace :metrics do
8
- task mutant: :coverage do
9
- args = %w[
10
- bundle exec mutant
11
- --ignore-subject Unparser::Buffer#initialize
12
- --include lib
13
- --require unparser
14
- --use rspec
15
- --zombie
16
- --since HEAD~1
17
- ]
18
- args.concat(%w[--jobs 4]) if ENV.key?('CIRCLECI')
19
-
20
- system(*args.concat(%w[-- Unparser*])) or fail "Mutant task failed"
21
- end
22
- end
@@ -1,2 +0,0 @@
1
- ---
2
- unit_test_timeout: 1.0
@@ -1,3 +0,0 @@
1
- ---
2
- threshold: 13
3
- total_score: 638
@@ -1,2 +0,0 @@
1
- ---
2
- threshold: 21.3
@@ -1,6 +0,0 @@
1
- ---
2
- includes:
3
- - lib
4
- integration: rspec
5
- requires:
6
- - unparser
@@ -1,98 +0,0 @@
1
- ---
2
- detectors:
3
- Attribute:
4
- enabled: false
5
- exclude: []
6
- BooleanParameter:
7
- enabled: true
8
- exclude: []
9
- ClassVariable:
10
- enabled: true
11
- exclude: []
12
- ControlParameter:
13
- enabled: true
14
- exclude: []
15
- DataClump:
16
- enabled: true
17
- exclude: []
18
- max_copies: 2
19
- min_clump_size: 2
20
- DuplicateMethodCall:
21
- enabled: false
22
- exclude: []
23
- max_calls: 1
24
- allow_calls: []
25
- FeatureEnvy:
26
- enabled: false
27
- # Buggy smell detector
28
- IrresponsibleModule:
29
- enabled: false
30
- exclude: []
31
- LongParameterList:
32
- enabled: true
33
- exclude: []
34
- max_params: 2
35
- LongYieldList:
36
- enabled: true
37
- exclude: []
38
- max_params: 2
39
- NestedIterators:
40
- enabled: true
41
- exclude: []
42
- max_allowed_nesting: 1
43
- ignore_iterators: []
44
- NilCheck:
45
- enabled: false
46
- RepeatedConditional:
47
- enabled: true
48
- exclude: []
49
- max_ifs: 1
50
- TooManyInstanceVariables:
51
- enabled: true
52
- exclude: []
53
- max_instance_variables: 3
54
- TooManyMethods:
55
- enabled: true
56
- exclude: []
57
- max_methods: 10
58
- TooManyStatements:
59
- enabled: true
60
- exclude: []
61
- max_statements: 7
62
- UncommunicativeMethodName:
63
- enabled: true
64
- exclude: []
65
- reject:
66
- - '/^[a-z]$/'
67
- - '/[0-9]$/'
68
- - '/[A-Z]/'
69
- accept: []
70
- UncommunicativeModuleName:
71
- enabled: true
72
- exclude: []
73
- reject:
74
- - '/^.$/'
75
- - '/[0-9]$/'
76
- accept: []
77
- UncommunicativeParameterName:
78
- enabled: true
79
- exclude: []
80
- reject:
81
- - '/^.$/'
82
- - '/[0-9]$/'
83
- - '/[A-Z]/'
84
- accept: []
85
- UncommunicativeVariableName:
86
- enabled: true
87
- exclude: []
88
- reject:
89
- - '/^.$/'
90
- - '/[0-9]$/'
91
- - '/[A-Z]/'
92
- accept: ['force_utf32']
93
- UnusedParameters:
94
- enabled: true
95
- exclude: []
96
- UtilityFunction:
97
- enabled: true
98
- exclude: []
@@ -1,2 +0,0 @@
1
- ---
2
- threshold: 100
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Unparser
4
- class Emitter
5
-
6
- # Emitter for artifical empty node
7
- class Empty < self
8
-
9
- handle :empty
10
-
11
- private
12
-
13
- # Perform dispatch
14
- #
15
- # @return [undefined]
16
- #
17
- # @api private
18
- #
19
- def dispatch; end
20
-
21
- end
22
- end
23
- end # Unparser
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Unparser
4
- class Emitter
5
-
6
- # Emitter for ensure nodes
7
- class Ensure < self
8
-
9
- handle :ensure
10
-
11
- children :body, :ensure_body
12
-
13
- private
14
-
15
- # Perform dispatch
16
- #
17
- # @return [undefined]
18
- #
19
- # @api private
20
- #
21
- def dispatch
22
- if body
23
- visit_indented(body)
24
- else
25
- nl
26
- end
27
- write(K_ENSURE)
28
- if ensure_body
29
- visit_indented(ensure_body)
30
- else
31
- nl
32
- end
33
- end
34
-
35
- end # Ensure
36
- end # Emitter
37
- end # Unparser
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Unparser
4
- class Emitter
5
- # Namespace class for literal emiters
6
- class Literal < self
7
- include Terminated
8
- end # Literal
9
- end # Emitter
10
- end # Unparser
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Unparser
4
- class Emitter
5
- class Literal
6
-
7
- # Array literal emitter
8
- class Array < self
9
- handle :array
10
-
11
- private
12
-
13
- # Perform dispatch
14
- #
15
- # @return [undefined]
16
- #
17
- # @api private
18
- #
19
- def dispatch
20
- parentheses(*BRACKETS_SQUARE) do
21
- delimited(children)
22
- end
23
- end
24
-
25
- end # Array
26
-
27
- end # Literal
28
- end # Emitter
29
- end # Unparser
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Unparser
4
- class Emitter
5
- class Literal
6
-
7
- # Base class for dynamic literal emitters
8
- class Dynamic < self
9
-
10
- private
11
-
12
- # Perform dispatch
13
- #
14
- # @return [undefined]
15
- #
16
- # @api private
17
- #
18
- def dispatch
19
- util = self.class
20
- visit_parentheses(dynamic_body, util::OPEN, util::CLOSE)
21
- end
22
-
23
- # Return dynamic body
24
- #
25
- # @return [Parser::AST::Node]
26
- #
27
- # @api private
28
- #
29
- def dynamic_body
30
- Parser::AST::Node.new(:dyn_str_body, children)
31
- end
32
-
33
- # Dynamic string literal emitter
34
- class String < self
35
-
36
- OPEN = CLOSE = '"'.freeze
37
- handle :dstr
38
-
39
- end # String
40
-
41
- # Dynamic symbol literal emitter
42
- class Symbol < self
43
-
44
- OPEN = ':"'.freeze
45
- CLOSE = '"'.freeze
46
-
47
- handle :dsym
48
-
49
- end # Symbol
50
- end # Dynamic
51
- end # Literal
52
- end # Emitter
53
- end # Unparser
@@ -1,132 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Unparser
4
- class Emitter
5
- class Literal
6
-
7
- # Emitter for dynamic bodies
8
- class DynamicBody < self
9
-
10
- OPEN = '#{'.freeze
11
- CLOSE = '}'.freeze
12
-
13
- # Emitter for interpolated nodes
14
- class Interpolation < self
15
-
16
- handle :interpolated
17
-
18
- children :subject
19
-
20
- private
21
-
22
- # Perform dispatch
23
- #
24
- # @return [undefined]
25
- #
26
- # @api private
27
- #
28
- def dispatch
29
- write(OPEN)
30
- visit_plain(subject)
31
- write(CLOSE)
32
- end
33
-
34
- end
35
-
36
- private
37
-
38
- # Perform dispatch
39
- #
40
- # @return [undefined]
41
- #
42
- # @api private
43
- #
44
- def dispatch
45
- children.each(&method(:emit_segment))
46
- end
47
-
48
- # Emit segment
49
- #
50
- # @param [Parser::AST::Node] node
51
- #
52
- # @return [undefined]
53
- #
54
- # @api private
55
- #
56
- def emit_segment(node)
57
- emit_interpolated_segment(node)
58
- end
59
-
60
- pairs = Parser::Lexer::ESCAPES.invert.map do |key, value|
61
- [key, "\\#{value}"] unless key.eql?(WS)
62
- end.compact
63
-
64
- pairs << ['#{', '\#{']
65
-
66
- ESCAPES = ::Hash[pairs]
67
-
68
- REPLACEMENTS = ::Regexp.union(ESCAPES.keys)
69
-
70
- # Emit str segment
71
- #
72
- # @param [Parser::AST::Node] node
73
- #
74
- # @return [undefined]
75
- #
76
- # @api private
77
- #
78
- def emit_str_segment(node)
79
- util = self.class
80
- string = node.children.first
81
- segment = string
82
- .gsub(REPLACEMENTS, ESCAPES)
83
- .gsub(util::DELIMITER, util::REPLACEMENT)
84
- write(segment)
85
- end
86
-
87
- # Emit interpolated segment
88
- #
89
- # @param [Parser::AST::Node] node
90
- #
91
- # @return [undefined]
92
- #
93
- # @api private
94
- #
95
- def emit_interpolated_segment(node)
96
- visit_parentheses(node, OPEN, CLOSE)
97
- end
98
-
99
- # Dynamic string body
100
- class String < self
101
-
102
- handle :dyn_str_body
103
-
104
- DELIMITER = '"'.freeze
105
- REPLACEMENT = '\"'.freeze
106
-
107
- end # String
108
-
109
- # Dynamic regexp body
110
- class Regexp < self
111
-
112
- handle :dyn_regexp_body
113
-
114
- DELIMITER = '/'.freeze
115
- REPLACEMENT = '\/'.freeze
116
-
117
- end # Regexp
118
-
119
- # Dynamic regexp body
120
- class ExecuteString < self
121
-
122
- handle :dyn_xstr_body
123
-
124
- DELIMITER = '`'.freeze
125
- REPLACEMENT = '\`'.freeze
126
-
127
- end # ExecuteString
128
-
129
- end # DynamicBody
130
- end # Literal
131
- end # Emitter
132
- end # Unparser