rufo 0.0.25 → 0.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rufo +10 -7
- data/README.md +21 -3
- data/lib/rufo/formatter.rb +212 -43
- 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: 2da6aac7c9ee2daf498d8131afd7e77717a9ebb7
|
4
|
+
data.tar.gz: 1fbb0734dec03fc709b615fae32f6c52bfcb1df1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d21c78d0b4287cc04e5121c91631dacebcbf7f860c0398335e39f885da82de0a08676048b44c0964e8480253d86ebc78f699e23499931398318ba2a54e7dfc27
|
7
|
+
data.tar.gz: 23800db7fbb6224f5be334fab2141ef022d87906bc27926d6744debfd2d1751538ad9d189f956cf0a8e7c382c8cf0c801a5d6672dba49652117b041a615161ef
|
data/.rufo
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
space_after_array_bracket :never
|
2
|
+
space_after_hash_brace :dynamic
|
3
|
+
preserve_whitespace true
|
4
|
+
align_comments true
|
5
|
+
align_assignments false
|
6
|
+
align_hash_keys true
|
7
|
+
align_case_when true
|
8
|
+
align_chained_calls false
|
9
|
+
indent_size 2
|
10
|
+
trailing_commas :always
|
data/README.md
CHANGED
@@ -61,12 +61,13 @@ according to **rufo**, and will exit with exit code 1.
|
|
61
61
|
## Editor support
|
62
62
|
|
63
63
|
- Sublime Text: [sublime-rufo](https://github.com/asterite/sublime-rufo)
|
64
|
+
- Vim: [rufo-vim](https://github.com/splattael/rufo-vim) :construction:
|
65
|
+
- Atom: [rufo-atom](https://github.com/bmulvihill/rufo-atom) :construction:
|
64
66
|
|
65
67
|
Did you write a plugin for your favorite editor? That's great! Let me know about it and
|
66
68
|
I will list it here.
|
67
69
|
|
68
|
-
Right now it would be great to have [
|
69
|
-
[Atom](https://atom.io/) and [Emacs](https://www.gnu.org/software/emacs/) plugins :-)
|
70
|
+
Right now it would be great to have an [Emacs](https://www.gnu.org/software/emacs/) plugin :-)
|
70
71
|
|
71
72
|
## Configuration
|
72
73
|
|
@@ -79,9 +80,16 @@ The `.rufo` file is a Ruby file that is evaluated in the context of the formatte
|
|
79
80
|
available configurations:
|
80
81
|
|
81
82
|
```ruby
|
83
|
+
# Whether to put a space after an array bracket. Valid values are:
|
84
|
+
#
|
85
|
+
# * :dynamic: if there's a space, keep it. If not, don't add it
|
86
|
+
# * :always: always put a space after an array bracket (default)
|
87
|
+
# * :never: never put a space after an array bracket
|
88
|
+
space_after_array_bracket :never
|
89
|
+
|
82
90
|
# Whether to put a space after a hash brace. Valid values are:
|
83
91
|
#
|
84
|
-
# * :dynamic: if there's a space, keep it. If not, don't
|
92
|
+
# * :dynamic: if there's a space, keep it. If not, don't add it (default)
|
85
93
|
# * :always: always put a space after a hash brace
|
86
94
|
# * :never: never put a space after a hash brace
|
87
95
|
space_after_hash_brace :dynamic
|
@@ -98,6 +106,9 @@ align_hash_keys true
|
|
98
106
|
# Whether to align successive case when (default: true)
|
99
107
|
align_case_when true
|
100
108
|
|
109
|
+
# Whether to align chained calls to the dot (default: true)
|
110
|
+
align_chained_calls true
|
111
|
+
|
101
112
|
# Preserve whitespace after assignments target and values,
|
102
113
|
# after calls that start with a space, hash arrows and commas (default: true).
|
103
114
|
#
|
@@ -110,6 +121,13 @@ preserve_whitespace true
|
|
110
121
|
|
111
122
|
# The indent size (default: 2)
|
112
123
|
indent_size 2
|
124
|
+
|
125
|
+
# Whether to place commas at the end of a multi-line list
|
126
|
+
#
|
127
|
+
# * :dynamic: if there's a comma, keep it. If not, don't add it
|
128
|
+
# * :always: always put a comma (default)
|
129
|
+
# * :never: never put a comma
|
130
|
+
trailing_commas :always
|
113
131
|
```
|
114
132
|
|
115
133
|
As time passes there might be more configurations available. Please open an
|
data/lib/rufo/formatter.rb
CHANGED
@@ -26,6 +26,10 @@ class Rufo::Formatter
|
|
26
26
|
# calls to that dot
|
27
27
|
@dot_column = nil
|
28
28
|
|
29
|
+
# The column of a `obj.method` call, but only the name part,
|
30
|
+
# so we can also align arguments accordingly
|
31
|
+
@name_dot_column = nil
|
32
|
+
|
29
33
|
# Heredocs list, associated with calls ([heredoc, tilde])
|
30
34
|
@heredocs = []
|
31
35
|
|
@@ -38,6 +42,32 @@ class Rufo::Formatter
|
|
38
42
|
# The current hash or call or method that has hash-like parameters
|
39
43
|
@current_hash = nil
|
40
44
|
|
45
|
+
# Map lines to commands that start at the begining of a line with the following info:
|
46
|
+
# - line indent
|
47
|
+
# - first param indent
|
48
|
+
# - first line ends with '(', '[' or '{'?
|
49
|
+
# - line of matching pair of the previous item
|
50
|
+
# - last line of that call
|
51
|
+
#
|
52
|
+
# This is needed to dedent some calls that look like this:
|
53
|
+
#
|
54
|
+
# foo bar(
|
55
|
+
# 2,
|
56
|
+
# )
|
57
|
+
#
|
58
|
+
# Without the dedent it would normally look like this:
|
59
|
+
#
|
60
|
+
# foo bar(
|
61
|
+
# 2,
|
62
|
+
# )
|
63
|
+
#
|
64
|
+
# Because the formatter aligns this to the first parameter in the call.
|
65
|
+
# However, for these cases it's better to not align it like that.
|
66
|
+
@line_to_call_info = {}
|
67
|
+
|
68
|
+
# Each line that belongs to a heredoc content is put here
|
69
|
+
@heredoc_lines = {}
|
70
|
+
|
41
71
|
# Position of comments that occur at the end of a line
|
42
72
|
@comments_positions = []
|
43
73
|
|
@@ -75,11 +105,14 @@ class Rufo::Formatter
|
|
75
105
|
# Settings
|
76
106
|
indent_size options.fetch(:indent_size, 2)
|
77
107
|
space_after_hash_brace options.fetch(:space_after_hash_brace, :dynamic)
|
108
|
+
space_after_array_bracket options.fetch(:space_after_array_bracket, :never)
|
78
109
|
align_comments options.fetch(:align_comments, true)
|
79
110
|
align_assignments options.fetch(:align_assignments, false)
|
80
111
|
align_hash_keys options.fetch(:align_hash_keys, true)
|
81
112
|
align_case_when options.fetch(:align_case_when, true)
|
113
|
+
align_chained_calls options.fetch(:align_chained_calls, true)
|
82
114
|
preserve_whitespace options.fetch(:preserve_whitespace, true)
|
115
|
+
trailing_commas options.fetch(:trailing_commas, :always)
|
83
116
|
end
|
84
117
|
|
85
118
|
# The indent size (default: 2)
|
@@ -97,7 +130,21 @@ class Rufo::Formatter
|
|
97
130
|
when :dynamic, :always, :never
|
98
131
|
@space_after_hash_brace = value
|
99
132
|
else
|
100
|
-
raise ArgumentError.new("invalid value for
|
133
|
+
raise ArgumentError.new("invalid value for space_after_hash_brace: #{value}. Valid values are: :dynamic, :always, :never")
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
# Whether to put a space after an array bracket. Valid values are:
|
138
|
+
#
|
139
|
+
# * :dynamic: if there's a space, keep it. If not, don't keep it
|
140
|
+
# * :always: always put a space after an array bracket
|
141
|
+
# * :never: never put a space after an array bracket (default)
|
142
|
+
def space_after_array_bracket(value)
|
143
|
+
case value
|
144
|
+
when :dynamic, :always, :never
|
145
|
+
@space_after_array_bracket = value
|
146
|
+
else
|
147
|
+
raise ArgumentError.new("invalid value for space_after_array_bracket: #{value}. Valid values are: :dynamic, :always, :never")
|
101
148
|
end
|
102
149
|
end
|
103
150
|
|
@@ -121,6 +168,11 @@ class Rufo::Formatter
|
|
121
168
|
@align_case_when = value
|
122
169
|
end
|
123
170
|
|
171
|
+
# Whether to align chained calls to the dot (default: true)
|
172
|
+
def align_chained_calls(value)
|
173
|
+
@align_chained_calls = value
|
174
|
+
end
|
175
|
+
|
124
176
|
# Preserve whitespace after assignments target and values,
|
125
177
|
# after calls that start with a space, hash arrows and commas.
|
126
178
|
#
|
@@ -133,11 +185,26 @@ class Rufo::Formatter
|
|
133
185
|
@preserve_whitespace = value
|
134
186
|
end
|
135
187
|
|
188
|
+
# Whether to place commas at the end of a multi-line list
|
189
|
+
#
|
190
|
+
# * :dynamic: if there's a comma, keep it. If not, don't add it
|
191
|
+
# * :always: always put a comma (default)
|
192
|
+
# * :never: never put a comma
|
193
|
+
def trailing_commas(value)
|
194
|
+
case value
|
195
|
+
when :dynamic, :always, :never
|
196
|
+
@trailing_commas = value
|
197
|
+
else
|
198
|
+
raise ArgumentError.new("invalid value for trailing_commas: #{value}. Valid values are: :dynamic, :always, :never")
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
136
202
|
def format
|
137
203
|
visit @sexp
|
138
204
|
consume_end
|
139
205
|
write_line unless @last_was_newline
|
140
206
|
|
207
|
+
dedent_calls
|
141
208
|
do_align_assignments if @align_assignments
|
142
209
|
do_align_hash_keys if @align_hash_keys
|
143
210
|
do_align_case_when if @align_case_when
|
@@ -512,12 +579,18 @@ class Rufo::Formatter
|
|
512
579
|
end
|
513
580
|
|
514
581
|
def visit_string_literal_end(node)
|
582
|
+
line = @line
|
583
|
+
|
515
584
|
inner = node[1]
|
516
585
|
inner = inner[1..-1] unless node[0] == :xstring_literal
|
517
586
|
visit_exps(inner, with_lines: false)
|
518
587
|
|
519
588
|
case current_token_kind
|
520
589
|
when :on_heredoc_end
|
590
|
+
(line+1..@line).each do |i|
|
591
|
+
@heredoc_lines[i] = true
|
592
|
+
end
|
593
|
+
|
521
594
|
heredoc, tilde = @current_heredoc
|
522
595
|
if heredoc && tilde
|
523
596
|
write_indent
|
@@ -803,8 +876,8 @@ class Rufo::Formatter
|
|
803
876
|
end
|
804
877
|
|
805
878
|
def visit_call_with_receiver(node)
|
806
|
-
# [:call, obj, :".",
|
807
|
-
_, obj, text,
|
879
|
+
# [:call, obj, :".", name]
|
880
|
+
_, obj, text, name = node
|
808
881
|
|
809
882
|
@dot_column = nil
|
810
883
|
visit obj
|
@@ -814,7 +887,13 @@ class Rufo::Formatter
|
|
814
887
|
if newline? || comment?
|
815
888
|
consume_end_of_line
|
816
889
|
|
817
|
-
|
890
|
+
if @align_chained_calls
|
891
|
+
@name_dot_column = @dot_column || next_indent
|
892
|
+
write_indent(@dot_column || next_indent)
|
893
|
+
else
|
894
|
+
@name_dot_column = next_indent
|
895
|
+
write_indent(next_indent)
|
896
|
+
end
|
818
897
|
end
|
819
898
|
|
820
899
|
# Remember dot column
|
@@ -830,10 +909,10 @@ class Rufo::Formatter
|
|
830
909
|
skip_space_or_newline
|
831
910
|
end
|
832
911
|
|
833
|
-
if
|
912
|
+
if name == :call
|
834
913
|
# :call means it's .()
|
835
914
|
else
|
836
|
-
visit
|
915
|
+
visit name
|
837
916
|
end
|
838
917
|
|
839
918
|
# Only set it after we visit the call after the dot,
|
@@ -845,9 +924,7 @@ class Rufo::Formatter
|
|
845
924
|
if current_token_kind == :on_op
|
846
925
|
consume_token :on_op
|
847
926
|
else
|
848
|
-
|
849
|
-
next_token
|
850
|
-
write "."
|
927
|
+
consume_token :on_period
|
851
928
|
end
|
852
929
|
end
|
853
930
|
|
@@ -859,6 +936,7 @@ class Rufo::Formatter
|
|
859
936
|
# [:arg_paren, [:args_add_block, [[:@int, "1", [1, 6]]], false]]]
|
860
937
|
_, name, args = node
|
861
938
|
|
939
|
+
@name_dot_column = nil
|
862
940
|
visit name
|
863
941
|
|
864
942
|
# Some times a call comes without parens (should probably come as command, but well...)
|
@@ -866,8 +944,11 @@ class Rufo::Formatter
|
|
866
944
|
|
867
945
|
# Remember dot column so it's not affected by args
|
868
946
|
dot_column = @dot_column
|
947
|
+
want_indent = @name_dot_column && @name_dot_column > @indent
|
869
948
|
|
870
|
-
|
949
|
+
maybe_indent(want_indent, @name_dot_column) do
|
950
|
+
visit_call_at_paren(node, args)
|
951
|
+
end
|
871
952
|
|
872
953
|
# Restore dot column so it's not affected by args
|
873
954
|
@dot_column = dot_column
|
@@ -888,6 +969,9 @@ class Rufo::Formatter
|
|
888
969
|
skip_space
|
889
970
|
|
890
971
|
needs_trailing_newline = newline? || comment?
|
972
|
+
if needs_trailing_newline && (call_info = @line_to_call_info[@line])
|
973
|
+
call_info << true
|
974
|
+
end
|
891
975
|
|
892
976
|
push_call(node) do
|
893
977
|
visit args_node
|
@@ -898,7 +982,8 @@ class Rufo::Formatter
|
|
898
982
|
|
899
983
|
if found_comma
|
900
984
|
if needs_trailing_newline
|
901
|
-
write ","
|
985
|
+
write "," if @trailing_commas != :never
|
986
|
+
|
902
987
|
next_token
|
903
988
|
indent(next_indent) do
|
904
989
|
consume_end_of_line
|
@@ -912,7 +997,7 @@ class Rufo::Formatter
|
|
912
997
|
|
913
998
|
if newline? || comment?
|
914
999
|
if needs_trailing_newline
|
915
|
-
write ","
|
1000
|
+
write "," if @trailing_commas == :always
|
916
1001
|
|
917
1002
|
indent(next_indent) do
|
918
1003
|
consume_end_of_line
|
@@ -923,7 +1008,7 @@ class Rufo::Formatter
|
|
923
1008
|
end
|
924
1009
|
else
|
925
1010
|
if needs_trailing_newline && !found_comma
|
926
|
-
write ","
|
1011
|
+
write "," if @trailing_commas == :always
|
927
1012
|
consume_end_of_line
|
928
1013
|
write_indent
|
929
1014
|
end
|
@@ -932,6 +1017,8 @@ class Rufo::Formatter
|
|
932
1017
|
skip_space_or_newline
|
933
1018
|
end
|
934
1019
|
|
1020
|
+
call_info << @line if call_info
|
1021
|
+
|
935
1022
|
consume_token :on_rparen
|
936
1023
|
end
|
937
1024
|
|
@@ -1044,6 +1131,14 @@ class Rufo::Formatter
|
|
1044
1131
|
end
|
1045
1132
|
end
|
1046
1133
|
|
1134
|
+
call_info = @line_to_call_info[@line]
|
1135
|
+
if call_info
|
1136
|
+
call_info = nil
|
1137
|
+
else
|
1138
|
+
call_info = [@indent, @column]
|
1139
|
+
@line_to_call_info[@line] = call_info
|
1140
|
+
end
|
1141
|
+
|
1047
1142
|
indent(needed_indent) do
|
1048
1143
|
if args[0].is_a?(Symbol)
|
1049
1144
|
visit args
|
@@ -1051,6 +1146,10 @@ class Rufo::Formatter
|
|
1051
1146
|
visit_exps args, with_lines: false
|
1052
1147
|
end
|
1053
1148
|
end
|
1149
|
+
|
1150
|
+
if call_info && call_info.size > 2
|
1151
|
+
call_info << @line
|
1152
|
+
end
|
1054
1153
|
end
|
1055
1154
|
|
1056
1155
|
def visit_call_with_block(node)
|
@@ -1095,8 +1194,16 @@ class Rufo::Formatter
|
|
1095
1194
|
# Otherwise it's multiline
|
1096
1195
|
consume_token :on_lbrace
|
1097
1196
|
consume_block_args args
|
1197
|
+
|
1198
|
+
if call_info = @line_to_call_info[@line]
|
1199
|
+
call_info << true
|
1200
|
+
end
|
1201
|
+
|
1098
1202
|
indent_body body
|
1099
1203
|
write_indent
|
1204
|
+
|
1205
|
+
call_info << @line if call_info
|
1206
|
+
|
1100
1207
|
consume_token :on_rbrace
|
1101
1208
|
end
|
1102
1209
|
|
@@ -1312,27 +1419,28 @@ class Rufo::Formatter
|
|
1312
1419
|
# ]
|
1313
1420
|
_, args = node
|
1314
1421
|
|
1422
|
+
# For :mlsh_paren, sometimes a paren comes,
|
1423
|
+
# some times not, so act accordingly.
|
1424
|
+
has_paren = current_token_kind == :on_lparen
|
1425
|
+
if has_paren
|
1426
|
+
consume_token :on_lparen
|
1427
|
+
skip_space_or_newline
|
1428
|
+
end
|
1429
|
+
|
1315
1430
|
# For some reason there's nested :mlhs_paren for
|
1316
1431
|
# a single parentheses. It seems when there's
|
1317
1432
|
# a nested array we need parens, otherwise we
|
1318
1433
|
# just output whatever's inside `args`.
|
1319
1434
|
if args.is_a?(Array) && args[0].is_a?(Array)
|
1320
|
-
check :on_lparen
|
1321
|
-
write "("
|
1322
|
-
next_token
|
1323
|
-
skip_space_or_newline
|
1324
|
-
|
1325
1435
|
indent(@column) do
|
1326
1436
|
visit_comma_separated_list args
|
1327
1437
|
skip_space_or_newline
|
1328
1438
|
end
|
1329
|
-
|
1330
|
-
check :on_rparen
|
1331
|
-
write ")"
|
1332
|
-
next_token
|
1333
1439
|
else
|
1334
1440
|
visit args
|
1335
1441
|
end
|
1442
|
+
|
1443
|
+
consume_token :on_rparen if has_paren
|
1336
1444
|
end
|
1337
1445
|
|
1338
1446
|
def visit_mrhs_add_star(node)
|
@@ -1687,21 +1795,21 @@ class Rufo::Formatter
|
|
1687
1795
|
# ( exps )
|
1688
1796
|
#
|
1689
1797
|
# [:paren, exps]
|
1690
|
-
|
1691
|
-
|
1692
|
-
|
1798
|
+
_, exps = node
|
1799
|
+
|
1800
|
+
consume_token :on_lparen
|
1693
1801
|
skip_space_or_newline
|
1694
1802
|
|
1695
|
-
if
|
1696
|
-
|
1697
|
-
|
1698
|
-
|
1803
|
+
if exps
|
1804
|
+
if exps[0].is_a?(Symbol)
|
1805
|
+
visit exps
|
1806
|
+
else
|
1807
|
+
visit_exps exps, with_lines: false
|
1808
|
+
end
|
1699
1809
|
end
|
1700
1810
|
|
1701
1811
|
skip_space_or_newline
|
1702
|
-
|
1703
|
-
write ")"
|
1704
|
-
next_token
|
1812
|
+
consume_token :on_rparen
|
1705
1813
|
end
|
1706
1814
|
|
1707
1815
|
def visit_params(node)
|
@@ -1833,7 +1941,7 @@ class Rufo::Formatter
|
|
1833
1941
|
visit elements
|
1834
1942
|
skip_space_or_newline
|
1835
1943
|
else
|
1836
|
-
visit_literal_elements elements
|
1944
|
+
visit_literal_elements elements, inside_array: true
|
1837
1945
|
end
|
1838
1946
|
else
|
1839
1947
|
skip_space_or_newline
|
@@ -1853,6 +1961,7 @@ class Rufo::Formatter
|
|
1853
1961
|
elements = elements.flat_map { |x| x }
|
1854
1962
|
end
|
1855
1963
|
|
1964
|
+
has_space = current_token_value.end_with?(" ")
|
1856
1965
|
write current_token_value.strip
|
1857
1966
|
|
1858
1967
|
# If there's a newline after `%w(`, write line and indent
|
@@ -1863,7 +1972,9 @@ class Rufo::Formatter
|
|
1863
1972
|
|
1864
1973
|
next_token
|
1865
1974
|
|
1866
|
-
if elements
|
1975
|
+
if elements && !elements.empty?
|
1976
|
+
write_space if has_space
|
1977
|
+
|
1867
1978
|
elements.each_with_index do |elem, i|
|
1868
1979
|
if elem[0] == :@tstring_content
|
1869
1980
|
# elem is [:@tstring_content, string, [1, 5]
|
@@ -1903,6 +2014,8 @@ class Rufo::Formatter
|
|
1903
2014
|
if has_newline
|
1904
2015
|
write_line
|
1905
2016
|
write_indent
|
2017
|
+
elsif has_space && elements && !elements.empty?
|
2018
|
+
write_space
|
1906
2019
|
end
|
1907
2020
|
|
1908
2021
|
if last_token
|
@@ -2277,16 +2390,27 @@ class Rufo::Formatter
|
|
2277
2390
|
visit_comma_separated_list exps
|
2278
2391
|
end
|
2279
2392
|
|
2280
|
-
def visit_literal_elements(elements, inside_hash: false)
|
2393
|
+
def visit_literal_elements(elements, inside_hash: false, inside_array: false)
|
2281
2394
|
base_column = @column
|
2282
|
-
needs_final_space = inside_hash && space?
|
2395
|
+
needs_final_space = (inside_hash || inside_array) && space?
|
2283
2396
|
skip_space
|
2284
2397
|
|
2285
|
-
|
2286
|
-
|
2287
|
-
|
2288
|
-
|
2289
|
-
|
2398
|
+
if inside_hash
|
2399
|
+
case @space_after_hash_brace
|
2400
|
+
when :never
|
2401
|
+
needs_final_space = false
|
2402
|
+
when :always
|
2403
|
+
needs_final_space = true
|
2404
|
+
end
|
2405
|
+
end
|
2406
|
+
|
2407
|
+
if inside_array
|
2408
|
+
case @space_after_array_bracket
|
2409
|
+
when :never
|
2410
|
+
needs_final_space = false
|
2411
|
+
when :always
|
2412
|
+
needs_final_space = true
|
2413
|
+
end
|
2290
2414
|
end
|
2291
2415
|
|
2292
2416
|
if newline? || comment?
|
@@ -2301,6 +2425,10 @@ class Rufo::Formatter
|
|
2301
2425
|
# add a trailing comma to the last element
|
2302
2426
|
needs_trailing_comma = newline? || comment?
|
2303
2427
|
if needs_trailing_comma
|
2428
|
+
if (call_info = @line_to_call_info[@line])
|
2429
|
+
call_info << true
|
2430
|
+
end
|
2431
|
+
|
2304
2432
|
needed_indent = next_indent
|
2305
2433
|
indent { consume_end_of_line }
|
2306
2434
|
write_indent(needed_indent)
|
@@ -2309,10 +2437,12 @@ class Rufo::Formatter
|
|
2309
2437
|
end
|
2310
2438
|
|
2311
2439
|
wrote_comma = false
|
2440
|
+
last_has_comma = false
|
2312
2441
|
|
2313
2442
|
elements.each_with_index do |elem, i|
|
2314
2443
|
is_last = last?(i, elements)
|
2315
2444
|
wrote_comma = false
|
2445
|
+
last_has_comma = false
|
2316
2446
|
|
2317
2447
|
if needs_trailing_comma
|
2318
2448
|
indent(needed_indent) { visit elem }
|
@@ -2327,6 +2457,8 @@ class Rufo::Formatter
|
|
2327
2457
|
|
2328
2458
|
next unless comma?
|
2329
2459
|
|
2460
|
+
last_has_comma = true
|
2461
|
+
|
2330
2462
|
unless is_last
|
2331
2463
|
write ","
|
2332
2464
|
wrote_comma = true
|
@@ -2351,7 +2483,14 @@ class Rufo::Formatter
|
|
2351
2483
|
end
|
2352
2484
|
|
2353
2485
|
if needs_trailing_comma
|
2354
|
-
|
2486
|
+
case @trailing_commas
|
2487
|
+
when :always
|
2488
|
+
write "," unless wrote_comma
|
2489
|
+
when :never
|
2490
|
+
# Nothing
|
2491
|
+
when :dynamic
|
2492
|
+
write "," if last_has_comma && !wrote_comma
|
2493
|
+
end
|
2355
2494
|
|
2356
2495
|
consume_end_of_line
|
2357
2496
|
write_indent
|
@@ -2364,6 +2503,8 @@ class Rufo::Formatter
|
|
2364
2503
|
skip_space_or_newline
|
2365
2504
|
end
|
2366
2505
|
end
|
2506
|
+
|
2507
|
+
call_info << @line if call_info
|
2367
2508
|
end
|
2368
2509
|
|
2369
2510
|
def check_heredocs_in_literal_elements(is_last, needs_trailing_comma, wrote_comma)
|
@@ -2904,7 +3045,7 @@ class Rufo::Formatter
|
|
2904
3045
|
|
2905
3046
|
def write_space(value = " ")
|
2906
3047
|
@output << value
|
2907
|
-
@column +=
|
3048
|
+
@column += value.size
|
2908
3049
|
end
|
2909
3050
|
|
2910
3051
|
def write_line
|
@@ -3083,6 +3224,34 @@ class Rufo::Formatter
|
|
3083
3224
|
@current_hash = old_hash
|
3084
3225
|
end
|
3085
3226
|
|
3227
|
+
def dedent_calls
|
3228
|
+
return if @line_to_call_info.empty?
|
3229
|
+
|
3230
|
+
lines = @output.lines
|
3231
|
+
|
3232
|
+
while line_to_call_info = @line_to_call_info.shift
|
3233
|
+
first_line, call_info = line_to_call_info
|
3234
|
+
indent, first_param_indent, needs_dedent, first_paren_end_line, last_line = call_info
|
3235
|
+
next unless needs_dedent
|
3236
|
+
next unless first_paren_end_line == last_line
|
3237
|
+
|
3238
|
+
diff = first_param_indent - indent
|
3239
|
+
(first_line+1..last_line).each do |line|
|
3240
|
+
@line_to_call_info.delete(line)
|
3241
|
+
|
3242
|
+
next if @heredoc_lines[line]
|
3243
|
+
|
3244
|
+
current_line = lines[line]
|
3245
|
+
current_line = current_line[diff..-1]
|
3246
|
+
lines[line] = current_line
|
3247
|
+
|
3248
|
+
adjust_other_alignments nil, line, 0, -diff
|
3249
|
+
end
|
3250
|
+
end
|
3251
|
+
|
3252
|
+
@output = lines.join
|
3253
|
+
end
|
3254
|
+
|
3086
3255
|
def do_align_comments
|
3087
3256
|
do_align @comments_positions, :comment
|
3088
3257
|
end
|
data/lib/rufo/version.rb
CHANGED
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.
|
4
|
+
version: 0.0.26
|
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-
|
11
|
+
date: 2017-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|