rufo 0.0.4 → 0.0.5
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/README.md +1 -1
- data/lib/rufo/formatter.rb +30 -9
- data/lib/rufo/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4dee48483405a03bf26d15795f7d17aec4859813
|
|
4
|
+
data.tar.gz: 2003268779c62c5ba28066b176112baec2200aff
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c1199060cc3e550ab376e758d04605692dd25c295a67dc329d214a0d6055ee8eac43e6812e8b75ebcfa2021a5f8a06e31d3c06975be8ecb100867e0f30984cc9
|
|
7
|
+
data.tar.gz: '093f40f565a3d9c229ad7e467e5ba82a170844444cbdaf0d5d02795df65a1a2c9041fe7e95bb7191454bdd2895e5f1c5d2abb267df15b7aa34be6b1a5a271f77'
|
data/README.md
CHANGED
|
@@ -79,7 +79,7 @@ issue if you need something else to be configurable.
|
|
|
79
79
|
|
|
80
80
|
## Status
|
|
81
81
|
|
|
82
|
-
The
|
|
82
|
+
The formatter was tested on some big files with many Ruby
|
|
83
83
|
syntax and idioms, but since it's so new there might be some missing stuff. Don't hesitate
|
|
84
84
|
to open an issue if you find something is not working well. In any case, if the formatter
|
|
85
85
|
chokes on some valid input you will get an error prompting you to submit a bug report here :-)
|
data/lib/rufo/formatter.rb
CHANGED
|
@@ -1121,11 +1121,17 @@ class Rufo::Formatter
|
|
|
1121
1121
|
|
|
1122
1122
|
def visit_unary(node)
|
|
1123
1123
|
# [:unary, :-@, [:vcall, [:@ident, "x", [1, 2]]]]
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1124
|
+
_, op, exp = node
|
|
1125
|
+
|
|
1126
|
+
consume_op_or_keyword op
|
|
1127
|
+
|
|
1128
|
+
if op == :not
|
|
1129
|
+
consume_space
|
|
1130
|
+
else
|
|
1131
|
+
skip_space_or_newline
|
|
1132
|
+
end
|
|
1133
|
+
|
|
1134
|
+
visit exp
|
|
1129
1135
|
end
|
|
1130
1136
|
|
|
1131
1137
|
def visit_binary(node)
|
|
@@ -1140,12 +1146,20 @@ class Rufo::Formatter
|
|
|
1140
1146
|
end
|
|
1141
1147
|
skip_space
|
|
1142
1148
|
write_space " " if needs_space
|
|
1143
|
-
|
|
1144
|
-
write current_token_value
|
|
1145
|
-
next_token
|
|
1149
|
+
consume_op_or_keyword op
|
|
1146
1150
|
indent_after_space right, false, needs_space
|
|
1147
1151
|
end
|
|
1148
1152
|
|
|
1153
|
+
def consume_op_or_keyword(op)
|
|
1154
|
+
case current_token_kind
|
|
1155
|
+
when :on_op, :on_kw
|
|
1156
|
+
write current_token_value
|
|
1157
|
+
next_token
|
|
1158
|
+
else
|
|
1159
|
+
bug "Expected op or kw, not #{current_token_kind}"
|
|
1160
|
+
end
|
|
1161
|
+
end
|
|
1162
|
+
|
|
1149
1163
|
def visit_class(node)
|
|
1150
1164
|
# [:class,
|
|
1151
1165
|
# name
|
|
@@ -1413,7 +1427,8 @@ class Rufo::Formatter
|
|
|
1413
1427
|
# [:array, elements]
|
|
1414
1428
|
|
|
1415
1429
|
# Check if it's `%w(...)` or `%i(...)`
|
|
1416
|
-
|
|
1430
|
+
case current_token_kind
|
|
1431
|
+
when :on_qwords_beg, :on_qsymbols_beg, :on_words_beg, :on_symbols_beg
|
|
1417
1432
|
visit_q_or_i_array(node)
|
|
1418
1433
|
return
|
|
1419
1434
|
end
|
|
@@ -1443,6 +1458,12 @@ class Rufo::Formatter
|
|
|
1443
1458
|
def visit_q_or_i_array(node)
|
|
1444
1459
|
_, elements = node
|
|
1445
1460
|
|
|
1461
|
+
# For %W it seems elements appear inside other arrays
|
|
1462
|
+
# for some reason, so we flatten them
|
|
1463
|
+
if elements[0].is_a?(Array) && elements[0][0].is_a?(Array)
|
|
1464
|
+
elements = elements.flat_map(&:itself)
|
|
1465
|
+
end
|
|
1466
|
+
|
|
1446
1467
|
write current_token_value.strip
|
|
1447
1468
|
|
|
1448
1469
|
# If there's a newline after `%w(`, write line and indent
|
data/lib/rufo/version.rb
CHANGED