ruby-beautify 0.92.2 → 0.93.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,53 +0,0 @@
1
- module RBeautify
2
- class Line
3
-
4
- attr_reader :language, :content, :line_number, :original_block, :block, :indent_character
5
-
6
- def initialize(language, content, line_number, original_block = nil, use_tabs = false)
7
- @language = language
8
- @content = content
9
- @original_block = original_block
10
- @indent_character = use_tabs ? "\t" : " "
11
- @block = BlockMatcher.parse(language, original_block, line_number, stripped, 0)
12
- end
13
-
14
- def format
15
- if @formatted.nil?
16
- if format?
17
- if stripped.length == 0
18
- @formatted = ""
19
- else
20
- @formatted = tab_string + stripped
21
- end
22
- else
23
- @formatted = content
24
- end
25
- end
26
-
27
- @formatted
28
- end
29
-
30
- private
31
- def format?
32
- original_block.nil? || original_block.format_content?
33
- end
34
-
35
- def indent_size
36
- if (block.nil? || block.strict_ancestor_of?(original_block)) && (original_block && original_block.indent_end_line?)
37
- original_block.total_indent_size
38
- else
39
- common_ancestor = BlockStart.first_common_ancestor(original_block, block)
40
- common_ancestor.nil? ? 0 : common_ancestor.total_indent_size
41
- end
42
- end
43
-
44
- def tab_string
45
- indent_character * (indent_size / 2 ) + (indent_size.odd? ? ' ' : '')
46
- end
47
-
48
- def stripped
49
- @stripped = content.strip
50
- end
51
-
52
- end
53
- end
@@ -1,408 +0,0 @@
1
- - name: indent if else end statement
2
- input: |
3
- if foo
4
- bar = 1
5
- elsif foo2
6
- bar = 2
7
- else
8
- bar = 3
9
- end
10
- output: |
11
- if foo
12
- bar = 1
13
- elsif foo2
14
- bar = 2
15
- else
16
- bar = 3
17
- end
18
-
19
- - name: handle case where if begins and ends on same line
20
- input: |
21
- foo do
22
- if a then b = 1 else b = 2 end
23
- end
24
- output: |
25
- foo do
26
- if a then b = 1 else b = 2 end
27
- end
28
-
29
- - name: indent not double indent case/when statement
30
- input: |
31
- case foo
32
- when 1
33
- bar = 'some string'
34
- when 2
35
- bar = 'some other string'
36
- when 3 then bar = '3'
37
- else
38
- bar = '4'
39
- end
40
- output: |
41
- case foo
42
- when 1
43
- bar = 'some string'
44
- when 2
45
- bar = 'some other string'
46
- when 3 then bar = '3'
47
- else
48
- bar = '4'
49
- end
50
-
51
- - name: indent while statement
52
- input: |
53
- def foo
54
- bar = 1
55
- while bar < 3
56
- puts bar
57
- bar = bar.next
58
- end
59
- end
60
- output: |
61
- def foo
62
- bar = 1
63
- while bar < 3
64
- puts bar
65
- bar = bar.next
66
- end
67
- end
68
-
69
- - name: ignore code after end of line comment
70
- input: |
71
- def method_containing_end_of_line_comment
72
- a = b # Comment containing do
73
- end
74
- output: |
75
- def method_containing_end_of_line_comment
76
- a = b # Comment containing do
77
- end
78
-
79
- - name :not indent multineline comment:
80
- input: |
81
- =begin
82
- Comment
83
- =end
84
- foo
85
-
86
- - name: indent lines after first of multiline code
87
- input: |
88
- def method_with_multiline_method_call
89
- multiline_method_call \
90
- first_arg,
91
- second_arg,
92
- third_arg
93
- end
94
- output: |
95
- def method_with_multiline_method_call
96
- multiline_method_call \
97
- first_arg,
98
- second_arg,
99
- third_arg
100
- end
101
-
102
- - name: indent method call with bracketed multiline arguments
103
- input: |
104
- def method_with_multiline_method_call
105
- multiline_method_call(foo,
106
- bar,
107
- foobar)
108
- end
109
- output: |
110
- def method_with_multiline_method_call
111
- multiline_method_call(foo,
112
- bar,
113
- foobar)
114
- end
115
-
116
- - name: indent method call with bracketed multiline arguments_even_if_not_first_block_on_line
117
- input: |
118
- if (foo = bar(first_arg,
119
- second_arg))
120
- do_something
121
- end
122
- output: |
123
- if (foo = bar(first_arg,
124
- second_arg))
125
- do_something
126
- end
127
-
128
- - name: indent method call with multiline arguments (implicit brackets)
129
- input: |
130
- def method_with_multiline_method_call
131
- multiline_method_call first_arg,
132
- second_arg,
133
- # Comment in the middle of all this
134
- third_arg
135
-
136
- another_method_call
137
- end
138
- output: |
139
- def method_with_multiline_method_call
140
- multiline_method_call first_arg,
141
- second_arg,
142
- # Comment in the middle of all this
143
- third_arg
144
-
145
- another_method_call
146
- end
147
-
148
- - name: should indent multiline method call chains
149
- input: |
150
- def method_with_multiline_method_call_chain
151
- multiline_method_call.
152
- foo.
153
- bar
154
-
155
- another_method_call
156
- end
157
- output: |
158
- def method_with_multiline_method_call_chain
159
- multiline_method_call.
160
- foo.
161
- bar
162
-
163
- another_method_call
164
- end
165
-
166
- - name: handle multiline code with escaped quotes in strings
167
- input: |
168
- def method_containing_multiline_code_with_strings
169
- a = "foo #{method}" +
170
- "bar"
171
- end
172
- output: |
173
- def method_containing_multiline_code_with_strings
174
- a = "foo #{method}" +
175
- "bar"
176
- end
177
-
178
- - name: not change the indentation of multiline strings
179
- input: |
180
- def method_containing_long_string
181
- a = "
182
- Some text across multiple lines
183
- And another line
184
- "
185
- b = 5
186
- end
187
- output: |
188
- def method_containing_long_string
189
- a = "
190
- Some text across multiple lines
191
- And another line
192
- "
193
- b = 5
194
- end
195
-
196
- - name: not treat divison as start of regex
197
- input: |
198
- def foo
199
- a = 1/2
200
- b = :foo
201
- end
202
- output: |
203
- def foo
204
- a = 1/2
205
- b = :foo
206
- end
207
-
208
- - name: not indent multiline string even if it uses non quote delimiter
209
- pending: implementation of block matcher for non quote delimited strings
210
- input: |
211
- foo = <<TEXT
212
- some string
213
- and more string
214
- TEXT
215
-
216
- - name: recognize when two blocks end on the same line
217
- input: |
218
- class Foo
219
- def foobar
220
- if a = 3
221
- return 5
222
- end; end
223
- end
224
- output: |
225
- class Foo
226
- def foobar
227
- if a = 3
228
- return 5
229
- end; end
230
- end
231
-
232
- - name: indent multiline array definition
233
- input: |
234
- class Foo
235
- @@bar = [1, 2,
236
- 3, 4]
237
- end
238
- output: |
239
- class Foo
240
- @@bar = [1, 2,
241
- 3, 4]
242
- end
243
-
244
- - name: indent multiline array definition (all on separate lines)
245
- input: |
246
- class Foo
247
- @@bar = [
248
- 1,
249
- 2,
250
- 3,
251
- 4
252
- ]
253
- end
254
- output: |
255
- class Foo
256
- @@bar = [
257
- 1,
258
- 2,
259
- 3,
260
- 4
261
- ]
262
- end
263
-
264
- - name: indent multiline hash definition
265
- input: |
266
- class Foo
267
- @@bar = { :foo => 1, :bar => 2
268
- :c => 3, :d => 4 }
269
- end
270
- output: |
271
- class Foo
272
- @@bar = { :foo => 1, :bar => 2
273
- :c => 3, :d => 4 }
274
- end
275
-
276
- - name: indent multiline block delimited with curly brackets
277
- input: |
278
- foo = bar.collect { |paragraph|
279
- paragraph.strip
280
- }.join("\n")
281
- output: |
282
- foo = bar.collect { |paragraph|
283
- paragraph.strip
284
- }.join("\n")
285
-
286
- - name: indent method call with bracketed multiline arguments including continuing statements
287
- pending: Implementation of support for continuing statements in bracketed multline arguments
288
- input: |
289
- def foo
290
- bar(first_arg,
291
- second_part_a +
292
- second_part_b,
293
- third_arg)
294
- end
295
- output: |
296
- def foo
297
- bar(first_arg,
298
- second_part_a +
299
- second_part_b,
300
- third_arg)
301
- end
302
-
303
- - name: indent continuing lines ending in = and +
304
- input: |
305
- def foo
306
- @bar ||=
307
- 1 +
308
- 2
309
- end
310
- output: |
311
- def foo
312
- @bar ||=
313
- 1 +
314
- 2
315
- end
316
-
317
- - name: indent block within implicit brackets
318
- pending: Implementation of support for this feature
319
- input: |
320
- def foo
321
- bar first_arg,
322
- second_arg,
323
- [
324
- 1,
325
- 2,
326
- 3
327
- ],
328
- last_arg
329
- end
330
- output: |
331
- def foo
332
- bar first_arg,
333
- second_arg,
334
- [
335
- 1,
336
- 2,
337
- 3
338
- ],
339
- last_arg
340
- end
341
-
342
- - name: "should not treat ':', '_' or '.' as word boundaries before keywords"
343
- input: |
344
- case params[:do]
345
- when "update_if"
346
- update_if.if
347
- when "update_do"
348
- update_do.do
349
- end
350
- output: |
351
- case params[:do]
352
- when "update_if"
353
- update_if.if
354
- when "update_do"
355
- update_do.do
356
- end
357
-
358
- - name: should recognize interpolation and not match other content within double quotes
359
- input: |
360
- def foo
361
- return "Foo#{" (#{bar})"}"
362
- end
363
- output: |
364
- def foo
365
- return "Foo#{" (#{bar})"}"
366
- end
367
-
368
- - name: should not non interpolated content within regexes and strings and backticks
369
- input: |
370
- def foo
371
- @foo = [
372
- /" if bar/,
373
- `ls if`,
374
- "if fun =",
375
- 'else'
376
- ]
377
- end
378
- output: |
379
- def foo
380
- @foo = [
381
- /" if bar/,
382
- `ls if`,
383
- "if fun =",
384
- 'else'
385
- ]
386
- end
387
-
388
- - name: should handle one liners that include an end statement correctly
389
- input: |
390
- def foo; puts 'foo' end
391
- def bar; puts 'bar' end
392
- output: |
393
- def foo; puts 'foo' end
394
- def bar; puts 'bar' end
395
-
396
- - name: should handle if and unless statements that are terminated implicitly
397
- input: |
398
- def foo
399
- bar = (1 + 2) if foobar
400
- baz unless foobaz
401
- Boo.new(:boo) rescue raise('Houston we have a problem')
402
- end
403
- output: |
404
- def foo
405
- bar = (1 + 2) if foobar
406
- baz unless foobaz
407
- Boo.new(:boo) rescue raise('Houston we have a problem')
408
- end