rufo 0.0.14 → 0.0.15

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: 7b047d001bf378b8733edc5693f53028394707a7
4
- data.tar.gz: eeebbd17f2c9a4bd8a432629bc008bebfced7204
3
+ metadata.gz: 58d381d047814159725642414cb1a125ec50d64e
4
+ data.tar.gz: 7464184e3f7d22c002de35262849aef5e4d2c7a6
5
5
  SHA512:
6
- metadata.gz: '082317f331df08fca9951fd18d64b458da6ce0fd118a1129da5f6b54e81b8618ce3e5894cda151c40246ed71dc3d12e19c3db3d06b4a9a12c1bbbffd06cf6b39'
7
- data.tar.gz: 71e4d7f9c434c7693202a639d3644e93d5124070bd5ee4908efed5aa957aaef2018a8170d4ada5ba07a328a90654e8fbbd3f2504a757a8235a33bef336098840
6
+ metadata.gz: 796b5876a25028f262840d138d83fd7e506e29322e2c7c20b6f30dbd6cfa0050bbe6e329eaa66a821f651637704e4d337249f44ef23d9670b67f3657eeaa9c5f
7
+ data.tar.gz: 51bcf73cfd16618b9d512325a74acbddbd6936e61c1ec1069af28a613ebabe20209ec4f85bcebd2378b69fc75af7f37b0227d5cb919cbc9ce78f2a5e76e24688
@@ -41,6 +41,11 @@ class Rufo::Formatter
41
41
  # Position of comments that occur at the end of a line
42
42
  @comments_positions = []
43
43
 
44
+ # Associate a line to an index inside @comments_position
45
+ # becuase when aligning something to the left of a comment
46
+ # we need to adjust the relative comment
47
+ @line_to_comments_position_index = {}
48
+
44
49
  # Position of assignments
45
50
  @assignments_positions = []
46
51
 
@@ -86,9 +91,9 @@ class Rufo::Formatter
86
91
  consume_end
87
92
  write_line unless @last_was_newline
88
93
 
89
- do_align_comments if @align_comments
90
94
  do_align_assignments if @align_assignments
91
95
  do_align_hash_keys if @align_hash_keys
96
+ do_align_comments if @align_comments
92
97
  end
93
98
 
94
99
  def visit(node)
@@ -488,7 +493,15 @@ class Rufo::Formatter
488
493
  _, string1, string2 = node
489
494
 
490
495
  visit string1
491
- consume_space
496
+
497
+ if skip_space_backslash
498
+ write " \\"
499
+ write_line
500
+ write_indent
501
+ else
502
+ consume_space
503
+ end
504
+
492
505
  visit string2
493
506
  end
494
507
 
@@ -628,6 +641,7 @@ class Rufo::Formatter
628
641
  end
629
642
 
630
643
  def track_comment
644
+ @line_to_comments_position_index[@line] = @comments_positions.size
631
645
  @comments_positions << [@line, @column, 0, nil, 0]
632
646
  end
633
647
 
@@ -838,7 +852,13 @@ class Rufo::Formatter
838
852
 
839
853
  push_call(node) do
840
854
  visit name
841
- consume_space
855
+ if skip_space_backslash
856
+ write " \\"
857
+ write_line
858
+ write_indent(next_indent)
859
+ else
860
+ consume_space
861
+ end
842
862
  end
843
863
 
844
864
  visit_command_end(node, args)
@@ -1340,8 +1360,16 @@ class Rufo::Formatter
1340
1360
  else
1341
1361
  needs_space = op != :* && op != :/ && op != :**
1342
1362
  end
1343
- skip_space
1344
- write_space " " if needs_space
1363
+
1364
+ if skip_space_backslash
1365
+ needs_space = true
1366
+ write " \\"
1367
+ write_line
1368
+ write_indent(next_indent)
1369
+ else
1370
+ write_space " " if needs_space
1371
+ end
1372
+
1345
1373
  consume_op_or_keyword op
1346
1374
  indent_after_space right, false, needs_space
1347
1375
  end
@@ -2353,6 +2381,15 @@ class Rufo::Formatter
2353
2381
  end
2354
2382
  end
2355
2383
 
2384
+ def skip_space_backslash
2385
+ has_slash_newline = false
2386
+ while space?
2387
+ has_slash_newline ||= current_token_value == "\\\n"
2388
+ next_token
2389
+ end
2390
+ has_slash_newline
2391
+ end
2392
+
2356
2393
  def skip_space_or_newline(want_semicolon = false)
2357
2394
  found_newline = false
2358
2395
  found_comment = false
@@ -2763,7 +2800,7 @@ class Rufo::Formatter
2763
2800
  end
2764
2801
 
2765
2802
  def do_align_comments
2766
- do_align @comments_positions
2803
+ do_align @comments_positions, false
2767
2804
  end
2768
2805
 
2769
2806
  def do_align_assignments
@@ -2774,7 +2811,7 @@ class Rufo::Formatter
2774
2811
  do_align @hash_keys_positions
2775
2812
  end
2776
2813
 
2777
- def do_align(elements)
2814
+ def do_align(elements, adjust_comments = true)
2778
2815
  lines = @output.lines
2779
2816
 
2780
2817
  elements.reject! { |l, c, indent, id, off, ignore| ignore == :ignore }
@@ -2800,7 +2837,13 @@ class Rufo::Formatter
2800
2837
  before = target_line[0...split_index]
2801
2838
  after = target_line[split_index..-1]
2802
2839
 
2803
- filler = " " * (max_column - column)
2840
+ filler_size = max_column - column
2841
+ filler = " " * filler_size
2842
+
2843
+ if adjust_comments && (index = @line_to_comments_position_index[line])
2844
+ @comments_positions[index][1] += filler_size
2845
+ end
2846
+
2804
2847
  lines[line] = "#{before}#{filler}#{after}"
2805
2848
  end
2806
2849
  end
data/lib/rufo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rufo
2
- VERSION = "0.0.14"
2
+ VERSION = "0.0.15"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rufo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ary Borenszweig
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-23 00:00:00.000000000 Z
11
+ date: 2017-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler