diff --git a/src/dfmt/formatter.d b/src/dfmt/formatter.d index 7003bfe..544f234 100644 --- a/src/dfmt/formatter.d +++ b/src/dfmt/formatter.d @@ -895,6 +895,20 @@ private: indents.push(tok!"if"); formatLeftBrace(); } + else if (currentIs(tok!"{") && indents.topAre(tok!"static", tok!"foreach")) + { + indents.pop(); + indents.pop(); + indents.push(tok!"foreach"); + formatLeftBrace(); + } + else if (currentIs(tok!"{") && indents.topAre(tok!"static", tok!"foreach_reverse")) + { + indents.pop(); + indents.pop(); + indents.push(tok!"foreach_reverse"); + formatLeftBrace(); + } } void formatElse() diff --git a/src/dfmt/indentation.d b/src/dfmt/indentation.d index 9c0b275..01c14bd 100644 --- a/src/dfmt/indentation.d +++ b/src/dfmt/indentation.d @@ -197,7 +197,8 @@ private: immutable currentIsNonWrapTemp = !isWrapIndent(arr[i]) && isTempIndent(arr[i]) && arr[i] != tok!")" && arr[i] != tok!"!"; if (arr[i] == tok!"static" && (arr[i + 1] == tok!"if" - || arr[i + 1] == tok!"else") && (i + 2 >= index || arr[i + 2] != tok!"{")) + || arr[i + 1] == tok!"else" || arr[i + 1] == tok!"foreach" + || arr[i + 1] == tok!"foreach_reverse") && (i + 2 >= index || arr[i + 2] != tok!"{")) { parenCount = pc; continue; diff --git a/tests/allman/issue0303.d.ref b/tests/allman/issue0303.d.ref new file mode 100644 index 0000000..9b974c5 --- /dev/null +++ b/tests/allman/issue0303.d.ref @@ -0,0 +1,12 @@ +static foreach (thing; things) +{ + doStuff(); +} +static foreach_reverse (thing; things) +{ + doStuff(); +} +static foreach (thing; things) + doStuff(); +static foreach_reverse (thing; things) + doStuff(); diff --git a/tests/issue0303.d b/tests/issue0303.d new file mode 100644 index 0000000..3a4d6b3 --- /dev/null +++ b/tests/issue0303.d @@ -0,0 +1,4 @@ +static foreach (thing; things){doStuff();} +static foreach_reverse (thing; things){doStuff();} +static foreach (thing; things) doStuff(); +static foreach_reverse (thing; things) doStuff(); \ No newline at end of file diff --git a/tests/otbs/issue0303.d.ref b/tests/otbs/issue0303.d.ref new file mode 100644 index 0000000..878435f --- /dev/null +++ b/tests/otbs/issue0303.d.ref @@ -0,0 +1,10 @@ +static foreach (thing; things) { + doStuff(); +} +static foreach_reverse (thing; things) { + doStuff(); +} +static foreach (thing; things) + doStuff(); +static foreach_reverse (thing; things) + doStuff();