File tree 2 files changed +7
-1
lines changed
src/compiler/crystal/tools
2 files changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -883,6 +883,8 @@ describe Crystal::Formatter do
883
883
assert_format " foo.[1]"
884
884
885
885
assert_format " @foo : Int32 # comment\n\n def foo\n end"
886
+ assert_format " getter foo # comment\n\n def foo\n end"
887
+ assert_format " getter foo : Int32 # comment\n\n def foo\n end"
886
888
887
889
assert_format " a &.b.as C" , " a &.b.as C"
888
890
assert_format " a &.b.c.as C" , " a &.b.c.as C"
Original file line number Diff line number Diff line change @@ -54,6 +54,7 @@ module Crystal
54
54
@output : IO ::Memory
55
55
@line_output : IO ::Memory
56
56
@wrote_newline : Bool
57
+ @wrote_double_newlines : Bool
57
58
@wrote_comment : Bool
58
59
@macro_state : Token ::MacroState
59
60
@inside_macro : Int32
@@ -91,6 +92,7 @@ module Crystal
91
92
@output = IO ::Memory .new(source.bytesize)
92
93
@line_output = IO ::Memory .new
93
94
@wrote_newline = false
95
+ @wrote_double_newlines = false
94
96
@wrote_comment = false
95
97
@macro_state = Token ::MacroState .default
96
98
@inside_macro = 0
@@ -257,7 +259,7 @@ module Crystal
257
259
unless found_comment
258
260
skip_space_write_line
259
261
found_comment = skip_space_or_newline last: true , at_least_one: true
260
- write_line unless found_comment
262
+ write_line unless found_comment || @wrote_double_newlines
261
263
end
262
264
else
263
265
consume_newlines
@@ -4275,6 +4277,7 @@ module Crystal
4275
4277
4276
4278
if @token .type == :NEWLINE
4277
4279
write_line
4280
+ @wrote_double_newlines = true
4278
4281
end
4279
4282
4280
4283
skip_space_or_newline
@@ -4352,6 +4355,7 @@ module Crystal
4352
4355
end
4353
4356
4354
4357
def write_line
4358
+ @wrote_double_newlines = false
4355
4359
@current_doc_comment = nil unless @wrote_comment
4356
4360
@wrote_comment = false
4357
4361
You can’t perform that action at this time.
0 commit comments