From 69bd684b444276070c6e3b8225ef5469e416f22e Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Tue, 9 Jun 2020 17:09:29 -0700 Subject: [PATCH] Fix #490 --- src/dfmt/formatter.d | 8 ++++---- tests/allman/issue0490.d.ref | 6 ++++++ tests/issue0490.args | 1 + tests/issue0490.d | 6 ++++++ tests/otbs/issue0490.d.ref | 5 +++++ 5 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 tests/allman/issue0490.d.ref create mode 100644 tests/issue0490.args create mode 100644 tests/issue0490.d create mode 100644 tests/otbs/issue0490.d.ref diff --git a/src/dfmt/formatter.d b/src/dfmt/formatter.d index 6f9b7cc..c922c5f 100644 --- a/src/dfmt/formatter.d +++ b/src/dfmt/formatter.d @@ -9,8 +9,9 @@ module dfmt.formatter; import dparse.lexer; import dparse.parser; import dparse.rollback_allocator; -import dfmt.config; import dfmt.ast_info; +import dfmt.config; +import dfmt.editorconfig : OptionalBoolean; import dfmt.indentation; import dfmt.tokens; import dfmt.wrapping; @@ -477,7 +478,8 @@ private: immutable j = justAddedExtraNewline; if (currIsSlashSlash) { - newline(); + if (config.dfmt_keep_line_breaks != OptionalBoolean.t) + newline(); justAddedExtraNewline = j; } else if (hasCurrent) @@ -584,8 +586,6 @@ private: } do { - import dfmt.editorconfig : OptionalBoolean; - immutable p = current.type; regenLineBreakHintsIfNecessary(index); writeToken(); diff --git a/tests/allman/issue0490.d.ref b/tests/allman/issue0490.d.ref new file mode 100644 index 0000000..0a25298 --- /dev/null +++ b/tests/allman/issue0490.d.ref @@ -0,0 +1,6 @@ +void foo() +{ + afdsafds + .asdf // blah + .flub; +} diff --git a/tests/issue0490.args b/tests/issue0490.args new file mode 100644 index 0000000..7e7e52d --- /dev/null +++ b/tests/issue0490.args @@ -0,0 +1 @@ +--keep_line_breaks=true diff --git a/tests/issue0490.d b/tests/issue0490.d new file mode 100644 index 0000000..0a25298 --- /dev/null +++ b/tests/issue0490.d @@ -0,0 +1,6 @@ +void foo() +{ + afdsafds + .asdf // blah + .flub; +} diff --git a/tests/otbs/issue0490.d.ref b/tests/otbs/issue0490.d.ref new file mode 100644 index 0000000..7332368 --- /dev/null +++ b/tests/otbs/issue0490.d.ref @@ -0,0 +1,5 @@ +void foo() { + afdsafds + .asdf // blah + .flub; +}