rufo 0.0.19 → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 37581d331f99c0a339a02883d5eee479441a51c7
4
- data.tar.gz: 5f65749a69f3d7542630b8509bb75b8925be48d1
3
+ metadata.gz: b322ac4c05931d04475299c6b98e3ca70537941c
4
+ data.tar.gz: 707eeb3653a5e309028fd3aea0f104654f9d7e4d
5
5
  SHA512:
6
- metadata.gz: 987ae28a14a0c618bed6d037607d698931b71ce3b2757f59078ec68c58b0f239d66077931d9b53a65aa94c75309961fe5834f6dde425889a24165d55b47fb79f
7
- data.tar.gz: 7070cc3d2d44f9fc55d1029458cf7145d36b7bf97c438ac2cda077f8c670521d5516d3b817e8cc32d483e3799766650327223c7431eca65a3d96a4dd8b3e9608
6
+ metadata.gz: 14cbee46609b75b46199a5dcd1b54f6066efc8b1fda1ec1e0f6494191f41fe6f0d8148c632c46bcb6868cd7a8ade5421d9d0a04dfbaaa125c51300b65d1a273c
7
+ data.tar.gz: 4b983949675d6764b73ecf1479ad26992aace76b197b1e96a348a8699416e83b2da645bf2392f066d5dca30a1d08e8c486ecb7a11c1ef5a9f2c98390f0373a59
data/.rufo CHANGED
@@ -2,4 +2,5 @@ space_after_hash_brace :dynamic
2
2
  align_comments true
3
3
  align_assignments false
4
4
  align_hash_keys true
5
+ align_case_when true
5
6
  indent_size 2
data/README.md CHANGED
@@ -74,6 +74,9 @@ align_assignments false
74
74
  # Whether to align successive hash keys (default: true)
75
75
  align_hash_keys true
76
76
 
77
+ # Whether to align successive case when (default: true)
78
+ align_case_when true
79
+
77
80
  # The indent size (default: 2)
78
81
  indent_size 2
79
82
  ```
@@ -52,12 +52,16 @@ class Rufo::Formatter
52
52
  # Hash keys positions
53
53
  @hash_keys_positions = []
54
54
 
55
+ # Case when positions
56
+ @case_when_positions = []
57
+
55
58
  # Settings
56
59
  indent_size options.fetch(:indent_size, 2)
57
60
  space_after_hash_brace options.fetch(:space_after_hash_brace, :dynamic)
58
61
  align_comments options.fetch(:align_comments, true)
59
62
  align_assignments options.fetch(:align_assignments, false)
60
63
  align_hash_keys options.fetch(:align_hash_keys, true)
64
+ align_case_when options.fetch(:align_case_when, true)
61
65
  end
62
66
 
63
67
  # The indent size (default: 2)
@@ -94,6 +98,11 @@ class Rufo::Formatter
94
98
  @align_hash_keys = value
95
99
  end
96
100
 
101
+ # Whether to align successive case when (default: true)
102
+ def align_case_when(value)
103
+ @align_case_when = value
104
+ end
105
+
97
106
  def format
98
107
  visit @sexp
99
108
  consume_end
@@ -101,6 +110,7 @@ class Rufo::Formatter
101
110
 
102
111
  do_align_assignments if @align_assignments
103
112
  do_align_hash_keys if @align_hash_keys
113
+ do_align_case_when if @align_case_when
104
114
  do_align_comments if @align_comments
105
115
  end
106
116
 
@@ -672,10 +682,14 @@ class Rufo::Formatter
672
682
  track_alignment @hash_keys_positions, 0, @current_hash.object_id
673
683
  end
674
684
 
685
+ def track_case_when
686
+ track_alignment @case_when_positions
687
+ end
688
+
675
689
  def track_alignment(target, offset = 0, id = nil)
676
690
  last = target.last
677
691
  if last && last[0] == @line
678
- last << :ignore if last.size < 6
692
+ # Track only the first alignment in a line
679
693
  return
680
694
  end
681
695
 
@@ -1799,7 +1813,7 @@ class Rufo::Formatter
1799
1813
 
1800
1814
  if has_newline
1801
1815
  write_line
1802
- write_indent(next_indent)
1816
+ write_indent
1803
1817
  end
1804
1818
 
1805
1819
  if last_token
@@ -2402,10 +2416,14 @@ class Rufo::Formatter
2402
2416
  if then_keyword
2403
2417
  next_token
2404
2418
  skip_space
2419
+ track_case_when
2405
2420
  skip_semicolons
2406
2421
 
2407
2422
  if newline? || comment?
2408
2423
  inline = false
2424
+
2425
+ # Cancel tracking of `case when ... then` on a nelwine.
2426
+ @case_when_positions.pop
2409
2427
  else
2410
2428
  write " then "
2411
2429
  end
@@ -2415,7 +2433,9 @@ class Rufo::Formatter
2415
2433
  if newline? || comment?
2416
2434
  inline = false
2417
2435
  else
2418
- write "; "
2436
+ write ";"
2437
+ track_case_when
2438
+ write " "
2419
2439
  end
2420
2440
  end
2421
2441
 
@@ -2926,11 +2946,13 @@ class Rufo::Formatter
2926
2946
  do_align @hash_keys_positions, true, true
2927
2947
  end
2928
2948
 
2949
+ def do_align_case_when
2950
+ do_align @case_when_positions
2951
+ end
2952
+
2929
2953
  def do_align(elements, adjust_comments = true, hash_keys = false)
2930
2954
  lines = @output.lines
2931
2955
 
2932
- elements.reject! { |l, c, indent, id, off, ignore| ignore == :ignore }
2933
-
2934
2956
  # Chunk comments that are in consecutive lines
2935
2957
  chunks = chunk_while(elements) do |(l1, c1, i1, id1), (l2, c2, i2, id2)|
2936
2958
  l1 + 1 == l2 && i1 == i2 && id1 == id2
@@ -1,3 +1,3 @@
1
1
  module Rufo
2
- VERSION = "0.0.19"
2
+ VERSION = "0.0.20"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rufo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.19
4
+ version: 0.0.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ary Borenszweig