From 40085ec4ca04eaa9f9613a681bf835239f775886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Fri, 6 Jan 2023 12:33:11 +0100 Subject: [PATCH] Fix formatter comment on extra line at end of method args --- spec/compiler/formatter/formatter_spec.cr | 2 ++ src/compiler/crystal/tools/formatter.cr | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/spec/compiler/formatter/formatter_spec.cr b/spec/compiler/formatter/formatter_spec.cr index abcbac598c29..3b856225cfe7 100644 --- a/spec/compiler/formatter/formatter_spec.cr +++ b/spec/compiler/formatter/formatter_spec.cr @@ -505,6 +505,8 @@ describe Crystal::Formatter do assert_format "foo.% bar" assert_format "foo.bar(&.%(baz))" assert_format "foo.bar(&.% baz)" + assert_format "if 1\n foo(\n bar\n # comment\n )\nend" + assert_format "if 1\n foo(\n bar,\n # comment\n )\nend" assert_format "foo.bar\n.baz", "foo.bar\n .baz" assert_format "foo.bar.baz\n.qux", "foo.bar.baz\n .qux" diff --git a/src/compiler/crystal/tools/formatter.cr b/src/compiler/crystal/tools/formatter.cr index c2bc17cec2ea..ced032ee2e07 100644 --- a/src/compiler/crystal/tools/formatter.cr +++ b/src/compiler/crystal/tools/formatter.cr @@ -2766,7 +2766,7 @@ module Crystal if @token.type.newline? ends_with_newline = true end - skip_space_or_newline + indent(base_indent + 2) { skip_space_or_newline(last: true, at_least_one: ends_with_newline) } elsif has_args || node.block_arg write " " unless passed_backslash_newline skip_space @@ -2958,8 +2958,9 @@ module Crystal if @token.type.newline? && has_newlines write "," write_line - write_indent(column) skip_space_or_newline(column + 2) + write_indent(column) + skip_space_or_newline(column) else found_comment |= skip_space_or_newline(column + 2) if has_newlines