unparser 0.4.7 → 0.6.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +40 -9
  3. data/bin/unparser +2 -2
  4. data/lib/unparser/abstract_type.rb +121 -0
  5. data/lib/unparser/adamantium/method_builder.rb +111 -0
  6. data/lib/unparser/adamantium.rb +150 -0
  7. data/lib/unparser/anima/attribute.rb +59 -0
  8. data/lib/unparser/anima/error.rb +23 -0
  9. data/lib/unparser/anima.rb +184 -0
  10. data/lib/unparser/ast/local_variable_scope.rb +6 -76
  11. data/lib/unparser/ast.rb +1 -3
  12. data/lib/unparser/buffer.rb +14 -25
  13. data/lib/unparser/cli.rb +85 -77
  14. data/lib/unparser/{cli/color.rb → color.rb} +4 -14
  15. data/lib/unparser/comments.rb +0 -26
  16. data/lib/unparser/concord.rb +114 -0
  17. data/lib/unparser/constants.rb +4 -53
  18. data/lib/unparser/diff.rb +98 -0
  19. data/lib/unparser/dsl.rb +0 -32
  20. data/lib/unparser/either.rb +153 -0
  21. data/lib/unparser/emitter/alias.rb +2 -8
  22. data/lib/unparser/emitter/args.rb +45 -0
  23. data/lib/unparser/emitter/argument.rb +13 -169
  24. data/lib/unparser/emitter/array.rb +27 -0
  25. data/lib/unparser/emitter/array_pattern.rb +29 -0
  26. data/lib/unparser/emitter/assignment.rb +36 -127
  27. data/lib/unparser/emitter/begin.rb +9 -84
  28. data/lib/unparser/emitter/binary.rb +7 -20
  29. data/lib/unparser/emitter/block.rb +57 -41
  30. data/lib/unparser/emitter/case.rb +6 -48
  31. data/lib/unparser/emitter/case_guard.rb +27 -0
  32. data/lib/unparser/emitter/case_match.rb +40 -0
  33. data/lib/unparser/emitter/cbase.rb +1 -3
  34. data/lib/unparser/emitter/class.rb +6 -26
  35. data/lib/unparser/emitter/const_pattern.rb +24 -0
  36. data/lib/unparser/emitter/def.rb +7 -51
  37. data/lib/unparser/emitter/defined.rb +2 -12
  38. data/lib/unparser/emitter/dstr.rb +22 -0
  39. data/lib/unparser/emitter/dsym.rb +41 -0
  40. data/lib/unparser/emitter/find_pattern.rb +18 -0
  41. data/lib/unparser/emitter/flipflop.rb +11 -10
  42. data/lib/unparser/emitter/float.rb +29 -0
  43. data/lib/unparser/emitter/flow_modifier.rb +15 -53
  44. data/lib/unparser/emitter/for.rb +5 -19
  45. data/lib/unparser/emitter/hash.rb +36 -0
  46. data/lib/unparser/emitter/hash_pattern.rb +67 -0
  47. data/lib/unparser/emitter/hookexe.rb +5 -11
  48. data/lib/unparser/emitter/if.rb +15 -71
  49. data/lib/unparser/emitter/in_match.rb +21 -0
  50. data/lib/unparser/emitter/in_pattern.rb +36 -0
  51. data/lib/unparser/emitter/index.rb +22 -89
  52. data/lib/unparser/emitter/kwargs.rb +13 -0
  53. data/lib/unparser/emitter/kwbegin.rb +31 -0
  54. data/lib/unparser/emitter/lambda.rb +0 -8
  55. data/lib/unparser/emitter/masgn.rb +20 -0
  56. data/lib/unparser/emitter/match.rb +3 -17
  57. data/lib/unparser/emitter/match_alt.rb +23 -0
  58. data/lib/unparser/emitter/match_as.rb +21 -0
  59. data/lib/unparser/emitter/match_pattern.rb +30 -0
  60. data/lib/unparser/emitter/match_pattern_p.rb +20 -0
  61. data/lib/unparser/emitter/match_rest.rb +33 -0
  62. data/lib/unparser/emitter/match_var.rb +19 -0
  63. data/lib/unparser/emitter/mlhs.rb +40 -0
  64. data/lib/unparser/emitter/module.rb +3 -9
  65. data/lib/unparser/emitter/op_assign.rb +14 -29
  66. data/lib/unparser/emitter/pair.rb +33 -0
  67. data/lib/unparser/emitter/pin.rb +19 -0
  68. data/lib/unparser/emitter/primitive.rb +93 -0
  69. data/lib/unparser/emitter/range.rb +35 -0
  70. data/lib/unparser/emitter/regexp.rb +35 -0
  71. data/lib/unparser/emitter/repetition.rb +17 -57
  72. data/lib/unparser/emitter/rescue.rb +1 -97
  73. data/lib/unparser/emitter/root.rb +17 -1
  74. data/lib/unparser/emitter/send.rb +10 -219
  75. data/lib/unparser/emitter/simple.rb +33 -0
  76. data/lib/unparser/emitter/splat.rb +13 -19
  77. data/lib/unparser/emitter/super.rb +1 -29
  78. data/lib/unparser/emitter/undef.rb +1 -9
  79. data/lib/unparser/emitter/variable.rb +1 -31
  80. data/lib/unparser/emitter/xstr.rb +72 -0
  81. data/lib/unparser/emitter/yield.rb +1 -9
  82. data/lib/unparser/emitter.rb +24 -425
  83. data/lib/unparser/equalizer.rb +98 -0
  84. data/lib/unparser/generation.rb +252 -0
  85. data/lib/unparser/node_details/send.rb +65 -0
  86. data/lib/unparser/node_details.rb +21 -0
  87. data/lib/unparser/node_helpers.rb +48 -6
  88. data/lib/unparser/validation.rb +172 -0
  89. data/lib/unparser/writer/binary.rb +99 -0
  90. data/lib/unparser/writer/dynamic_string.rb +211 -0
  91. data/lib/unparser/writer/resbody.rb +40 -0
  92. data/lib/unparser/writer/rescue.rb +43 -0
  93. data/lib/unparser/{emitter → writer}/send/attribute_assignment.rb +11 -26
  94. data/lib/unparser/writer/send/binary.rb +27 -0
  95. data/lib/unparser/writer/send/conditional.rb +25 -0
  96. data/lib/unparser/writer/send/regular.rb +33 -0
  97. data/lib/unparser/{emitter → writer}/send/unary.rb +10 -17
  98. data/lib/unparser/writer/send.rb +115 -0
  99. data/lib/unparser/writer.rb +15 -0
  100. data/lib/unparser.rb +161 -77
  101. metadata +100 -157
  102. data/.circleci/config.yml +0 -49
  103. data/.gitignore +0 -37
  104. data/.rspec +0 -4
  105. data/.rubocop.yml +0 -9
  106. data/Changelog.md +0 -156
  107. data/Gemfile +0 -9
  108. data/Gemfile.lock +0 -181
  109. data/LICENSE +0 -20
  110. data/Rakefile +0 -22
  111. data/config/devtools.yml +0 -2
  112. data/config/flay.yml +0 -3
  113. data/config/flog.yml +0 -2
  114. data/config/mutant.yml +0 -6
  115. data/config/reek.yml +0 -98
  116. data/config/rubocop.yml +0 -122
  117. data/config/yardstick.yml +0 -2
  118. data/lib/unparser/cli/differ.rb +0 -152
  119. data/lib/unparser/cli/source.rb +0 -267
  120. data/lib/unparser/emitter/empty.rb +0 -23
  121. data/lib/unparser/emitter/ensure.rb +0 -37
  122. data/lib/unparser/emitter/literal/array.rb +0 -29
  123. data/lib/unparser/emitter/literal/dynamic.rb +0 -53
  124. data/lib/unparser/emitter/literal/dynamic_body.rb +0 -132
  125. data/lib/unparser/emitter/literal/execute_string.rb +0 -38
  126. data/lib/unparser/emitter/literal/hash.rb +0 -156
  127. data/lib/unparser/emitter/literal/primitive.rb +0 -145
  128. data/lib/unparser/emitter/literal/range.rb +0 -36
  129. data/lib/unparser/emitter/literal/regexp.rb +0 -114
  130. data/lib/unparser/emitter/literal/singleton.rb +0 -26
  131. data/lib/unparser/emitter/literal.rb +0 -10
  132. data/lib/unparser/emitter/meta.rb +0 -16
  133. data/lib/unparser/emitter/redo.rb +0 -25
  134. data/lib/unparser/emitter/resbody.rb +0 -76
  135. data/lib/unparser/emitter/retry.rb +0 -25
  136. data/lib/unparser/emitter/send/binary.rb +0 -57
  137. data/lib/unparser/emitter/send/conditional.rb +0 -40
  138. data/lib/unparser/emitter/send/regular.rb +0 -40
  139. data/lib/unparser/preprocessor.rb +0 -159
  140. data/spec/integration/unparser/corpus_spec.rb +0 -111
  141. data/spec/integrations.yml +0 -92
  142. data/spec/spec_helper.rb +0 -20
  143. data/spec/unit/unparser/buffer/append_spec.rb +0 -24
  144. data/spec/unit/unparser/buffer/append_without_prefix_spec.rb +0 -23
  145. data/spec/unit/unparser/buffer/capture_content_spec.rb +0 -17
  146. data/spec/unit/unparser/buffer/content_spec.rb +0 -38
  147. data/spec/unit/unparser/buffer/fresh_line_spec.rb +0 -20
  148. data/spec/unit/unparser/buffer/indent_spec.rb +0 -20
  149. data/spec/unit/unparser/buffer/nl_spec.rb +0 -16
  150. data/spec/unit/unparser/buffer/unindent_spec.rb +0 -20
  151. data/spec/unit/unparser/comments/consume_spec.rb +0 -22
  152. data/spec/unit/unparser/comments/take_all_spec.rb +0 -19
  153. data/spec/unit/unparser/comments/take_before_spec.rb +0 -46
  154. data/spec/unit/unparser/comments/take_eol_comments_spec.rb +0 -32
  155. data/spec/unit/unparser/emitter/class_methods/handle_spec.rb +0 -17
  156. data/spec/unit/unparser_spec.rb +0 -1849
  157. data/unparser.gemspec +0 -32
data/Gemfile.lock DELETED
@@ -1,181 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- unparser (0.4.7)
5
- abstract_type (~> 0.0.7)
6
- adamantium (~> 0.2.0)
7
- concord (~> 0.1.5)
8
- diff-lcs (~> 1.3)
9
- equalizer (~> 0.0.9)
10
- parser (>= 2.6.5)
11
- procto (~> 0.0.2)
12
-
13
- GEM
14
- remote: https://rubygems.org/
15
- remote: https://oss:Px2ENN7S91OmWaD5G7MIQJi1dmtmYrEh@gem.mutant.dev/
16
- specs:
17
- abstract_type (0.0.7)
18
- adamantium (0.2.0)
19
- ice_nine (~> 0.11.0)
20
- memoizable (~> 0.4.0)
21
- anima (0.3.1)
22
- abstract_type (~> 0.0.7)
23
- adamantium (~> 0.2)
24
- equalizer (~> 0.0.11)
25
- ast (2.4.0)
26
- axiom-types (0.1.1)
27
- descendants_tracker (~> 0.0.4)
28
- ice_nine (~> 0.11.0)
29
- thread_safe (~> 0.3, >= 0.3.1)
30
- codeclimate-engine-rb (0.4.1)
31
- virtus (~> 1.0)
32
- coercible (1.0.0)
33
- descendants_tracker (~> 0.0.1)
34
- concord (0.1.5)
35
- adamantium (~> 0.2.0)
36
- equalizer (~> 0.0.9)
37
- descendants_tracker (0.0.4)
38
- thread_safe (~> 0.3, >= 0.3.1)
39
- devtools (0.1.24)
40
- abstract_type (~> 0.0.7)
41
- adamantium (~> 0.2.0)
42
- anima (~> 0.3.0)
43
- concord (~> 0.1.5)
44
- flay (~> 2.12.0)
45
- flog (~> 4.6.2)
46
- procto (~> 0.0.3)
47
- rake (~> 12.3.0)
48
- reek (~> 5.3.0)
49
- rspec (~> 3.8.0)
50
- rspec-core (~> 3.8.0)
51
- rspec-its (~> 1.2.0)
52
- rubocop (~> 0.61.1)
53
- simplecov (~> 0.16.1)
54
- yard (~> 0.9.16)
55
- yardstick (~> 0.9.9)
56
- diff-lcs (1.3)
57
- docile (1.3.2)
58
- equalizer (0.0.11)
59
- erubis (2.7.0)
60
- flay (2.12.1)
61
- erubis (~> 2.7.0)
62
- path_expander (~> 1.0)
63
- ruby_parser (~> 3.0)
64
- sexp_processor (~> 4.0)
65
- flog (4.6.4)
66
- path_expander (~> 1.0)
67
- ruby_parser (~> 3.1, > 3.1.0)
68
- sexp_processor (~> 4.8)
69
- ice_nine (0.11.2)
70
- jaro_winkler (1.5.4)
71
- json (2.3.0)
72
- kwalify (0.7.2)
73
- memoizable (0.4.2)
74
- thread_safe (~> 0.3, >= 0.3.1)
75
- morpher (0.2.6)
76
- abstract_type (~> 0.0.7)
77
- adamantium (~> 0.2.0)
78
- anima (~> 0.3.0)
79
- ast (~> 2.2)
80
- concord (~> 0.1.5)
81
- equalizer (~> 0.0.9)
82
- ice_nine (~> 0.11.0)
83
- procto (~> 0.0.2)
84
- mprelude (0.1.0)
85
- abstract_type (~> 0.0.7)
86
- adamantium (~> 0.2.0)
87
- concord (~> 0.1.5)
88
- equalizer (~> 0.0.9)
89
- ice_nine (~> 0.11.1)
90
- procto (~> 0.0.2)
91
- mutant (0.9.4)
92
- abstract_type (~> 0.0.7)
93
- adamantium (~> 0.2.0)
94
- anima (~> 0.3.1)
95
- ast (~> 2.2)
96
- concord (~> 0.1.5)
97
- diff-lcs (~> 1.3)
98
- equalizer (~> 0.0.9)
99
- ice_nine (~> 0.11.1)
100
- memoizable (~> 0.4.2)
101
- mprelude (~> 0.1.0)
102
- parser (~> 2.6.5)
103
- procto (~> 0.0.2)
104
- unparser (~> 0.4.6)
105
- mutant-license (0.1.0)
106
- mutant-rspec (0.9.4)
107
- mutant (~> 0.9.4)
108
- rspec-core (>= 3.8.0, < 4.0.0)
109
- parallel (1.19.1)
110
- parser (2.6.5.0)
111
- ast (~> 2.4.0)
112
- path_expander (1.1.0)
113
- powerpack (0.1.2)
114
- procto (0.0.3)
115
- psych (3.1.0)
116
- rainbow (3.0.0)
117
- rake (12.3.3)
118
- reek (5.3.2)
119
- codeclimate-engine-rb (~> 0.4.0)
120
- kwalify (~> 0.7.0)
121
- parser (>= 2.5.0.0, < 2.7, != 2.5.1.1)
122
- psych (~> 3.1.0)
123
- rainbow (>= 2.0, < 4.0)
124
- rspec (3.8.0)
125
- rspec-core (~> 3.8.0)
126
- rspec-expectations (~> 3.8.0)
127
- rspec-mocks (~> 3.8.0)
128
- rspec-core (3.8.2)
129
- rspec-support (~> 3.8.0)
130
- rspec-expectations (3.8.6)
131
- diff-lcs (>= 1.2.0, < 2.0)
132
- rspec-support (~> 3.8.0)
133
- rspec-its (1.2.0)
134
- rspec-core (>= 3.0.0)
135
- rspec-expectations (>= 3.0.0)
136
- rspec-mocks (3.8.2)
137
- diff-lcs (>= 1.2.0, < 2.0)
138
- rspec-support (~> 3.8.0)
139
- rspec-support (3.8.3)
140
- rubocop (0.61.1)
141
- jaro_winkler (~> 1.5.1)
142
- parallel (~> 1.10)
143
- parser (>= 2.5, != 2.5.1.1)
144
- powerpack (~> 0.1)
145
- rainbow (>= 2.2.2, < 4.0)
146
- ruby-progressbar (~> 1.7)
147
- unicode-display_width (~> 1.4.0)
148
- ruby-progressbar (1.10.1)
149
- ruby_parser (3.14.1)
150
- sexp_processor (~> 4.9)
151
- sexp_processor (4.13.0)
152
- simplecov (0.16.1)
153
- docile (~> 1.1)
154
- json (>= 1.8, < 3)
155
- simplecov-html (~> 0.10.0)
156
- simplecov-html (0.10.2)
157
- thread_safe (0.3.6)
158
- unicode-display_width (1.4.1)
159
- virtus (1.0.5)
160
- axiom-types (~> 0.1)
161
- coercible (~> 1.0)
162
- descendants_tracker (~> 0.0, >= 0.0.3)
163
- equalizer (~> 0.0, >= 0.0.9)
164
- yard (0.9.22)
165
- yardstick (0.9.9)
166
- yard (~> 0.8, >= 0.8.7.2)
167
-
168
- PLATFORMS
169
- ruby
170
-
171
- DEPENDENCIES
172
- anima (~> 0.3.1)
173
- devtools (~> 0.1.23)
174
- morpher (~> 0.2.6)
175
- mutant (~> 0.9.4)
176
- mutant-license!
177
- mutant-rspec (~> 0.9.4)
178
- unparser!
179
-
180
- BUNDLED WITH
181
- 1.17.3
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
data/config/devtools.yml DELETED
@@ -1,2 +0,0 @@
1
- ---
2
- unit_test_timeout: 1.0
data/config/flay.yml DELETED
@@ -1,3 +0,0 @@
1
- ---
2
- threshold: 13
3
- total_score: 638
data/config/flog.yml DELETED
@@ -1,2 +0,0 @@
1
- ---
2
- threshold: 21.3
data/config/mutant.yml DELETED
@@ -1,6 +0,0 @@
1
- ---
2
- includes:
3
- - lib
4
- integration: rspec
5
- requires:
6
- - unparser
data/config/reek.yml DELETED
@@ -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: []
data/config/rubocop.yml DELETED
@@ -1,122 +0,0 @@
1
- inherit_from: ../.rubocop.yml
2
-
3
- AllCops:
4
- Include:
5
- - 'lib/unparser.rb'
6
- - 'lib/unparser/**/*.rb'
7
- - '**/*.rake'
8
- - 'Gemfile'
9
- - 'Gemfile.triage'
10
-
11
- # Avoid parameter lists longer than five parameters.
12
- ParameterLists:
13
- Max: 3
14
- CountKeywordArgs: true
15
-
16
- MethodLength:
17
- CountComments: false
18
- Max: 17
19
-
20
- AbcSize:
21
- Max: 18
22
-
23
- # Avoid more than `Max` levels of nesting.
24
- BlockNesting:
25
- Max: 3
26
-
27
- # Align with the style guide.
28
- CollectionMethods:
29
- PreferredMethods:
30
- collect: 'map'
31
- inject: 'reduce'
32
- find: 'detect'
33
- find_all: 'select'
34
-
35
- # Limit line length
36
- LineLength:
37
- Max: 113 # TODO: lower to 79 once the rubocop branch in shared/Gemfile is removed
38
-
39
- ClassLength:
40
- Max: 204
41
-
42
- # Prefer modifiers and explicit if statements over returning early for small methods
43
- GuardClause:
44
- Enabled: false
45
-
46
- Metrics/BlockLength:
47
- Exclude:
48
- # Ignore RSpec DSL
49
- - spec/**/*
50
-
51
- # Flags freezes for singletons that could still be mutated like Regexps
52
- RedundantFreeze:
53
- Enabled: false
54
-
55
- # Allow Fixnum and Bignum. This Gem supports versions before 2.4
56
- UnifiedInteger:
57
- Enabled: false
58
-
59
- # Disabled because of indenting with private keyword in class bodies.
60
- IndentationWidth:
61
- Enabled: false
62
-
63
- # I like raise more
64
- SignalException:
65
- Enabled: false
66
-
67
- # False positive in unparser source
68
- OneLineConditional:
69
- Enabled: false
70
-
71
- Documentation:
72
- Enabled: false
73
-
74
- # Disable documentation checking until a class needs to be documented once
75
- Documentation:
76
- Enabled: false
77
-
78
- # Do not favor modifier if/unless usage when you have a single-line body
79
- IfUnlessModifier:
80
- Enabled: false
81
-
82
- # Allow case equality operator (in limited use within the specs)
83
- CaseEquality:
84
- Enabled: false
85
-
86
- # Constants do not always have to use SCREAMING_SNAKE_CASE
87
- ConstantName:
88
- Enabled: false
89
-
90
- # Not all trivial readers/writers can be defined with attr_* methods
91
- TrivialAccessors:
92
- Enabled: false
93
-
94
- # I like to have an empty line before closing the currently opened body
95
- EmptyLinesAroundBlockBody:
96
- Enabled: false
97
-
98
- EmptyLinesAroundClassBody:
99
- Enabled: false
100
-
101
- EmptyLinesAroundModuleBody:
102
- Enabled: false
103
-
104
- # I like my style more
105
- AccessModifierIndentation:
106
- Enabled: false
107
-
108
- Style/CommentedKeyword:
109
- Enabled: false
110
-
111
- Style/MixinGrouping:
112
- Enabled: false
113
-
114
- Lint/BooleanSymbol:
115
- Enabled: false
116
-
117
- Style/AccessModifierDeclarations:
118
- Enabled: false
119
-
120
- Layout/AlignHash:
121
- EnforcedColonStyle: table
122
- EnforcedHashRocketStyle: table
data/config/yardstick.yml DELETED
@@ -1,2 +0,0 @@
1
- ---
2
- threshold: 100
@@ -1,152 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Unparser
4
- class CLI
5
- # Class to create diffs from source code
6
- class Differ
7
- include Adamantium::Flat, Concord.new(:old, :new), Procto.call(:colorized_diff)
8
-
9
- CONTEXT_LINES = 5
10
-
11
- # Return new object
12
- #
13
- # @param [String] old
14
- # @param [String] new
15
- #
16
- # @return [Differ]
17
- #
18
- # @api private
19
- #
20
- def self.build(old, new)
21
- new(lines(old), lines(new))
22
- end
23
-
24
- # Return colorized diff line
25
- #
26
- # @param [String] line
27
- #
28
- # @return [String]
29
- #
30
- # @api private
31
- #
32
- def self.colorize_line(line)
33
- case line[0]
34
- when '+'
35
- Color::GREEN
36
- when '-'
37
- Color::RED
38
- else
39
- Color::NONE
40
- end.format(line)
41
- end
42
-
43
- # Break up source into lines
44
- #
45
- # @param [String] source
46
- #
47
- # @return [Array<String>]
48
- #
49
- # @api private
50
- #
51
- def self.lines(source)
52
- source.lines.map(&:chomp)
53
- end
54
- private_class_method :lines
55
-
56
- # Return hunks
57
- #
58
- # @return [Array<Diff::LCS::Hunk>]
59
- #
60
- # @api private
61
- #
62
- def hunks
63
- file_length_difference = new.length - old.length
64
- diffs.map do |piece|
65
- hunk = Diff::LCS::Hunk.new(old, new, piece, CONTEXT_LINES, file_length_difference)
66
- file_length_difference = hunk.file_length_difference
67
- hunk
68
- end
69
- end
70
-
71
- # Return collapsed hunks
72
- #
73
- # @return [Enumerable<Diff::LCS::Hunk>]
74
- #
75
- # @api private
76
- #
77
- def collapsed_hunks
78
- hunks.each_with_object([]) do |hunk, output|
79
- last = output.last
80
-
81
- if last && hunk.merge(last)
82
- output.pop
83
- end
84
-
85
- output << hunk
86
- end
87
- end
88
-
89
- # Return source diff
90
- #
91
- # @return [String]
92
- # if there is a diff
93
- #
94
- # @return [nil]
95
- # otherwise
96
- #
97
- # @api private
98
- #
99
- def diff
100
- output = +''
101
-
102
- collapsed_hunks.each do |hunk|
103
- output << hunk.diff(:unified) << "\n"
104
- end
105
-
106
- output
107
- end
108
- memoize :diff
109
-
110
- # Return colorized source diff
111
- #
112
- # @return [String]
113
- # if there is a diff
114
- #
115
- # @return [nil]
116
- # otherwise
117
- #
118
- # @api private
119
- #
120
- def colorized_diff
121
- diff.lines.map do |line|
122
- self.class.colorize_line(line)
123
- end.join
124
- end
125
- memoize :colorized_diff
126
-
127
- private
128
-
129
- # Return diffs
130
- #
131
- # @return [Array<Array>]
132
- #
133
- # @api private
134
- #
135
- def diffs
136
- Diff::LCS.diff(old, new)
137
- end
138
- memoize :diffs
139
-
140
- # Return max length
141
- #
142
- # @return [Fixnum]
143
- #
144
- # @api private
145
- #
146
- def max_length
147
- [old, new].map(&:length).max
148
- end
149
-
150
- end # CLI
151
- end # Differ
152
- end # Unparser