From 00fda4f5eb2a009287909080ec6cca31db32c6c7 Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Wed, 25 Oct 2017 13:26:35 -0700 Subject: [PATCH] Fix #248 --- src/dfmt/formatter.d | 14 ++++++++++++-- tests/allman/issue0248.d.ref | 11 +++++++++++ tests/issue0248.d | 11 +++++++++++ tests/otbs/issue0248.d.ref | 9 +++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 tests/allman/issue0248.d.ref create mode 100644 tests/issue0248.d create mode 100644 tests/otbs/issue0248.d.ref diff --git a/src/dfmt/formatter.d b/src/dfmt/formatter.d index cd4ec83..c80b9a1 100644 --- a/src/dfmt/formatter.d +++ b/src/dfmt/formatter.d @@ -595,7 +595,8 @@ private: } else if (index < tokens.length && (currentIs(tok!"@") || isBasicType(tokens[index].type) - || currentIs(tok!"identifier") || currentIs(tok!"if"))) + || currentIs(tok!"identifier") || currentIs(tok!"if")) + && !currentIsIndentedTemplateConstraint()) write(" "); } @@ -1021,7 +1022,8 @@ private: else { writeToken(); - write(" "); + if (!currentIsIndentedTemplateConstraint()) + write(" "); } } else @@ -1030,6 +1032,14 @@ private: } } + bool currentIsIndentedTemplateConstraint() + { + return index < tokens.length + && astInformation.constraintLocations.canFindIndex(current.index) + && (config.dfmt_template_constraint_style == TemplateConstraintStyle.always_newline + || currentLineLength >= config.dfmt_soft_max_line_length); + } + void formatOperator() { import std.algorithm : canFind; diff --git a/tests/allman/issue0248.d.ref b/tests/allman/issue0248.d.ref new file mode 100644 index 0000000..457d138 --- /dev/null +++ b/tests/allman/issue0248.d.ref @@ -0,0 +1,11 @@ +T[] arrayOp(T, Args...)(T res, Filter!(isType, Args) args) @trusted @nogc pure @things + if (Args[$ - 1] != "=") +{ + +} + +T[] arrayOp(T, Args...)(T res, Filter!(isType, Args) args) @trusted @nogc pure nothrow + if (Args[$ - 1] != "=") +{ + +} diff --git a/tests/issue0248.d b/tests/issue0248.d new file mode 100644 index 0000000..91f60b7 --- /dev/null +++ b/tests/issue0248.d @@ -0,0 +1,11 @@ +T[] arrayOp(T, Args...)(T res, Filter!(isType, Args) args) @trusted @nogc pure @things + if (Args[$ - 1] != "=") +{ + +} + +T[] arrayOp(T, Args...)(T res, Filter!(isType, Args) args) @trusted @nogc pure nothrow + if (Args[$ - 1] != "=") +{ + +} diff --git a/tests/otbs/issue0248.d.ref b/tests/otbs/issue0248.d.ref new file mode 100644 index 0000000..1d93ce2 --- /dev/null +++ b/tests/otbs/issue0248.d.ref @@ -0,0 +1,9 @@ +T[] arrayOp(T, Args...)(T res, Filter!(isType, Args) args) @trusted @nogc pure @things + if (Args[$ - 1] != "=") { + +} + +T[] arrayOp(T, Args...)(T res, Filter!(isType, Args) args) @trusted @nogc pure nothrow + if (Args[$ - 1] != "=") { + +}