seeing_is_believing 2.2.0 → 3.0.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Changelog.md +33 -0
- data/bin/seeing_is_believing +1 -1
- data/features/errors.feature +3 -3
- data/features/examples.feature +6 -6
- data/features/flags.feature +51 -196
- data/features/regression.feature +12 -3
- data/features/safe.feature +33 -0
- data/features/support/env.rb +20 -0
- data/features/xmpfilter-style.feature +156 -0
- data/lib/seeing_is_believing.rb +17 -35
- data/lib/seeing_is_believing/binary.rb +81 -176
- data/lib/seeing_is_believing/binary/align_chunk.rb +5 -7
- data/lib/seeing_is_believing/binary/align_file.rb +4 -5
- data/lib/seeing_is_believing/binary/align_line.rb +4 -4
- data/lib/seeing_is_believing/binary/annotate_end_of_file.rb +60 -0
- data/lib/seeing_is_believing/binary/annotate_every_line.rb +64 -0
- data/lib/seeing_is_believing/binary/annotate_xmpfilter_style.rb +133 -0
- data/lib/seeing_is_believing/binary/comment_formatter.rb +19 -5
- data/lib/seeing_is_believing/binary/comment_lines.rb +1 -1
- data/lib/seeing_is_believing/binary/commentable_lines.rb +1 -1
- data/lib/seeing_is_believing/binary/interpret_flags.rb +149 -0
- data/lib/seeing_is_believing/binary/parse_args.rb +96 -104
- data/lib/seeing_is_believing/binary/remove_annotations.rb +95 -0
- data/lib/seeing_is_believing/binary/rewrite_comments.rb +8 -30
- data/lib/seeing_is_believing/code.rb +99 -0
- data/lib/seeing_is_believing/evaluate_by_moving_files.rb +27 -19
- data/lib/seeing_is_believing/evaluate_with_eval_in.rb +27 -0
- data/lib/seeing_is_believing/event_stream/consumer.rb +111 -0
- data/lib/seeing_is_believing/event_stream/events.rb +16 -0
- data/lib/seeing_is_believing/event_stream/producer.rb +106 -0
- data/lib/seeing_is_believing/event_stream/update_result.rb +21 -0
- data/lib/seeing_is_believing/inspect_expressions.rb +24 -0
- data/lib/seeing_is_believing/parser_helpers.rb +1 -11
- data/lib/seeing_is_believing/result.rb +14 -56
- data/lib/seeing_is_believing/the_matrix.rb +14 -14
- data/lib/seeing_is_believing/version.rb +1 -1
- data/lib/seeing_is_believing/wrap_expressions.rb +32 -9
- data/seeing_is_believing.gemspec +7 -7
- data/spec/binary/comment_formatter_spec.rb +169 -18
- data/spec/binary/comment_lines_spec.rb +1 -1
- data/spec/binary/interpret_flags_spec.rb +307 -0
- data/spec/binary/parse_args_spec.rb +93 -91
- data/spec/binary/{clean_body_spec.rb → remove_annotations_spec.rb} +29 -22
- data/spec/binary/rewrite_comments_spec.rb +13 -13
- data/spec/code_spec.rb +49 -0
- data/spec/debugger_spec.rb +1 -1
- data/spec/evaluate_by_moving_files_spec.rb +7 -3
- data/spec/event_stream_spec.rb +390 -0
- data/spec/hard_core_ensure_spec.rb +1 -1
- data/spec/seeing_is_believing_spec.rb +137 -40
- data/spec/spec_helper.rb +3 -3
- data/spec/wrap_expressions_spec.rb +48 -35
- metadata +58 -35
- data/lib/seeing_is_believing/binary/add_annotations.rb +0 -144
- data/lib/seeing_is_believing/binary/clean_body.rb +0 -95
- data/lib/seeing_is_believing/has_exception.rb +0 -27
- data/lib/seeing_is_believing/line.rb +0 -90
- data/spec/line_spec.rb +0 -86
metadata
CHANGED
@@ -1,77 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seeing_is_believing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0.beta.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Cheek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: eval_in
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '2.2'
|
20
|
-
- - "<"
|
17
|
+
- - "~>"
|
21
18
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
19
|
+
version: 0.1.6
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- - "
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '2.2'
|
30
|
-
- - "<"
|
24
|
+
- - "~>"
|
31
25
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
26
|
+
version: 0.1.6
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
|
-
name:
|
28
|
+
name: parser
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
36
30
|
requirements:
|
37
|
-
- - "
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.1.4
|
34
|
+
- - "<"
|
38
35
|
- !ruby/object:Gem::Version
|
39
|
-
version: '2.
|
36
|
+
version: '2.3'
|
40
37
|
type: :runtime
|
41
38
|
prerelease: false
|
42
39
|
version_requirements: !ruby/object:Gem::Requirement
|
43
40
|
requirements:
|
44
|
-
- - "
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.1.4
|
44
|
+
- - "<"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: '2.
|
46
|
+
version: '2.3'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
48
|
+
name: webmock
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
53
|
+
version: '1.18'
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version:
|
60
|
+
version: '1.18'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: haiti
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
|
-
- - "
|
65
|
+
- - ">="
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version: 0.1
|
67
|
+
version: '0.1'
|
68
|
+
- - "<"
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0.3'
|
68
71
|
type: :development
|
69
72
|
prerelease: false
|
70
73
|
version_requirements: !ruby/object:Gem::Requirement
|
71
74
|
requirements:
|
72
|
-
- - "
|
75
|
+
- - ">="
|
73
76
|
- !ruby/object:Gem::Version
|
74
|
-
version: 0.1
|
77
|
+
version: '0.1'
|
78
|
+
- - "<"
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0.3'
|
75
81
|
- !ruby/object:Gem::Dependency
|
76
82
|
name: rake
|
77
83
|
requirement: !ruby/object:Gem::Requirement
|
@@ -140,6 +146,7 @@ extra_rdoc_files: []
|
|
140
146
|
files:
|
141
147
|
- ".gitignore"
|
142
148
|
- ".travis.yml"
|
149
|
+
- Changelog.md
|
143
150
|
- Gemfile
|
144
151
|
- Rakefile
|
145
152
|
- Readme.md
|
@@ -151,40 +158,52 @@ files:
|
|
151
158
|
- features/examples.feature
|
152
159
|
- features/flags.feature
|
153
160
|
- features/regression.feature
|
161
|
+
- features/safe.feature
|
154
162
|
- features/support/env.rb
|
163
|
+
- features/xmpfilter-style.feature
|
155
164
|
- lib/seeing_is_believing.rb
|
156
165
|
- lib/seeing_is_believing/binary.rb
|
157
|
-
- lib/seeing_is_believing/binary/add_annotations.rb
|
158
166
|
- lib/seeing_is_believing/binary/align_chunk.rb
|
159
167
|
- lib/seeing_is_believing/binary/align_file.rb
|
160
168
|
- lib/seeing_is_believing/binary/align_line.rb
|
161
|
-
- lib/seeing_is_believing/binary/
|
169
|
+
- lib/seeing_is_believing/binary/annotate_end_of_file.rb
|
170
|
+
- lib/seeing_is_believing/binary/annotate_every_line.rb
|
171
|
+
- lib/seeing_is_believing/binary/annotate_xmpfilter_style.rb
|
162
172
|
- lib/seeing_is_believing/binary/comment_formatter.rb
|
163
173
|
- lib/seeing_is_believing/binary/comment_lines.rb
|
164
174
|
- lib/seeing_is_believing/binary/commentable_lines.rb
|
175
|
+
- lib/seeing_is_believing/binary/interpret_flags.rb
|
165
176
|
- lib/seeing_is_believing/binary/parse_args.rb
|
177
|
+
- lib/seeing_is_believing/binary/remove_annotations.rb
|
166
178
|
- lib/seeing_is_believing/binary/rewrite_comments.rb
|
179
|
+
- lib/seeing_is_believing/code.rb
|
167
180
|
- lib/seeing_is_believing/debugger.rb
|
168
181
|
- lib/seeing_is_believing/error.rb
|
169
182
|
- lib/seeing_is_believing/evaluate_by_moving_files.rb
|
183
|
+
- lib/seeing_is_believing/evaluate_with_eval_in.rb
|
184
|
+
- lib/seeing_is_believing/event_stream/consumer.rb
|
185
|
+
- lib/seeing_is_believing/event_stream/events.rb
|
186
|
+
- lib/seeing_is_believing/event_stream/producer.rb
|
187
|
+
- lib/seeing_is_believing/event_stream/update_result.rb
|
170
188
|
- lib/seeing_is_believing/hard_core_ensure.rb
|
171
|
-
- lib/seeing_is_believing/
|
172
|
-
- lib/seeing_is_believing/line.rb
|
189
|
+
- lib/seeing_is_believing/inspect_expressions.rb
|
173
190
|
- lib/seeing_is_believing/parser_helpers.rb
|
174
191
|
- lib/seeing_is_believing/result.rb
|
175
192
|
- lib/seeing_is_believing/the_matrix.rb
|
176
193
|
- lib/seeing_is_believing/version.rb
|
177
194
|
- lib/seeing_is_believing/wrap_expressions.rb
|
178
195
|
- seeing_is_believing.gemspec
|
179
|
-
- spec/binary/clean_body_spec.rb
|
180
196
|
- spec/binary/comment_formatter_spec.rb
|
181
197
|
- spec/binary/comment_lines_spec.rb
|
198
|
+
- spec/binary/interpret_flags_spec.rb
|
182
199
|
- spec/binary/parse_args_spec.rb
|
200
|
+
- spec/binary/remove_annotations_spec.rb
|
183
201
|
- spec/binary/rewrite_comments_spec.rb
|
202
|
+
- spec/code_spec.rb
|
184
203
|
- spec/debugger_spec.rb
|
185
204
|
- spec/evaluate_by_moving_files_spec.rb
|
205
|
+
- spec/event_stream_spec.rb
|
186
206
|
- spec/hard_core_ensure_spec.rb
|
187
|
-
- spec/line_spec.rb
|
188
207
|
- spec/seeing_is_believing_spec.rb
|
189
208
|
- spec/spec_helper.rb
|
190
209
|
- spec/wrap_expressions_spec.rb
|
@@ -243,9 +262,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
243
262
|
version: '0'
|
244
263
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
245
264
|
requirements:
|
246
|
-
- - "
|
265
|
+
- - ">"
|
247
266
|
- !ruby/object:Gem::Version
|
248
|
-
version:
|
267
|
+
version: 1.3.1
|
249
268
|
requirements: []
|
250
269
|
rubyforge_project: seeing_is_believing
|
251
270
|
rubygems_version: 2.4.1
|
@@ -257,16 +276,20 @@ test_files:
|
|
257
276
|
- features/examples.feature
|
258
277
|
- features/flags.feature
|
259
278
|
- features/regression.feature
|
279
|
+
- features/safe.feature
|
260
280
|
- features/support/env.rb
|
261
|
-
-
|
281
|
+
- features/xmpfilter-style.feature
|
262
282
|
- spec/binary/comment_formatter_spec.rb
|
263
283
|
- spec/binary/comment_lines_spec.rb
|
284
|
+
- spec/binary/interpret_flags_spec.rb
|
264
285
|
- spec/binary/parse_args_spec.rb
|
286
|
+
- spec/binary/remove_annotations_spec.rb
|
265
287
|
- spec/binary/rewrite_comments_spec.rb
|
288
|
+
- spec/code_spec.rb
|
266
289
|
- spec/debugger_spec.rb
|
267
290
|
- spec/evaluate_by_moving_files_spec.rb
|
291
|
+
- spec/event_stream_spec.rb
|
268
292
|
- spec/hard_core_ensure_spec.rb
|
269
|
-
- spec/line_spec.rb
|
270
293
|
- spec/seeing_is_believing_spec.rb
|
271
294
|
- spec/spec_helper.rb
|
272
295
|
- spec/wrap_expressions_spec.rb
|
@@ -1,144 +0,0 @@
|
|
1
|
-
require 'stringio'
|
2
|
-
require 'seeing_is_believing/has_exception'
|
3
|
-
require 'seeing_is_believing/binary/comment_formatter'
|
4
|
-
|
5
|
-
require 'seeing_is_believing/binary'
|
6
|
-
require 'seeing_is_believing/binary/clean_body'
|
7
|
-
require 'seeing_is_believing/binary/rewrite_comments'
|
8
|
-
require 'seeing_is_believing/binary/comment_lines'
|
9
|
-
|
10
|
-
class SeeingIsBelieving
|
11
|
-
class Binary
|
12
|
-
class AddAnnotations
|
13
|
-
include HasException
|
14
|
-
|
15
|
-
def self.method_from_options(*args)
|
16
|
-
define_method(args.first) { options.fetch *args }
|
17
|
-
end
|
18
|
-
|
19
|
-
method_from_options :filename, nil
|
20
|
-
method_from_options :start_line # rename: line_to_begin_recording
|
21
|
-
method_from_options :end_line # rename: line_to_end_recording
|
22
|
-
method_from_options :xmpfilter_style
|
23
|
-
method_from_options :debugger
|
24
|
-
|
25
|
-
attr_accessor :results, :body
|
26
|
-
def initialize(uncleaned_body, options={}, &annotater)
|
27
|
-
self.options = options
|
28
|
-
self.body = CleanBody.call uncleaned_body, !xmpfilter_style
|
29
|
-
self.results = SeeingIsBelieving.call body,
|
30
|
-
filename: (options[:as] || options[:filename]),
|
31
|
-
require: options[:require],
|
32
|
-
load_path: options[:load_path],
|
33
|
-
encoding: options[:encoding],
|
34
|
-
stdin: options[:stdin],
|
35
|
-
timeout: options[:timeout],
|
36
|
-
debugger: debugger,
|
37
|
-
ruby_executable: options[:shebang],
|
38
|
-
number_of_captures: options[:number_of_captures]
|
39
|
-
end
|
40
|
-
|
41
|
-
def call
|
42
|
-
@new_body ||= begin
|
43
|
-
new_body = if xmpfilter_style
|
44
|
-
body_with_updated_annotations
|
45
|
-
else
|
46
|
-
body_with_everything_annotated
|
47
|
-
end
|
48
|
-
|
49
|
-
add_stdout_stderr_and_exceptions_to new_body
|
50
|
-
|
51
|
-
debugger.context "OUTPUT"
|
52
|
-
new_body
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
private
|
57
|
-
|
58
|
-
attr_accessor :body, :options, :alignment_strategy
|
59
|
-
|
60
|
-
# doesn't currently realign output markers, do we want to do that?
|
61
|
-
def body_with_updated_annotations
|
62
|
-
RewriteComments.call body do |line_number, line_to_whitespace, whitespace, comment|
|
63
|
-
if !comment[VALUE_REGEX]
|
64
|
-
[whitespace, comment]
|
65
|
-
elsif line_to_whitespace.empty?
|
66
|
-
result = results[line_number-1].map { |result| result.gsub "\n", '\n' }.join(', ')
|
67
|
-
[whitespace, CommentFormatter.call(whitespace.size, VALUE_MARKER, result, options)]
|
68
|
-
else
|
69
|
-
result = results[line_number].map { |result| result.gsub "\n", '\n' }.join(', ')
|
70
|
-
[whitespace, CommentFormatter.call(line_to_whitespace.size + whitespace.size, VALUE_MARKER, result, options)]
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def body_with_everything_annotated
|
76
|
-
alignment_strategy = options[:alignment_strategy].new body, start_line, end_line
|
77
|
-
CommentLines.call body do |line, line_number|
|
78
|
-
options = options().merge pad_to: alignment_strategy.line_length_for(line_number)
|
79
|
-
if line_number < start_line || end_line < line_number
|
80
|
-
''
|
81
|
-
elsif results[line_number].has_exception?
|
82
|
-
exception = results[line_number].exception
|
83
|
-
result = sprintf "%s: %s", exception.class_name, exception.message.gsub("\n", '\n')
|
84
|
-
CommentFormatter.call(line.size, EXCEPTION_MARKER, result, options)
|
85
|
-
elsif results[line_number].any?
|
86
|
-
result = results[line_number].map { |result| result.gsub "\n", '\n' }.join(', ')
|
87
|
-
CommentFormatter.call(line.size, VALUE_MARKER, result, options)
|
88
|
-
else
|
89
|
-
''
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
def add_stdout_stderr_and_exceptions_to(new_body)
|
95
|
-
output = stdout_ouptut_for(results) <<
|
96
|
-
stderr_ouptut_for(results) <<
|
97
|
-
exception_output_for(results)
|
98
|
-
|
99
|
-
# this technically could find an __END__ in a string or whatever
|
100
|
-
# going to just ignore that, though
|
101
|
-
if new_body[/^__END__$/]
|
102
|
-
new_body.sub! "\n__END__", "\n#{output}__END__"
|
103
|
-
else
|
104
|
-
new_body << "\n" unless new_body.end_with? "\n"
|
105
|
-
new_body << output
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def stdout_ouptut_for(results)
|
110
|
-
return '' unless results.has_stdout?
|
111
|
-
output = "\n"
|
112
|
-
results.stdout.each_line do |line|
|
113
|
-
output << CommentFormatter.call(0, STDOUT_MARKER, line.chomp, options()) << "\n"
|
114
|
-
end
|
115
|
-
output
|
116
|
-
end
|
117
|
-
|
118
|
-
def stderr_ouptut_for(results)
|
119
|
-
return '' unless results.has_stderr?
|
120
|
-
output = "\n"
|
121
|
-
results.stderr.each_line do |line|
|
122
|
-
output << CommentFormatter.call(0, STDERR_MARKER, line.chomp, options()) << "\n"
|
123
|
-
end
|
124
|
-
output
|
125
|
-
end
|
126
|
-
|
127
|
-
def exception_output_for(results)
|
128
|
-
return '' unless results.has_exception?
|
129
|
-
exception = results.exception
|
130
|
-
output = "\n"
|
131
|
-
output << CommentFormatter.new(0, EXCEPTION_MARKER, exception.class_name, options).call << "\n"
|
132
|
-
exception.message.each_line do |line|
|
133
|
-
output << CommentFormatter.new(0, EXCEPTION_MARKER, line.chomp, options).call << "\n"
|
134
|
-
end
|
135
|
-
output << EXCEPTION_MARKER.sub(/\s+$/, '') << "\n"
|
136
|
-
exception.backtrace.each do |line|
|
137
|
-
output << CommentFormatter.new(0, EXCEPTION_MARKER, line.chomp, options).call << "\n"
|
138
|
-
end
|
139
|
-
output
|
140
|
-
end
|
141
|
-
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
@@ -1,95 +0,0 @@
|
|
1
|
-
# CleanedBody
|
2
|
-
# takes a body
|
3
|
-
# removes annotations
|
4
|
-
# only removes "# =>" when should_clean_values is false
|
5
|
-
|
6
|
-
require 'seeing_is_believing/binary'
|
7
|
-
require 'seeing_is_believing/parser_helpers'
|
8
|
-
|
9
|
-
class SeeingIsBelieving
|
10
|
-
class Binary
|
11
|
-
class CleanBody
|
12
|
-
def self.call(code, should_clean_values)
|
13
|
-
new(code, should_clean_values).call
|
14
|
-
end
|
15
|
-
|
16
|
-
def initialize(code, should_clean_values)
|
17
|
-
self.should_clean_values = should_clean_values
|
18
|
-
self.code = code
|
19
|
-
end
|
20
|
-
|
21
|
-
def call
|
22
|
-
buffer, parser, rewriter = ParserHelpers.initialize_parser code, 'strip_comments'
|
23
|
-
comments = ParserHelpers.comments_from parser, buffer
|
24
|
-
|
25
|
-
removed_comments = { result: [], exception: [], stdout: [], stderr: [] }
|
26
|
-
|
27
|
-
comments.each do |comment|
|
28
|
-
case comment.text
|
29
|
-
when VALUE_REGEX
|
30
|
-
if should_clean_values
|
31
|
-
removed_comments[:result] << comment
|
32
|
-
rewriter.remove comment.location.expression
|
33
|
-
end
|
34
|
-
when EXCEPTION_REGEX
|
35
|
-
removed_comments[:exception] << comment
|
36
|
-
rewriter.remove comment.location.expression
|
37
|
-
when STDOUT_REGEX
|
38
|
-
removed_comments[:stdout] << comment
|
39
|
-
rewriter.remove comment.location.expression
|
40
|
-
when STDERR_REGEX
|
41
|
-
removed_comments[:stderr] << comment
|
42
|
-
rewriter.remove comment.location.expression
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
remove_whitespace_preceeding_comments(buffer, rewriter, removed_comments)
|
47
|
-
rewriter.process
|
48
|
-
rescue Parser::SyntaxError => e
|
49
|
-
raise SyntaxError, e.message
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
|
54
|
-
attr_accessor :code, :should_clean_values, :buffer
|
55
|
-
|
56
|
-
def remove_whitespace_preceeding_comments(buffer, rewriter, removed_comments)
|
57
|
-
removed_comments[:result].each { |comment| remove_whitespace_before comment.location.expression.begin_pos, buffer, rewriter, false }
|
58
|
-
removed_comments[:exception].each { |comment| remove_whitespace_before comment.location.expression.begin_pos, buffer, rewriter, true }
|
59
|
-
removed_comments[:stdout].each { |comment| remove_whitespace_before comment.location.expression.begin_pos, buffer, rewriter, true }
|
60
|
-
removed_comments[:stderr].each { |comment| remove_whitespace_before comment.location.expression.begin_pos, buffer, rewriter, true }
|
61
|
-
end
|
62
|
-
|
63
|
-
# any whitespace before the index (on the same line) will be removed
|
64
|
-
# if the preceeding whitespace is at the beginning of the line, the newline will be removed
|
65
|
-
# if there is a newline before all of that, and remove_preceeding_newline is true, it will be removed as well
|
66
|
-
def remove_whitespace_before(index, buffer, rewriter, remove_preceeding_newline)
|
67
|
-
end_pos = index
|
68
|
-
begin_pos = end_pos - 1
|
69
|
-
begin_pos -= 1 while code[begin_pos] =~ /\s/ && code[begin_pos] != "\n"
|
70
|
-
begin_pos -= 1 if code[begin_pos] == "\n"
|
71
|
-
begin_pos -= 1 if code[begin_pos] == "\n" && remove_preceeding_newline
|
72
|
-
return if begin_pos.next == end_pos
|
73
|
-
rewriter.remove Parser::Source::Range.new(buffer, begin_pos.next, end_pos)
|
74
|
-
end
|
75
|
-
|
76
|
-
# returns comments in groups that are on consecutive lines
|
77
|
-
def adjacent_comments(comments, buffer)
|
78
|
-
comments = comments.sort_by { |comment| comment.location.begin_pos }
|
79
|
-
current_chunk = 0
|
80
|
-
last_line_seen = -100
|
81
|
-
chunks_to_comment = comments.chunk do |comment|
|
82
|
-
line = comment.location.begin_pos.line
|
83
|
-
if last_line_seen.next == line
|
84
|
-
last_line_seen = line
|
85
|
-
current_chunk
|
86
|
-
else
|
87
|
-
last_line_seen = line
|
88
|
-
current_chunk += 1
|
89
|
-
end
|
90
|
-
end
|
91
|
-
chunks_to_comment.map &:last
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|