Skip to content

Commit ec423eb

Browse files
makenowjustRX14
authored andcommittedApr 3, 2018
Fix #5907 formatter bug (#5909)
* Fix #5907 formatter bug * Apply new formatter
1 parent 5056859 commit ec423eb

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed
 

Diff for: ‎spec/compiler/formatter/formatter_spec.cr

+1
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ describe Crystal::Formatter do
326326
assert_format "1 && 2", "1 && 2"
327327
assert_format "1 &&\n2", "1 &&\n 2"
328328
assert_format "1 &&\n2 &&\n3", "1 &&\n 2 &&\n 3"
329+
assert_format "1 && # foo\n 2 &&\n 3"
329330
assert_format "if 0\n1 &&\n2 &&\n3\nend", "if 0\n 1 &&\n 2 &&\n 3\nend"
330331
assert_format "if 1 &&\n2 &&\n3\n4\nend", "if 1 &&\n 2 &&\n 3\n 4\nend"
331332
assert_format "if 1 &&\n (2 || 3)\n 1\nelse\n 2\nend"

Diff for: ‎src/compiler/crystal/tools/formatter.cr

+2-2
Original file line numberDiff line numberDiff line change
@@ -2946,8 +2946,8 @@ module Crystal
29462946
end
29472947

29482948
write_token " ", token
2949-
skip_space
2950-
if @token.type == :NEWLINE
2949+
found_comment = skip_space
2950+
if found_comment || @token.type == :NEWLINE
29512951
if @inside_call_or_assign == 0
29522952
next_indent = @inside_cond == 0 ? @indent + 2 : @indent
29532953
else

Diff for: ‎src/float/printer/grisu3.cr

+4-4
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ module Float::Printer::Grisu3
126126
# We need to do the following tests in this order to avoid over- and
127127
# underflows.
128128
while (
129-
rest < small_distance && # Negated condition 1
130-
unsafe_interval - rest >= ten_kappa && # Negated condition 2
131-
(rest + ten_kappa < small_distance || # buffer{-1} > w_high
132-
small_distance - rest >= rest + ten_kappa - small_distance)
129+
rest < small_distance && # Negated condition 1
130+
unsafe_interval - rest >= ten_kappa && # Negated condition 2
131+
(rest + ten_kappa < small_distance || # buffer{-1} > w_high
132+
small_distance - rest >= rest + ten_kappa - small_distance)
133133
)
134134
buffer[length - 1] -= 1
135135
rest += ten_kappa

0 commit comments

Comments
 (0)