From 1f21a977137e2fabfd8d692b06a50b9b6a414908 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Tue, 9 Mar 2021 10:46:32 +0100 Subject: [PATCH] Don't indent associative array keys as labels --- src/dfmt/formatter.d | 4 ++-- tests/allman/assoc_key_indent.d.ref | 8 ++++++++ tests/assoc_key_indent.args | 1 + tests/assoc_key_indent.d | 8 ++++++++ tests/otbs/assoc_key_indent.d.ref | 7 +++++++ 5 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 tests/allman/assoc_key_indent.d.ref create mode 100644 tests/assoc_key_indent.args create mode 100644 tests/assoc_key_indent.d create mode 100644 tests/otbs/assoc_key_indent.d.ref diff --git a/src/dfmt/formatter.d b/src/dfmt/formatter.d index 696b4f8..f8883da 100644 --- a/src/dfmt/formatter.d +++ b/src/dfmt/formatter.d @@ -1694,8 +1694,8 @@ private: assert(l2 != -1, "Recent '{' is not found despite being in struct initializer"); indentLevel = l2 + 1; } - else if (config.dfmt_compact_labeled_statements == OptionalBoolean.f - || !isBlockHeader(2) || peek2Is(tok!"if")) + else if ((config.dfmt_compact_labeled_statements == OptionalBoolean.f + || !isBlockHeader(2) || peek2Is(tok!"if")) && !indents.topIs(tok!"]")) { immutable l2 = indents.indentToMostRecent(tok!"{"); indentLevel = l2 != -1 ? l2 : indents.indentLevel - 1; diff --git a/tests/allman/assoc_key_indent.d.ref b/tests/allman/assoc_key_indent.d.ref new file mode 100644 index 0000000..a357a35 --- /dev/null +++ b/tests/allman/assoc_key_indent.d.ref @@ -0,0 +1,8 @@ +void main() +{ + string key; + + int[string] var = [ + key: 5 + ]; +} diff --git a/tests/assoc_key_indent.args b/tests/assoc_key_indent.args new file mode 100644 index 0000000..7e7e52d --- /dev/null +++ b/tests/assoc_key_indent.args @@ -0,0 +1 @@ +--keep_line_breaks=true diff --git a/tests/assoc_key_indent.d b/tests/assoc_key_indent.d new file mode 100644 index 0000000..a357a35 --- /dev/null +++ b/tests/assoc_key_indent.d @@ -0,0 +1,8 @@ +void main() +{ + string key; + + int[string] var = [ + key: 5 + ]; +} diff --git a/tests/otbs/assoc_key_indent.d.ref b/tests/otbs/assoc_key_indent.d.ref new file mode 100644 index 0000000..814c7cd --- /dev/null +++ b/tests/otbs/assoc_key_indent.d.ref @@ -0,0 +1,7 @@ +void main() { + string key; + + int[string] var = [ + key: 5 + ]; +}