rufo 0.0.32 → 0.0.33
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rufo +24 -10
- data/README.md +856 -71
- data/lib/rufo.rb +2 -2
- data/lib/rufo/formatter.rb +388 -183
- data/lib/rufo/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3fd395a366e561d4a5196bd66a89e84488ca699
|
4
|
+
data.tar.gz: b1e5f7872f193254a8287a0778a9c6a747c4532a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abef0e942b850cbfbd21a032f63dd1f7a9d487ae4d1dd2fbc071232f7ff434f5dddb855faba972773e6d0a1747e15d59ab11e85e3920c838d5c2afb4b7135498
|
7
|
+
data.tar.gz: 701c57b9d9bdca0a1e5bd121f6abd33b1ecff4cdeb6c1449905bd77d3064fc4facdb2381d472043b25a09e898be12972ab89ea016e7010bb35ff398f6dca1db9
|
data/.rufo
CHANGED
@@ -1,10 +1,24 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
indent_size 2
|
2
|
+
spaces_inside_hash_brace :never
|
3
|
+
spaces_inside_array_bracket :never
|
4
|
+
spaces_around_equal :one
|
5
|
+
spaces_in_ternary :one
|
6
|
+
spaces_in_suffix :one
|
7
|
+
spaces_in_commands :dynamic
|
8
|
+
spaces_around_block_brace :one
|
9
|
+
spaces_after_comma :dynamic
|
10
|
+
spaces_around_hash_arrow :one
|
11
|
+
spaces_around_when :one
|
12
|
+
spaces_around_dot :no
|
13
|
+
spaces_after_lambda_arrow :no
|
14
|
+
spaces_around_unary :no
|
15
|
+
spaces_around_binary :one
|
16
|
+
parens_in_def :yes
|
17
|
+
double_newline_inside_type :no
|
18
|
+
visibility_indent :align
|
19
|
+
trailing_commas :always
|
20
|
+
align_comments true
|
21
|
+
align_assignments false
|
22
|
+
align_hash_keys false
|
23
|
+
align_case_when true
|
24
|
+
align_chained_calls true
|
data/README.md
CHANGED
@@ -19,6 +19,88 @@ However, it takes between 2 and 5 seconds to format a 3000+ lines file, and abou
|
|
19
19
|
a 500 lines file. A second is too much delay for a plugin editor. Additionally, RuboCop is much more
|
20
20
|
than just a code formatter. Rufo is and will always be a code formatter.
|
21
21
|
|
22
|
+
## Unobtrusive by default
|
23
|
+
|
24
|
+
We Ruby programmers think code beauty and readability is very important. We might align code
|
25
|
+
in some ways that a formatter would come and destroy. Many are against automatic code formatters
|
26
|
+
for this reason.
|
27
|
+
|
28
|
+
By default, Rufo is configured in a way that these decisions are preserved. In this way you
|
29
|
+
can start using it in your favorite text editor without forcing your whole team to start using it.
|
30
|
+
|
31
|
+
For example, this code:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
class Foo
|
35
|
+
include Bar
|
36
|
+
extend Baz
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
has an extra space after `extend`, but by doing that `Bar` becomes aligned with `Baz`.
|
41
|
+
It might look better for some, and Rufo preserves this choice by default.
|
42
|
+
|
43
|
+
A similar example is aligning call arguments:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
register :command, "Format"
|
47
|
+
register :action, "Save"
|
48
|
+
```
|
49
|
+
|
50
|
+
Here too, an extra space is added to align `"Format"` with `"Save"`. Again, Rufo will preserve
|
51
|
+
this choice.
|
52
|
+
|
53
|
+
Another example is aligning call parameters:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
# Align with respect to the first parameter
|
57
|
+
foo 1, 2,
|
58
|
+
3, 4,
|
59
|
+
5
|
60
|
+
|
61
|
+
# Align by regular indent (2 spaces)
|
62
|
+
foo 1, 2,
|
63
|
+
3, 4,
|
64
|
+
5
|
65
|
+
|
66
|
+
# Align arrays
|
67
|
+
foo 1, [
|
68
|
+
2,
|
69
|
+
3,
|
70
|
+
]
|
71
|
+
|
72
|
+
# Don't extra align arrays:
|
73
|
+
foo 1, [
|
74
|
+
2,
|
75
|
+
3,
|
76
|
+
]
|
77
|
+
|
78
|
+
# Aling trailing calls
|
79
|
+
assert foo(
|
80
|
+
1
|
81
|
+
)
|
82
|
+
|
83
|
+
# Don't extra align trailing calls
|
84
|
+
assert foo(
|
85
|
+
1
|
86
|
+
)
|
87
|
+
```
|
88
|
+
|
89
|
+
All of the alignment choices above are fine depending on the context where they are
|
90
|
+
used, and Rufo will not destroy that choice. It will, however, keep things aligned
|
91
|
+
so they look good.
|
92
|
+
|
93
|
+
If Rufo does not change these things by default, what does it do? Well, it makes sure that:
|
94
|
+
|
95
|
+
- code at the beginning of a line is correctly indented
|
96
|
+
- array and hash elements are aligned
|
97
|
+
- there are no spaces **before** commas
|
98
|
+
- there are no more than one consecutive empty lines
|
99
|
+
- methods are separated by an empty line
|
100
|
+
- no trailing semicolons remain
|
101
|
+
|
102
|
+
And of course it can be configured to do more. Check the settings section below.
|
103
|
+
|
22
104
|
## Installation
|
23
105
|
|
24
106
|
Add this line to your application's Gemfile:
|
@@ -70,105 +152,808 @@ I will list it here.
|
|
70
152
|
|
71
153
|
## Configuration
|
72
154
|
|
73
|
-
|
74
|
-
|
75
|
-
To configure it, place a `.rufo` file in your project. When formatting a file or a directory
|
155
|
+
To configure Rufo, place a `.rufo` file in your project. When formatting a file or a directory
|
76
156
|
via the `rufo` program, a `.rufo` file will try to be found in that directory or parent directories.
|
77
157
|
|
78
|
-
The `.rufo` file is a Ruby file that is evaluated in the context of the formatter.
|
79
|
-
available configurations
|
158
|
+
The `.rufo` file is a Ruby file that is evaluated in the context of the formatter.
|
159
|
+
The available configurations are listed below.
|
160
|
+
|
161
|
+
### indent_size
|
162
|
+
|
163
|
+
Sets the indent size. Default: 2
|
164
|
+
|
165
|
+
### spaces_inside_hash_brace
|
166
|
+
|
167
|
+
Allow spaces inside hash braces?
|
168
|
+
|
169
|
+
- `:dynamic`: (default) if there's a space, keep it. Otherwise don't add it.
|
170
|
+
- `:always`: always add a space
|
171
|
+
- `:never`: never add a space
|
172
|
+
|
173
|
+
With `:always`, hashes will look like this:
|
174
|
+
|
175
|
+
```ruby
|
176
|
+
{ :foo => 1, :bar => 2}
|
177
|
+
```
|
178
|
+
|
179
|
+
With `:never`, hashes will look like this:
|
180
|
+
|
181
|
+
```ruby
|
182
|
+
{:foo => 1, :bar => 2}
|
183
|
+
```
|
184
|
+
|
185
|
+
With `:dynamic`, any of the above choices is fine.
|
186
|
+
|
187
|
+
### spaces_inside_array_bracket
|
188
|
+
|
189
|
+
Allow spaces inside array brackets?
|
190
|
+
|
191
|
+
- `:dynamic`: (default) if there's a space, keep it. Otherwise don't add it.
|
192
|
+
- `:always`: always add a space
|
193
|
+
- `:never`: never add a space
|
194
|
+
|
195
|
+
With `:always`, arrays will look like this:
|
196
|
+
|
197
|
+
```ruby
|
198
|
+
[ 1, 2 ]
|
199
|
+
```
|
200
|
+
|
201
|
+
With `:never`, arrays will look like this:
|
202
|
+
|
203
|
+
```ruby
|
204
|
+
[1, 2]
|
205
|
+
```
|
206
|
+
|
207
|
+
With `:dynamic`, any of the above choices is fine.
|
208
|
+
|
209
|
+
### spaces_around_equal
|
210
|
+
|
211
|
+
How to format spaces around an equal (`=`) sign?
|
212
|
+
|
213
|
+
- `:dynamic`: (default) allow any number of spaces (even zero) around the equal sign
|
214
|
+
- `:one`: always use one space before and after the equal sign
|
215
|
+
|
216
|
+
Given this code:
|
217
|
+
|
218
|
+
```ruby
|
219
|
+
a=1
|
220
|
+
b = 2
|
221
|
+
```
|
222
|
+
|
223
|
+
With `:one` the formatter will change it to:
|
224
|
+
|
225
|
+
```ruby
|
226
|
+
a = 1
|
227
|
+
b = 2
|
228
|
+
```
|
229
|
+
|
230
|
+
With `:dynamic` it won't modify it.
|
231
|
+
|
232
|
+
If `align_assignments` is `true`, then this setting has no effect and `:one`
|
233
|
+
will be used when no other assignments are above/below an assignment.
|
234
|
+
|
235
|
+
### spaces_around_ternary
|
236
|
+
|
237
|
+
How to format spaces around a ternary (`cond ? then : else`) operator?
|
238
|
+
|
239
|
+
- `:dynamic`: (default) allow any number of spaces (even zero) around `?` and `:`
|
240
|
+
- `:one`: always use one space before and after `?` and `:`
|
241
|
+
|
242
|
+
Given this code:
|
243
|
+
|
244
|
+
```ruby
|
245
|
+
a?b:c
|
246
|
+
a ? b : c
|
247
|
+
```
|
248
|
+
|
249
|
+
With `:one` the formatter will change it to:
|
250
|
+
|
251
|
+
```ruby
|
252
|
+
a ? b : c
|
253
|
+
a ? b : c
|
254
|
+
```
|
255
|
+
|
256
|
+
With `:dynamic` it won't modify it.
|
257
|
+
|
258
|
+
### spaces_in_suffix
|
259
|
+
|
260
|
+
How to format spaces around a suffix `if`, `unless`, etc?
|
261
|
+
|
262
|
+
- `:dynamic`: (default) allow any number of spaces (even zero) around `if`
|
263
|
+
- `:one`: always use one space before and after `if`
|
264
|
+
|
265
|
+
Given this code:
|
266
|
+
|
267
|
+
```ruby
|
268
|
+
a if b
|
269
|
+
```
|
270
|
+
|
271
|
+
With `:one` the formatter will change it to:
|
272
|
+
|
273
|
+
```ruby
|
274
|
+
a if b
|
275
|
+
```
|
276
|
+
|
277
|
+
With `:dynamic` it won't modify it.
|
278
|
+
|
279
|
+
### spaces_in_commands
|
280
|
+
|
281
|
+
How to format spaces after command names (a command is a call without parentheses)?
|
282
|
+
|
283
|
+
- `:dynamic`: (default) allow any number of spaces after a command name
|
284
|
+
- `:one`: always use one space after a command name
|
285
|
+
|
286
|
+
Given this code:
|
287
|
+
|
288
|
+
```ruby
|
289
|
+
include Foo
|
290
|
+
extend Bar
|
291
|
+
```
|
292
|
+
|
293
|
+
With `:one` the formatter will change it to:
|
294
|
+
|
295
|
+
```ruby
|
296
|
+
include Foo
|
297
|
+
extend Bar
|
298
|
+
```
|
299
|
+
|
300
|
+
With `:dynamic` it won't modify it.
|
301
|
+
|
302
|
+
### spaces_around_block_brace
|
303
|
+
|
304
|
+
How to format spaces around block braces?
|
305
|
+
|
306
|
+
- `:dynamic`: (default) allow any number of spaces around block braces
|
307
|
+
- `:one`: always use one space around block braces
|
308
|
+
|
309
|
+
Given this code:
|
310
|
+
|
311
|
+
```ruby
|
312
|
+
foo{|x|1}
|
313
|
+
foo {|x|1}
|
314
|
+
foo { |x|1}
|
315
|
+
foo { |x| 1}
|
316
|
+
```
|
317
|
+
|
318
|
+
With `:one` the formatter will change it to:
|
319
|
+
|
320
|
+
```ruby
|
321
|
+
foo { |x| 1 }
|
322
|
+
foo { |x| 1 }
|
323
|
+
foo { |x| 1 }
|
324
|
+
foo { |x| 1 }
|
325
|
+
```
|
326
|
+
|
327
|
+
With `:dynamic` it won't modify it.
|
328
|
+
|
329
|
+
### spaces_after_comma
|
330
|
+
|
331
|
+
How to format spaces after commas?
|
332
|
+
|
333
|
+
- `:dynamic`: (default) allow any number of spaces around block braces
|
334
|
+
- `:one`: always use one space after a comma
|
335
|
+
|
336
|
+
Given this code:
|
337
|
+
|
338
|
+
```ruby
|
339
|
+
foo 1, 2, 3
|
340
|
+
[1, 2, 3]
|
341
|
+
```
|
342
|
+
|
343
|
+
With `:one` the formatter will change it to:
|
344
|
+
|
345
|
+
```ruby
|
346
|
+
foo 1, 2, 3
|
347
|
+
[1, 2, 3]
|
348
|
+
```
|
349
|
+
|
350
|
+
With `:dynamic` it won't modify it.
|
351
|
+
|
352
|
+
### spaces_around_hash_arrow
|
353
|
+
|
354
|
+
How to format spaces around a hash arrow or keyword argument?
|
355
|
+
|
356
|
+
- `:dynamic`: (default) allow any number of spaces around hash arrows
|
357
|
+
- `:one`: always use one space around hash arrows
|
358
|
+
|
359
|
+
Given this code:
|
360
|
+
|
361
|
+
```ruby
|
362
|
+
{ 1 => 2, 3 => 4 }
|
363
|
+
{ foo: 1, bar: 2 }
|
364
|
+
```
|
365
|
+
|
366
|
+
With `:one` the formatter will change it to:
|
367
|
+
|
368
|
+
```ruby
|
369
|
+
{ 1 => 2, 3 => 4 }
|
370
|
+
{ foo: 1, bar: 2}
|
371
|
+
```
|
372
|
+
|
373
|
+
With `:dynamic` it won't modify it.
|
374
|
+
|
375
|
+
If `align_hash_keys` is `true`, then this setting has no effect and `:one`
|
376
|
+
will be used when no other hash keys are above/below.
|
377
|
+
|
378
|
+
### spaces_around_when
|
379
|
+
|
380
|
+
How to format spaces around a case when and then?
|
381
|
+
|
382
|
+
- `:dynamic`: (default) allow any number of spaces around a case when and then
|
383
|
+
- `:one`: always use one space around a case when and then
|
384
|
+
|
385
|
+
Given this code:
|
386
|
+
|
387
|
+
```ruby
|
388
|
+
case foo
|
389
|
+
when 1 then 2
|
390
|
+
end
|
391
|
+
```
|
392
|
+
|
393
|
+
With `:one` the formatter will change it to:
|
394
|
+
|
395
|
+
```ruby
|
396
|
+
case foo
|
397
|
+
when 1 then 2
|
398
|
+
end
|
399
|
+
```
|
400
|
+
|
401
|
+
With `:dynamic` it won't modify it.
|
402
|
+
|
403
|
+
If `align_case_when` is `true`, then this setting has no effect and `:one`
|
404
|
+
will be used when no other case when are above/below.
|
405
|
+
|
406
|
+
### spaces_around_dot
|
407
|
+
|
408
|
+
How to format spaces around a call dot?
|
409
|
+
|
410
|
+
- `:dynamic`: (default) allow any number of spaces around a call dot
|
411
|
+
- `:no`: no spaces around a call dot
|
412
|
+
|
413
|
+
Given this code:
|
414
|
+
|
415
|
+
```ruby
|
416
|
+
foo . bar
|
417
|
+
foo :: bar
|
418
|
+
foo &. bar
|
419
|
+
```
|
420
|
+
|
421
|
+
With `:no` the formatter will change it to:
|
422
|
+
|
423
|
+
```ruby
|
424
|
+
foo.bar
|
425
|
+
foo::bar
|
426
|
+
foo&.bar
|
427
|
+
```
|
428
|
+
|
429
|
+
With `:dynamic` it won't modify it.
|
430
|
+
|
431
|
+
### spaces_after_lambda_arrow
|
432
|
+
|
433
|
+
How to format spaces after a lambda arrow?
|
434
|
+
|
435
|
+
- `:dynamic`: (default) allow any number of spaces after a lambda arrow
|
436
|
+
- `:no`: no spaces after a lambda arrow
|
437
|
+
|
438
|
+
Given this code:
|
439
|
+
|
440
|
+
```ruby
|
441
|
+
->{ 1 }
|
442
|
+
-> { 2 }
|
443
|
+
```
|
444
|
+
|
445
|
+
With `:no` the formatter will change it to:
|
446
|
+
|
447
|
+
```ruby
|
448
|
+
->{ 1 }
|
449
|
+
->{ 2 }
|
450
|
+
```
|
451
|
+
|
452
|
+
With `:dynamic` it won't modify it.
|
453
|
+
|
454
|
+
For spaces inside the braces, the `spaces_around_block_brace` setting is used.
|
455
|
+
|
456
|
+
### spaces_around_unary
|
457
|
+
|
458
|
+
How to format spaces around a unary operator?
|
459
|
+
|
460
|
+
- `:dynamic`: (default) allow any number of spaces around a unary operator
|
461
|
+
- `:no`: no spaces around a unary operator
|
462
|
+
|
463
|
+
Given this code:
|
464
|
+
|
465
|
+
```ruby
|
466
|
+
+1
|
467
|
+
- 2
|
468
|
+
! x
|
469
|
+
```
|
470
|
+
|
471
|
+
With `:no` the formatter will change it to:
|
472
|
+
|
473
|
+
```ruby
|
474
|
+
+1
|
475
|
+
-2
|
476
|
+
!x
|
477
|
+
```
|
478
|
+
|
479
|
+
With `:dynamic` it won't modify it.
|
480
|
+
|
481
|
+
### spaces_around_binary
|
482
|
+
|
483
|
+
How to format spaces around a binary operator?
|
484
|
+
|
485
|
+
- `:dynamic`: (default) allow any number of spaces around a binary operator
|
486
|
+
- `:one`: at most one space around a binary operator
|
487
|
+
|
488
|
+
Given this code:
|
489
|
+
|
490
|
+
```ruby
|
491
|
+
1+2
|
492
|
+
1 +2
|
493
|
+
1+ 2
|
494
|
+
1 + 2
|
495
|
+
```
|
496
|
+
|
497
|
+
With `:one` the formatter will change it to:
|
498
|
+
|
499
|
+
```ruby
|
500
|
+
1+2
|
501
|
+
1 + 2
|
502
|
+
1+2
|
503
|
+
1 + 2
|
504
|
+
```
|
505
|
+
|
506
|
+
Note that with `:one` the spaces are kept balanced: if there's no space
|
507
|
+
before the operator, no space is kept after it. If there's a space
|
508
|
+
before the operator, a space is added after it.
|
509
|
+
|
510
|
+
With `:dynamic` it won't modify it.
|
511
|
+
|
512
|
+
### parens_in_defs
|
513
|
+
|
514
|
+
Use parentheses in defs?
|
515
|
+
|
516
|
+
- `:dynamic`: (default) don't modify existing methods parentheses choice
|
517
|
+
- `:yes`: always use parentheses (add them if they are not there)
|
518
|
+
|
519
|
+
Given this code:
|
520
|
+
|
521
|
+
```ruby
|
522
|
+
def foo x, y
|
523
|
+
end
|
524
|
+
|
525
|
+
def bar(x, y)
|
526
|
+
end
|
527
|
+
```
|
528
|
+
|
529
|
+
With `:yes` the formatter will change it to:
|
530
|
+
|
531
|
+
```ruby
|
532
|
+
def foo(x, y)
|
533
|
+
end
|
534
|
+
|
535
|
+
def bar(x, y)
|
536
|
+
end
|
537
|
+
```
|
538
|
+
|
539
|
+
With `:dynamic` it won't modify it.
|
540
|
+
|
541
|
+
### double_newline_inside_type
|
542
|
+
|
543
|
+
Allow an empty line inside a type declaration?
|
544
|
+
|
545
|
+
- `:dynamic`: (default) allow at most one empty newline
|
546
|
+
- `:no`: no empty newlines inside type declarations
|
547
|
+
|
548
|
+
Given this code:
|
549
|
+
|
550
|
+
```ruby
|
551
|
+
class Foo
|
552
|
+
|
553
|
+
CONST = 1
|
554
|
+
|
555
|
+
end
|
556
|
+
|
557
|
+
class Bar
|
558
|
+
CONST = 2
|
559
|
+
end
|
560
|
+
```
|
561
|
+
|
562
|
+
With `:no` the formatter will change it to:
|
563
|
+
|
564
|
+
```ruby
|
565
|
+
class Foo
|
566
|
+
CONST = 1
|
567
|
+
end
|
568
|
+
|
569
|
+
class Bar
|
570
|
+
CONST = 2
|
571
|
+
end
|
572
|
+
```
|
573
|
+
|
574
|
+
With `:dynamic` it won't modify it.
|
575
|
+
|
576
|
+
### visibility_indent
|
577
|
+
|
578
|
+
How to indent code after a visibility method (`public`, `protected`, `private`)?
|
579
|
+
|
580
|
+
- `:dynamic`: (default) keep the current code's choice according to the first expression that follows
|
581
|
+
- `:indent`: indent code after the visibility method
|
582
|
+
- `:align`: align code at the same column as the visibility method
|
583
|
+
|
584
|
+
Given this code:
|
585
|
+
|
586
|
+
```ruby
|
587
|
+
class Foo
|
588
|
+
private
|
589
|
+
|
590
|
+
def foo
|
591
|
+
end
|
592
|
+
|
593
|
+
def bar
|
594
|
+
end
|
595
|
+
end
|
596
|
+
|
597
|
+
class Bar
|
598
|
+
private
|
599
|
+
|
600
|
+
def foo
|
601
|
+
end
|
602
|
+
|
603
|
+
def bar
|
604
|
+
end
|
605
|
+
end
|
606
|
+
```
|
607
|
+
|
608
|
+
With `:dynamic`, the formatter will change it to:
|
609
|
+
|
610
|
+
```ruby
|
611
|
+
class Foo
|
612
|
+
private
|
613
|
+
|
614
|
+
def foo
|
615
|
+
end
|
616
|
+
|
617
|
+
def bar
|
618
|
+
end
|
619
|
+
end
|
620
|
+
|
621
|
+
class Bar
|
622
|
+
private
|
623
|
+
|
624
|
+
def foo
|
625
|
+
end
|
626
|
+
|
627
|
+
def bar
|
628
|
+
end
|
629
|
+
end
|
630
|
+
```
|
631
|
+
|
632
|
+
Note that the formatter unified the indentation choice according to the first
|
633
|
+
expression. It makes no sense to keep two choices together inside a same type
|
634
|
+
declaration.
|
635
|
+
|
636
|
+
With `:align`, the formatter will change it to:
|
80
637
|
|
81
638
|
```ruby
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
space_after_array_bracket :dynamic
|
639
|
+
class Foo
|
640
|
+
private
|
641
|
+
|
642
|
+
def foo
|
643
|
+
end
|
88
644
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
# * :always: always put a space after a hash brace
|
93
|
-
# * :never: never put a space after a hash brace
|
94
|
-
space_after_hash_brace :dynamic
|
645
|
+
def bar
|
646
|
+
end
|
647
|
+
end
|
95
648
|
|
96
|
-
|
97
|
-
|
649
|
+
class Bar
|
650
|
+
private
|
98
651
|
|
99
|
-
|
100
|
-
|
652
|
+
def foo
|
653
|
+
end
|
101
654
|
|
102
|
-
|
103
|
-
|
655
|
+
def bar
|
656
|
+
end
|
657
|
+
end
|
658
|
+
```
|
104
659
|
|
105
|
-
|
106
|
-
|
660
|
+
With `:indent`, the formatter will change it to:
|
661
|
+
|
662
|
+
```ruby
|
663
|
+
class Foo
|
664
|
+
private
|
107
665
|
|
108
|
-
|
109
|
-
|
666
|
+
def foo
|
667
|
+
end
|
110
668
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
# This allows for manual alignment of some code that would otherwise
|
115
|
-
# be impossible to automatically format or preserve "beautiful".
|
116
|
-
#
|
117
|
-
# If `align_assignments` is true, this doesn't apply to assignments.
|
118
|
-
# If `align_hash_keys` is true, this doesn't apply to hash keys.
|
119
|
-
#
|
120
|
-
#
|
121
|
-
# Can also be set to `:YES` to preserve whitespace in many more places,
|
122
|
-
# in case there's no clear rule in your workplace/project as to when
|
123
|
-
# to leave spaces or not. This includes spaces (or the absence of them)
|
124
|
-
# around dots, braces, pipes and hash keys and values.
|
125
|
-
preserve_whitespace true
|
669
|
+
def bar
|
670
|
+
end
|
671
|
+
end
|
126
672
|
|
127
|
-
|
128
|
-
|
673
|
+
class Bar
|
674
|
+
private
|
129
675
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
676
|
+
def foo
|
677
|
+
end
|
678
|
+
|
679
|
+
def bar
|
680
|
+
end
|
681
|
+
end
|
136
682
|
```
|
137
683
|
|
138
|
-
|
139
|
-
|
684
|
+
**NOTE:** There's another commonly used indentation style which is `:dedent`:
|
685
|
+
|
686
|
+
```ruby
|
687
|
+
class Foo
|
688
|
+
def foo
|
689
|
+
end
|
690
|
+
|
691
|
+
private
|
692
|
+
|
693
|
+
def bar
|
694
|
+
end
|
695
|
+
end
|
696
|
+
```
|
140
697
|
|
141
|
-
|
698
|
+
Rufo currently doesn't support it, but in the future it might.
|
142
699
|
|
143
|
-
|
700
|
+
### align_comments
|
144
701
|
|
145
|
-
|
702
|
+
Align successive comments?
|
146
703
|
|
147
|
-
|
704
|
+
- `false`: (default) don't align comments (preserve existing code)
|
705
|
+
- `true`: align successive comments
|
148
706
|
|
149
|
-
|
707
|
+
Given this code:
|
150
708
|
|
151
709
|
```ruby
|
152
|
-
#
|
153
|
-
2
|
710
|
+
foo = 1 # some comment
|
711
|
+
barbaz = 2 # some other comment
|
712
|
+
```
|
154
713
|
|
155
|
-
|
156
|
-
2 * x + 3 * y + z
|
714
|
+
With `true`, the formatter will change it to:
|
157
715
|
|
158
|
-
|
159
|
-
|
716
|
+
```ruby
|
717
|
+
foo = 1 # some comment
|
718
|
+
barbaz = 2 # some other comment
|
160
719
|
```
|
161
720
|
|
162
|
-
|
163
|
-
|
164
|
-
|
721
|
+
With `false` it won't modify it.
|
722
|
+
|
723
|
+
### align_assignments
|
724
|
+
|
725
|
+
Align successive assignments?
|
165
726
|
|
166
|
-
|
727
|
+
- `false`: (default) don't align assignments (preserve existing code)
|
728
|
+
- `true`: align successive assignments
|
729
|
+
|
730
|
+
Given this code:
|
731
|
+
|
732
|
+
```ruby
|
733
|
+
foo = 1
|
734
|
+
barbaz = 2
|
735
|
+
```
|
736
|
+
|
737
|
+
With `true`, the formatter will change it to:
|
738
|
+
|
739
|
+
```ruby
|
740
|
+
foo = 1
|
741
|
+
barbaz = 2
|
742
|
+
```
|
743
|
+
|
744
|
+
With `false` it won't modify it.
|
745
|
+
|
746
|
+
### align_hash_keys
|
747
|
+
|
748
|
+
Align successive hash keys?
|
749
|
+
|
750
|
+
- `false`: (default) don't align hash keys (preserve existing code)
|
751
|
+
- `true`: align successive hash keys
|
752
|
+
|
753
|
+
Given this code:
|
754
|
+
|
755
|
+
```ruby
|
756
|
+
{
|
757
|
+
foo: 1,
|
758
|
+
barbaz: 2,
|
759
|
+
}
|
760
|
+
|
761
|
+
{
|
762
|
+
:foo => 1,
|
763
|
+
:barbaz => 2,
|
764
|
+
}
|
765
|
+
|
766
|
+
method foo: 1,
|
767
|
+
barbaz: 2
|
768
|
+
```
|
769
|
+
|
770
|
+
With `true`, the formatter will change it to:
|
771
|
+
|
772
|
+
```ruby
|
773
|
+
{
|
774
|
+
foo: 1,
|
775
|
+
barbaz: 2,
|
776
|
+
}
|
777
|
+
|
778
|
+
{
|
779
|
+
:foo => 1,
|
780
|
+
:barbaz => 2,
|
781
|
+
}
|
782
|
+
|
783
|
+
method foo: 1,
|
784
|
+
barbaz: 2
|
785
|
+
```
|
167
786
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
787
|
+
With `false` it won't modify it.
|
788
|
+
|
789
|
+
### align_case_when
|
790
|
+
|
791
|
+
Align successive case when?
|
792
|
+
|
793
|
+
- `false`: (default) don't align case when (preserve existing code)
|
794
|
+
- `true`: align successive case when
|
795
|
+
|
796
|
+
Given this code:
|
797
|
+
|
798
|
+
```ruby
|
799
|
+
case exp
|
800
|
+
when foo then 2
|
801
|
+
when barbaz then 3
|
802
|
+
end
|
803
|
+
```
|
804
|
+
|
805
|
+
With `true`, the formatter will change it to:
|
806
|
+
|
807
|
+
```ruby
|
808
|
+
case exp
|
809
|
+
when foo then 2
|
810
|
+
when barbaz then 3
|
811
|
+
end
|
812
|
+
```
|
813
|
+
|
814
|
+
With `false` it won't modify it.
|
815
|
+
|
816
|
+
### align_chained_calls
|
817
|
+
|
818
|
+
Align chained calls to the dot?
|
819
|
+
|
820
|
+
- `false`: (default) don't align chained calls to the dot (preserve existing code)
|
821
|
+
- `true`: align chained calls to the dot
|
822
|
+
|
823
|
+
Given this code:
|
824
|
+
|
825
|
+
```ruby
|
826
|
+
foo.bar
|
827
|
+
.baz
|
828
|
+
|
829
|
+
foo.bar
|
830
|
+
.baz
|
831
|
+
```
|
832
|
+
|
833
|
+
With `true`, the formatter will change it to:
|
834
|
+
|
835
|
+
```ruby
|
836
|
+
foo.bar
|
837
|
+
.baz
|
838
|
+
|
839
|
+
foo.bar
|
840
|
+
.baz
|
841
|
+
```
|
842
|
+
|
843
|
+
With `false` it won't modify it.
|
844
|
+
|
845
|
+
Note that with `false` it will keep it aligned to the dot if it's already like that.
|
846
|
+
|
847
|
+
### trailing_commas
|
848
|
+
|
849
|
+
Use trailing commas in array and hash literals, and keyword arguments?
|
850
|
+
|
851
|
+
- `:dynamic`: (default) if there's a trailing comma, keep it. Otherwise, don't remove it
|
852
|
+
- `:always`: always put a trailing comma
|
853
|
+
- `:never`: never put a trailing comma
|
854
|
+
|
855
|
+
Given this code:
|
856
|
+
|
857
|
+
```ruby
|
858
|
+
[
|
859
|
+
1,
|
860
|
+
2
|
861
|
+
]
|
862
|
+
|
863
|
+
[
|
864
|
+
1,
|
865
|
+
2,
|
866
|
+
]
|
867
|
+
|
868
|
+
{
|
869
|
+
foo: 1,
|
870
|
+
bar: 2
|
871
|
+
}
|
872
|
+
|
873
|
+
{
|
874
|
+
foo: 1,
|
875
|
+
bar: 2,
|
876
|
+
}
|
877
|
+
|
878
|
+
foo(
|
879
|
+
x: 1,
|
880
|
+
y: 2
|
881
|
+
)
|
882
|
+
|
883
|
+
foo(
|
884
|
+
x: 1,
|
885
|
+
y: 2,
|
886
|
+
)
|
887
|
+
```
|
888
|
+
|
889
|
+
With `:always`, the formatter will change it to:
|
890
|
+
|
891
|
+
```ruby
|
892
|
+
[
|
893
|
+
1,
|
894
|
+
2,
|
895
|
+
]
|
896
|
+
|
897
|
+
[
|
898
|
+
1,
|
899
|
+
2,
|
900
|
+
]
|
901
|
+
|
902
|
+
{
|
903
|
+
foo: 1,
|
904
|
+
bar: 2,
|
905
|
+
}
|
906
|
+
|
907
|
+
{
|
908
|
+
foo: 1,
|
909
|
+
bar: 2,
|
910
|
+
}
|
911
|
+
|
912
|
+
foo(
|
913
|
+
x: 1,
|
914
|
+
y: 2,
|
915
|
+
)
|
916
|
+
|
917
|
+
foo(
|
918
|
+
x: 1,
|
919
|
+
y: 2,
|
920
|
+
)
|
921
|
+
```
|
922
|
+
With `:never`, the formatter will change it to:
|
923
|
+
|
924
|
+
```ruby
|
925
|
+
[
|
926
|
+
1,
|
927
|
+
2
|
928
|
+
]
|
929
|
+
|
930
|
+
[
|
931
|
+
1,
|
932
|
+
2
|
933
|
+
]
|
934
|
+
|
935
|
+
{
|
936
|
+
foo: 1,
|
937
|
+
bar: 2
|
938
|
+
}
|
939
|
+
|
940
|
+
{
|
941
|
+
foo: 1,
|
942
|
+
bar: 2
|
943
|
+
}
|
944
|
+
|
945
|
+
foo(
|
946
|
+
x: 1,
|
947
|
+
y: 2
|
948
|
+
)
|
949
|
+
|
950
|
+
foo(
|
951
|
+
x: 1,
|
952
|
+
y: 2
|
953
|
+
)
|
954
|
+
``
|
955
|
+
|
956
|
+
With `:dynamic` it won't modify it.
|
172
957
|
|
173
958
|
## How it works
|
174
959
|
|