From 886903f8eaf78d6e9e68dc04669206535fab8d8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20Tr=C3=A9guier?= Date: Sun, 7 Oct 2018 12:13:19 +0200 Subject: [PATCH] Fix #246 - Questionable indentation for multiple `with` statements --- src/dfmt/formatter.d | 2 +- tests/allman/issue0246.d.ref | 23 +++++++++++++++++++++++ tests/issue0246.d | 24 ++++++++++++++++++++++++ tests/otbs/issue0246.d.ref | 17 +++++++++++++++++ 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 tests/allman/issue0246.d.ref create mode 100644 tests/issue0246.d create mode 100644 tests/otbs/issue0246.d.ref diff --git a/src/dfmt/formatter.d b/src/dfmt/formatter.d index 2730f68..159060c 100644 --- a/src/dfmt/formatter.d +++ b/src/dfmt/formatter.d @@ -207,7 +207,7 @@ private: } else if (currentIs(tok!"with")) { - if (indents.length == 0 || indents.top != tok!"switch") + if (indents.length == 0 || (indents.top != tok!"switch" && indents.top != tok!"with")) indents.push(tok!"with"); writeToken(); write(" "); diff --git a/tests/allman/issue0246.d.ref b/tests/allman/issue0246.d.ref new file mode 100644 index 0000000..5d66aba --- /dev/null +++ b/tests/allman/issue0246.d.ref @@ -0,0 +1,23 @@ +unittest +{ + with (Object) + { + // do something + } + with (Object) with (Object) + { + // do something + } + with (Object) with (Object) with (Object) + { + // do something + } + + with (Object) + { + with (Object) + { + // do something + } + } +} diff --git a/tests/issue0246.d b/tests/issue0246.d new file mode 100644 index 0000000..26d8c69 --- /dev/null +++ b/tests/issue0246.d @@ -0,0 +1,24 @@ +unittest +{ + with (Object) + { + // do something + } + with (Object) with (Object) +{ +// do something +} + with (Object) with (Object) + with (Object) + { + // do something + } + + with (Object) + { + with (Object) + { +// do something + } + } +} diff --git a/tests/otbs/issue0246.d.ref b/tests/otbs/issue0246.d.ref new file mode 100644 index 0000000..3637e2f --- /dev/null +++ b/tests/otbs/issue0246.d.ref @@ -0,0 +1,17 @@ +unittest { + with (Object) { + // do something + } + with (Object) with (Object) { + // do something + } + with (Object) with (Object) with (Object) { + // do something + } + + with (Object) { + with (Object) { + // do something + } + } +}