diff --git a/src/dfmt/formatter.d b/src/dfmt/formatter.d index 97b33c8..05b18b3 100644 --- a/src/dfmt/formatter.d +++ b/src/dfmt/formatter.d @@ -387,7 +387,8 @@ private: break; else if (t == tok!"import" && !currentIs(tok!"import") && !currentIs(tok!"}") && !(currentIs(tok!"public") - && peekIs(tok!"import"))) + && peekIs(tok!"import")) + && !indents.topIsOneOf(tok!"if", tok!"debug", tok!"version")) { simpleNewline(); currentLineLength = 0; @@ -481,7 +482,8 @@ private: if (parenDepth == 0) indents.popWrapIndents(); - if (parenDepth == 0 && (peekIs(tok!"is") || peekIs(tok!"in") || peekIs(tok!"out") || peekIs(tok!"body"))) + if (parenDepth == 0 && (peekIs(tok!"is") || peekIs(tok!"in") + || peekIs(tok!"out") || peekIs(tok!"body"))) writeToken(); else if (peekIsLiteralOrIdent() || peekIsBasicType()) { @@ -489,7 +491,8 @@ private: if (spaceAfterParens || parenDepth > 0) write(" "); } - else if ((peekIsKeyword() || peekIs(tok!"@")) && spaceAfterParens && !peekIs(tok!"in") && !peekIs(tok!"is")) + else if ((peekIsKeyword() || peekIs(tok!"@")) && spaceAfterParens + && !peekIs(tok!"in") && !peekIs(tok!"is")) { writeToken(); write(" "); @@ -762,7 +765,8 @@ private: || astInformation.conditionalWithElseLocations.canFindIndex(current.index); immutable bool c = b || astInformation.conditionalStatementLocations.canFindIndex(current.index); - immutable bool shouldPushIndent = c && !(currentIs(tok!"if") && indents.topIsWrap()); + immutable bool shouldPushIndent = (c || peekBackIs(tok!"else")) + && !(currentIs(tok!"if") && indents.topIsWrap()); if (currentIs(tok!"out") && !peekBackIs(tok!"}")) newline(); if (shouldPushIndent) @@ -863,8 +867,8 @@ private: write(" "); break; case tok!"is": - if (!peekBackIsOneOf(false, tok!"!", tok!"(", - tok!",", tok!"}", tok!"=", tok!"&&", tok!"||") && !peekBackIsKeyword()) + if (!peekBackIsOneOf(false, tok!"!", tok!"(", tok!",", + tok!"}", tok!"=", tok!"&&", tok!"||") && !peekBackIsKeyword()) write(" "); writeToken(); if (!currentIs(tok!"(") && !currentIs(tok!"{")) @@ -1223,8 +1227,8 @@ private: } immutable l = indents.indentToMostRecent(tok!"switch"); if (l != -1) - indentLevel = config.dfmt_align_switch_statements == OptionalBoolean.t - ? l : indents.indentLevel; + indentLevel = config.dfmt_align_switch_statements + == OptionalBoolean.t ? l : indents.indentLevel; } else if (currentIs(tok!"{")) { diff --git a/tests/allman/issue0213.d.ref b/tests/allman/issue0213.d.ref new file mode 100644 index 0000000..b32eda7 --- /dev/null +++ b/tests/allman/issue0213.d.ref @@ -0,0 +1,6 @@ +version (linux) + import core.sys.linux.elf; +else version (FreeBSD) + import core.sys.freebsd.sys.elf; +else version (Solaris) + import core.sys.solaris.elf; diff --git a/tests/issue0213.d b/tests/issue0213.d new file mode 100644 index 0000000..b2e172d --- /dev/null +++ b/tests/issue0213.d @@ -0,0 +1,6 @@ +version (linux) + import core.sys.linux.elf; +else version (FreeBSD) + import core.sys.freebsd.sys.elf; +else version (Solaris) + import core.sys.solaris.elf; diff --git a/tests/otbs/issue0213.d.ref b/tests/otbs/issue0213.d.ref new file mode 100644 index 0000000..b32eda7 --- /dev/null +++ b/tests/otbs/issue0213.d.ref @@ -0,0 +1,6 @@ +version (linux) + import core.sys.linux.elf; +else version (FreeBSD) + import core.sys.freebsd.sys.elf; +else version (Solaris) + import core.sys.solaris.elf;