From b70e78276f9b645521395a4020610e0bfc31f342 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sun, 13 Sep 2020 18:37:28 +0200 Subject: [PATCH] Keep line breaks in UFCS chains Fixes #503. --- src/dfmt/formatter.d | 3 ++- tests/allman/issue0503.d.ref | 15 +++++++++++++++ tests/issue0503.args | 1 + tests/issue0503.d | 14 ++++++++++++++ tests/otbs/issue0503.d.ref | 12 ++++++++++++ 5 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 tests/allman/issue0503.d.ref create mode 100644 tests/issue0503.args create mode 100644 tests/issue0503.d create mode 100644 tests/otbs/issue0503.d.ref diff --git a/src/dfmt/formatter.d b/src/dfmt/formatter.d index 12bd8fe..a364831 100644 --- a/src/dfmt/formatter.d +++ b/src/dfmt/formatter.d @@ -1401,7 +1401,8 @@ private: break; case tok!".": regenLineBreakHintsIfNecessary(index); - immutable bool ufcsWrap = astInformation.ufcsHintLocations.canFindIndex(current.index); + immutable bool ufcsWrap = config.dfmt_keep_line_breaks == OptionalBoolean.f + && astInformation.ufcsHintLocations.canFindIndex(current.index); if (ufcsWrap || linebreakHints.canFind(index) || onNextLine || (linebreakHints.length == 0 && currentLineLength + nextTokenLength() > config.max_line_length)) { diff --git a/tests/allman/issue0503.d.ref b/tests/allman/issue0503.d.ref new file mode 100644 index 0000000..a939b68 --- /dev/null +++ b/tests/allman/issue0503.d.ref @@ -0,0 +1,15 @@ +string f() +{ + return duration.total!"seconds".to!string; +} + +string g() +{ + return duration.total!"seconds"().to!string; +} + +string h() +{ + return duration.total!"seconds"().to!string.to!string.to!string.to!string.to!string.to!string + .to!string.to!string.to!string; +} diff --git a/tests/issue0503.args b/tests/issue0503.args new file mode 100644 index 0000000..7e7e52d --- /dev/null +++ b/tests/issue0503.args @@ -0,0 +1 @@ +--keep_line_breaks=true diff --git a/tests/issue0503.d b/tests/issue0503.d new file mode 100644 index 0000000..1025464 --- /dev/null +++ b/tests/issue0503.d @@ -0,0 +1,14 @@ +string f() +{ + return duration.total!"seconds".to!string; +} + +string g() +{ + return duration.total!"seconds"().to!string; +} + +string h() +{ + return duration.total!"seconds"().to!string.to!string.to!string.to!string.to!string.to!string.to!string.to!string.to!string; +} diff --git a/tests/otbs/issue0503.d.ref b/tests/otbs/issue0503.d.ref new file mode 100644 index 0000000..b27874e --- /dev/null +++ b/tests/otbs/issue0503.d.ref @@ -0,0 +1,12 @@ +string f() { + return duration.total!"seconds".to!string; +} + +string g() { + return duration.total!"seconds"().to!string; +} + +string h() { + return duration.total!"seconds"().to!string.to!string.to!string.to!string.to!string.to!string + .to!string.to!string.to!string; +}