diff --git a/src/dfmt/formatter.d b/src/dfmt/formatter.d index b9afcb6..9db9259 100644 --- a/src/dfmt/formatter.d +++ b/src/dfmt/formatter.d @@ -713,13 +713,13 @@ private: { writeToken(); if (spaceAfterParens || parenDepth > 0) - write(" "); + writeSpace(); } else if ((peekIsKeyword() || peekIs(tok!"@")) && spaceAfterParens && !peekIs(tok!"in") && !peekIs(tok!"is") && !peekIs(tok!"if")) { writeToken(); - write(" "); + writeSpace(); } else writeToken(); @@ -769,14 +769,7 @@ private: || currentIs(tok!"identifier")) && !currentIsIndentedTemplateConstraint()) { - if (onNextLine) - { - newline(); - } - else - { - write(" "); - } + writeSpace(); } } @@ -805,6 +798,11 @@ private: newline(); } } + else if (indents.topIs(tok!"]")) // Associative array + { + write(config.dfmt_space_before_aa_colon ? " : " : ": "); + ++index; + } else if (peekBackIs(tok!"identifier") && [tok!"{", tok!"}", tok!";", tok!":", tok!","] .any!((ptrdiff_t token) => peekBack2Is(cast(IdType)token, true)) @@ -838,12 +836,7 @@ private: } else { - const inAA = indents.topIs(tok!"]") && indents.topDetails.breakEveryItem; - - if (inAA && !config.dfmt_space_before_aa_colon) - write(": "); - else - write(" : "); + write(" : "); index++; } } @@ -1289,14 +1282,7 @@ private: default: if (peekBackIs(tok!"identifier")) { - if (onNextLine) - { - newline(); - } - else - { - write(" "); - } + writeSpace(); } if (index + 1 < tokens.length) { @@ -1310,14 +1296,7 @@ private: writeToken(); if (!currentIsIndentedTemplateConstraint()) { - if (onNextLine) - { - newline(); - } - else - { - write(" "); - } + writeSpace(); } } } @@ -1427,7 +1406,7 @@ private: { pushWrapIndent(); newline(); - if (ufcsWrap) + if (ufcsWrap || onNextLine) regenLineBreakHints(index); } writeToken(); @@ -1943,6 +1922,18 @@ private: indents.push(type, detail); } + void writeSpace() + { + if (onNextLine) + { + newline(); + } + else + { + write(" "); + } + } + const pure @safe @nogc: size_t expressionEndIndex(size_t i, bool matchComma = false) nothrow diff --git a/tests/allman/issue0465.d.ref b/tests/allman/issue0465.d.ref new file mode 100644 index 0000000..b28f284 --- /dev/null +++ b/tests/allman/issue0465.d.ref @@ -0,0 +1,8 @@ +bool asdf(const string owner, const string mail) @safe +{ + requestHTTP(url, (scope HTTPClientRequest request) { + request.writeFormBody([owner: owner, mail: mail]); + }, (scope HTTPClientResponse response) {}); + + return true; +} diff --git a/tests/allman/issue0485.d.ref b/tests/allman/issue0485.d.ref new file mode 100644 index 0000000..037932e --- /dev/null +++ b/tests/allman/issue0485.d.ref @@ -0,0 +1,5 @@ +void main() +{ + int a; + int[int] hashmap = [a : a, a : a, a : a]; +} diff --git a/tests/allman/issue0486.d.ref b/tests/allman/issue0486.d.ref new file mode 100644 index 0000000..de7a540 --- /dev/null +++ b/tests/allman/issue0486.d.ref @@ -0,0 +1,5 @@ +void main() +{ + auto someAutoVariableName = this.firstLink.secondLink + .filter!(shouldBeProbablySomeIdentifierOrNot); +} diff --git a/tests/allman/issue0501.d.ref b/tests/allman/issue0501.d.ref new file mode 100644 index 0000000..8f1cf11 --- /dev/null +++ b/tests/allman/issue0501.d.ref @@ -0,0 +1,4 @@ +void main() +{ + auto aa = ["aaa": 1, "bbb": 2]; +} diff --git a/tests/allman/issue0504.d.ref b/tests/allman/issue0504.d.ref new file mode 100644 index 0000000..7fb4598 --- /dev/null +++ b/tests/allman/issue0504.d.ref @@ -0,0 +1,40 @@ +deprecated("foo") +void test() +{ +} + +package(foo) +void bar() +{ +} + +@uda() +void baz() +{ +} + +deprecated +deprecated_() +{ +} + +@uda +void uda_() +{ +} + +@property +void property() +{ +} + +deprecated("Reason") @uda +void propertyuda() +{ +} + +deprecated("Reason") +@uda +void udaproperty() +{ +} diff --git a/tests/issue0465.d b/tests/issue0465.d new file mode 100644 index 0000000..e3026ea --- /dev/null +++ b/tests/issue0465.d @@ -0,0 +1,9 @@ +bool asdf(const string owner, const string mail) @safe +{ + requestHTTP(url, (scope HTTPClientRequest request) { + request.writeFormBody([owner: owner, mail: + mail]); + }, (scope HTTPClientResponse response) {}); + + return true; +} diff --git a/tests/issue0485.args b/tests/issue0485.args new file mode 100644 index 0000000..1b0d2ce --- /dev/null +++ b/tests/issue0485.args @@ -0,0 +1 @@ +--space_before_aa_colon true diff --git a/tests/issue0485.d b/tests/issue0485.d new file mode 100644 index 0000000..037932e --- /dev/null +++ b/tests/issue0485.d @@ -0,0 +1,5 @@ +void main() +{ + int a; + int[int] hashmap = [a : a, a : a, a : a]; +} diff --git a/tests/issue0486.args b/tests/issue0486.args new file mode 100644 index 0000000..7e7e52d --- /dev/null +++ b/tests/issue0486.args @@ -0,0 +1 @@ +--keep_line_breaks=true diff --git a/tests/issue0486.d b/tests/issue0486.d new file mode 100644 index 0000000..de7a540 --- /dev/null +++ b/tests/issue0486.d @@ -0,0 +1,5 @@ +void main() +{ + auto someAutoVariableName = this.firstLink.secondLink + .filter!(shouldBeProbablySomeIdentifierOrNot); +} diff --git a/tests/issue0501.d b/tests/issue0501.d new file mode 100644 index 0000000..8ab0e10 --- /dev/null +++ b/tests/issue0501.d @@ -0,0 +1,4 @@ +void main() +{ + auto aa = ["aaa": 1, "bbb":2]; +} diff --git a/tests/issue0504.args b/tests/issue0504.args new file mode 100644 index 0000000..7e7e52d --- /dev/null +++ b/tests/issue0504.args @@ -0,0 +1 @@ +--keep_line_breaks=true diff --git a/tests/issue0504.d b/tests/issue0504.d new file mode 100644 index 0000000..7fb4598 --- /dev/null +++ b/tests/issue0504.d @@ -0,0 +1,40 @@ +deprecated("foo") +void test() +{ +} + +package(foo) +void bar() +{ +} + +@uda() +void baz() +{ +} + +deprecated +deprecated_() +{ +} + +@uda +void uda_() +{ +} + +@property +void property() +{ +} + +deprecated("Reason") @uda +void propertyuda() +{ +} + +deprecated("Reason") +@uda +void udaproperty() +{ +} diff --git a/tests/otbs/issue0465.d.ref b/tests/otbs/issue0465.d.ref new file mode 100644 index 0000000..e20c47f --- /dev/null +++ b/tests/otbs/issue0465.d.ref @@ -0,0 +1,7 @@ +bool asdf(const string owner, const string mail) @safe { + requestHTTP(url, (scope HTTPClientRequest request) { + request.writeFormBody([owner: owner, mail: mail]); + }, (scope HTTPClientResponse response) {}); + + return true; +} diff --git a/tests/otbs/issue0485.d.ref b/tests/otbs/issue0485.d.ref new file mode 100644 index 0000000..058d065 --- /dev/null +++ b/tests/otbs/issue0485.d.ref @@ -0,0 +1,4 @@ +void main() { + int a; + int[int] hashmap = [a : a, a : a, a : a]; +} diff --git a/tests/otbs/issue0486.d.ref b/tests/otbs/issue0486.d.ref new file mode 100644 index 0000000..5f65301 --- /dev/null +++ b/tests/otbs/issue0486.d.ref @@ -0,0 +1,4 @@ +void main() { + auto someAutoVariableName = this.firstLink.secondLink + .filter!(shouldBeProbablySomeIdentifierOrNot); +} diff --git a/tests/otbs/issue0501.d.ref b/tests/otbs/issue0501.d.ref new file mode 100644 index 0000000..675401d --- /dev/null +++ b/tests/otbs/issue0501.d.ref @@ -0,0 +1,3 @@ +void main() { + auto aa = ["aaa": 1, "bbb": 2]; +} diff --git a/tests/otbs/issue0504.d.ref b/tests/otbs/issue0504.d.ref new file mode 100644 index 0000000..94a222c --- /dev/null +++ b/tests/otbs/issue0504.d.ref @@ -0,0 +1,32 @@ +deprecated("foo") +void test() { +} + +package(foo) +void bar() { +} + +@uda() +void baz() { +} + +deprecated +deprecated_() { +} + +@uda +void uda_() { +} + +@property +void property() { +} + +deprecated("Reason") @uda +void propertyuda() { +} + +deprecated("Reason") +@uda +void udaproperty() { +}