rufo 0.0.13 → 0.0.14

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: c0aa53149a53b3f3ff74b0faac96f745fb8de3bc
4
- data.tar.gz: df17be90c64c3bab54fd6fec7cc4cfa50e29308d
3
+ metadata.gz: 7b047d001bf378b8733edc5693f53028394707a7
4
+ data.tar.gz: eeebbd17f2c9a4bd8a432629bc008bebfced7204
5
5
  SHA512:
6
- metadata.gz: 01d29475450119316f571f6812d3137a8cd32d1e4dfc3b9ce66fdc808de906c65a6667fd997d6485c6ba067bf192dd5be527589a8c7b12751e0896b999b1da6c
7
- data.tar.gz: 8d23542daf66eb90d1f2e0b6b05d150654a9e6c636c3993aa9c48bac995c91e7bdff1f2542d2dc98b15ce4c22f32d0814d12fee80156a06889cb0b17432f57bb
6
+ metadata.gz: '082317f331df08fca9951fd18d64b458da6ce0fd118a1129da5f6b54e81b8618ce3e5894cda151c40246ed71dc3d12e19c3db3d06b4a9a12c1bbbffd06cf6b39'
7
+ data.tar.gz: 71e4d7f9c434c7693202a639d3644e93d5124070bd5ee4908efed5aa957aaef2018a8170d4ada5ba07a328a90654e8fbbd3f2504a757a8235a33bef336098840
@@ -83,7 +83,9 @@ class Rufo::Formatter
83
83
 
84
84
  def format
85
85
  visit @sexp
86
+ consume_end
86
87
  write_line unless @last_was_newline
88
+
87
89
  do_align_comments if @align_comments
88
90
  do_align_assignments if @align_assignments
89
91
  do_align_hash_keys if @align_hash_keys
@@ -115,6 +117,16 @@ class Rufo::Formatter
115
117
  #
116
118
  # [:@int, "123.45", [1, 0]]
117
119
  consume_token :on_float
120
+ when :@rational
121
+ # Rational literal
122
+ #
123
+ # [:@rational, "123r", [1, 0]]
124
+ consume_token :on_rational
125
+ when :@imaginary
126
+ # Imaginary literal
127
+ #
128
+ # [:@imaginary, "123i", [1, 0]]
129
+ consume_token :on_imaginary
118
130
  when :@CHAR
119
131
  # [:@CHAR, "?a", [1, 0]]
120
132
  consume_token :on_CHAR
@@ -332,7 +344,7 @@ class Rufo::Formatter
332
344
  visit_super(node)
333
345
  when :defined
334
346
  visit_defined(node)
335
- when :alias
347
+ when :alias, :var_alias
336
348
  visit_alias(node)
337
349
  when :undef
338
350
  visit_undef(node)
@@ -343,6 +355,10 @@ class Rufo::Formatter
343
355
  consume_keyword "retry"
344
356
  when :for
345
357
  visit_for(node)
358
+ when :BEGIN
359
+ visit_BEGIN(node)
360
+ when :END
361
+ visit_END(node)
346
362
  else
347
363
  bug "Unhandled node: #{node.first}"
348
364
  end
@@ -586,9 +602,8 @@ class Rufo::Formatter
586
602
  visit_comma_separated_list lefts
587
603
  skip_space
588
604
 
589
- # A trailing comma can come after the left hand side,
590
- # and we remove it
591
- next_token if comma?
605
+ # A trailing comma can come after the left hand side
606
+ consume_token :on_comma if comma?
592
607
 
593
608
  consume_space
594
609
  track_assignment
@@ -1198,6 +1213,39 @@ class Rufo::Formatter
1198
1213
  consume_keyword "end"
1199
1214
  end
1200
1215
 
1216
+ def visit_BEGIN(node)
1217
+ visit_BEGIN_or_END node, "BEGIN"
1218
+ end
1219
+
1220
+ def visit_END(node)
1221
+ visit_BEGIN_or_END node, "END"
1222
+ end
1223
+
1224
+ def visit_BEGIN_or_END(node, keyword)
1225
+ # [:BEGIN, body]
1226
+ _, body = node
1227
+
1228
+ consume_keyword(keyword)
1229
+ consume_space
1230
+
1231
+ closing_brace_token = find_closing_brace_token
1232
+
1233
+ # If the whole block fits into a single line, format
1234
+ # in a single line
1235
+ if current_token[0][0] == closing_brace_token[0][0]
1236
+ consume_token :on_lbrace
1237
+ consume_space
1238
+ visit_exps body, false, false
1239
+ consume_space
1240
+ consume_token :on_rbrace
1241
+ else
1242
+ consume_token :on_lbrace
1243
+ indent_body body
1244
+ write_indent
1245
+ consume_token :on_rbrace
1246
+ end
1247
+ end
1248
+
1201
1249
  def visit_comma_separated_list(nodes, inside_call = false)
1202
1250
  # When there's *x inside a left hand side assignment
1203
1251
  # or a case when, it comes as [:op, ...]
@@ -2506,6 +2554,21 @@ class Rufo::Formatter
2506
2554
  next_token
2507
2555
  end
2508
2556
 
2557
+ def consume_end
2558
+ return unless current_token_kind == :on___end__
2559
+
2560
+ line = current_token[0][0]
2561
+
2562
+ write_line
2563
+ consume_token :on___end__
2564
+
2565
+ lines = @code.lines[line..-1]
2566
+ lines.each do |line|
2567
+ write line.chomp
2568
+ write_line
2569
+ end
2570
+ end
2571
+
2509
2572
  def indent(value = nil)
2510
2573
  if value
2511
2574
  old_indent = @indent
@@ -2662,6 +2725,7 @@ class Rufo::Formatter
2662
2725
  return token if count == 0
2663
2726
  end
2664
2727
  end
2728
+ nil
2665
2729
  end
2666
2730
 
2667
2731
  def next_token
data/lib/rufo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rufo
2
- VERSION = "0.0.13"
2
+ VERSION = "0.0.14"
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.13
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ary Borenszweig