From e0549070a1069d6d81a9dfd1a9c177a4e8e231c2 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Thu, 10 Jun 2021 20:23:07 +0200 Subject: [PATCH] Fix double array indentation inside parens --- src/dfmt/formatter.d | 4 ++ tests/allman/array_access.d.ref | 6 +-- tests/allman/associative_array.d.ref | 36 +++++++++--------- tests/allman/associative_array_complex.d.ref | 40 ++++++++++---------- tests/otbs/array_access.d.ref | 6 +-- tests/otbs/associative_array.d.ref | 36 +++++++++--------- tests/otbs/associative_array_complex.d.ref | 40 ++++++++++---------- 7 files changed, 86 insertions(+), 82 deletions(-) diff --git a/src/dfmt/formatter.d b/src/dfmt/formatter.d index f8883da..0a355db 100644 --- a/src/dfmt/formatter.d +++ b/src/dfmt/formatter.d @@ -629,6 +629,10 @@ private: } else if (arrayInitializerStart && isMultilineAt(index - 1)) { + if (peekBack2Is(tok!"(")) { + indents.pop(); + } + // Use the close bracket as the indent token to distinguish // the array initialiazer from an array index in the newline // handling code diff --git a/tests/allman/array_access.d.ref b/tests/allman/array_access.d.ref index 7c7a6cc..b09ebfe 100644 --- a/tests/allman/array_access.d.ref +++ b/tests/allman/array_access.d.ref @@ -1,7 +1,7 @@ unittest { foo([ - target.value.region[1], target.value.region[1], - target.value.region[1], target.value.region[1], target.value.region[1] - ]); + target.value.region[1], target.value.region[1], target.value.region[1], + target.value.region[1], target.value.region[1] + ]); } diff --git a/tests/allman/associative_array.d.ref b/tests/allman/associative_array.d.ref index d1db193..b0e671b 100644 --- a/tests/allman/associative_array.d.ref +++ b/tests/allman/associative_array.d.ref @@ -1,24 +1,24 @@ unittest { Bson base = Bson([ - "maps": Bson([ - Bson(["id": Bson(4), "comment": Bson("hello")]), - Bson(["id": Bson(49), "comment": Bson(null)]) - ]), - "short": Bson(["a": "b", "c": "d"]), - "numbers": Bson([ - 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 - ]), - "shuffleOnReset": serializeToBson([ - "all": false, - "selected": true, - "maybe": false - ]), - "resetOnEmpty": Bson(false), - "applyMods": Bson(true), - "sendComments": Bson(true) - ]); + "maps": Bson([ + Bson(["id": Bson(4), "comment": Bson("hello")]), + Bson(["id": Bson(49), "comment": Bson(null)]) + ]), + "short": Bson(["a": "b", "c": "d"]), + "numbers": Bson([ + 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, + 3, 4, 5, 6, 7, 8, 9, 0 + ]), + "shuffleOnReset": serializeToBson([ + "all": false, + "selected": true, + "maybe": false + ]), + "resetOnEmpty": Bson(false), + "applyMods": Bson(true), + "sendComments": Bson(true) + ]); int[] x = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 diff --git a/tests/allman/associative_array_complex.d.ref b/tests/allman/associative_array_complex.d.ref index c7b803b..f637ca3 100644 --- a/tests/allman/associative_array_complex.d.ref +++ b/tests/allman/associative_array_complex.d.ref @@ -1,25 +1,25 @@ auto find() { return Map.findRange([ - "$and": [ - ["deleted": Bson(false)], - [ - "$or": Bson([ - serializeToBson(["forceUpdate": Bson(true)]), - serializeToBson([ - "info.approved": ["$eq": Bson(1)], - "fetchDate": [ - "$lte": Bson(BsonDate(currentTime - 60.days)) - ] - ]), - serializeToBson([ - "info.approved": ["$ne": Bson(1)], - "fetchDate": [ - "$lte": Bson(BsonDate(currentTime - 14.days)) - ] - ]) - ]) - ] + "$and": [ + ["deleted": Bson(false)], + [ + "$or": Bson([ + serializeToBson(["forceUpdate": Bson(true)]), + serializeToBson([ + "info.approved": ["$eq": Bson(1)], + "fetchDate": [ + "$lte": Bson(BsonDate(currentTime - 60.days)) + ] + ]), + serializeToBson([ + "info.approved": ["$ne": Bson(1)], + "fetchDate": [ + "$lte": Bson(BsonDate(currentTime - 14.days)) + ] + ]) + ]) ] - ]); + ] + ]); } diff --git a/tests/otbs/array_access.d.ref b/tests/otbs/array_access.d.ref index 7a2ac55..cf66c3d 100644 --- a/tests/otbs/array_access.d.ref +++ b/tests/otbs/array_access.d.ref @@ -1,6 +1,6 @@ unittest { foo([ - target.value.region[1], target.value.region[1], - target.value.region[1], target.value.region[1], target.value.region[1] - ]); + target.value.region[1], target.value.region[1], target.value.region[1], + target.value.region[1], target.value.region[1] + ]); } diff --git a/tests/otbs/associative_array.d.ref b/tests/otbs/associative_array.d.ref index 39f18c6..48442a3 100644 --- a/tests/otbs/associative_array.d.ref +++ b/tests/otbs/associative_array.d.ref @@ -1,23 +1,23 @@ unittest { Bson base = Bson([ - "maps": Bson([ - Bson(["id": Bson(4), "comment": Bson("hello")]), - Bson(["id": Bson(49), "comment": Bson(null)]) - ]), - "short": Bson(["a": "b", "c": "d"]), - "numbers": Bson([ - 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 - ]), - "shuffleOnReset": serializeToBson([ - "all": false, - "selected": true, - "maybe": false - ]), - "resetOnEmpty": Bson(false), - "applyMods": Bson(true), - "sendComments": Bson(true) - ]); + "maps": Bson([ + Bson(["id": Bson(4), "comment": Bson("hello")]), + Bson(["id": Bson(49), "comment": Bson(null)]) + ]), + "short": Bson(["a": "b", "c": "d"]), + "numbers": Bson([ + 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, + 3, 4, 5, 6, 7, 8, 9, 0 + ]), + "shuffleOnReset": serializeToBson([ + "all": false, + "selected": true, + "maybe": false + ]), + "resetOnEmpty": Bson(false), + "applyMods": Bson(true), + "sendComments": Bson(true) + ]); int[] x = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 diff --git a/tests/otbs/associative_array_complex.d.ref b/tests/otbs/associative_array_complex.d.ref index ddcbcd7..c3c9d00 100644 --- a/tests/otbs/associative_array_complex.d.ref +++ b/tests/otbs/associative_array_complex.d.ref @@ -1,24 +1,24 @@ auto find() { return Map.findRange([ - "$and": [ - ["deleted": Bson(false)], - [ - "$or": Bson([ - serializeToBson(["forceUpdate": Bson(true)]), - serializeToBson([ - "info.approved": ["$eq": Bson(1)], - "fetchDate": [ - "$lte": Bson(BsonDate(currentTime - 60.days)) - ] - ]), - serializeToBson([ - "info.approved": ["$ne": Bson(1)], - "fetchDate": [ - "$lte": Bson(BsonDate(currentTime - 14.days)) - ] - ]) - ]) - ] + "$and": [ + ["deleted": Bson(false)], + [ + "$or": Bson([ + serializeToBson(["forceUpdate": Bson(true)]), + serializeToBson([ + "info.approved": ["$eq": Bson(1)], + "fetchDate": [ + "$lte": Bson(BsonDate(currentTime - 60.days)) + ] + ]), + serializeToBson([ + "info.approved": ["$ne": Bson(1)], + "fetchDate": [ + "$lte": Bson(BsonDate(currentTime - 14.days)) + ] + ]) + ]) ] - ]); + ] + ]); }