Skip to content

Commit

Permalink
Merge pull request #398 from LaurentTreguier/issue-345
Browse files Browse the repository at this point in the history
Fix #345 -  Case of trailing white space
merged-on-behalf-of: BBasile <BBasile@users.noreply.github.com>
  • Loading branch information
dlang-bot authored Oct 10, 2018
2 parents 810e4b4 + b928eb6 commit 18eea57
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 8 deletions.
9 changes: 5 additions & 4 deletions src/dfmt/formatter.d
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ private:
|| peekBack2Is(tok!")")
|| peekBack2Is(tok!"]") )
&& currentIs(tok!("(") )
|| isBasicType(current.type) || currentIs(tok!"@") || currentIs(tok!"if")
|| isBasicType(current.type) || currentIs(tok!"@")
|| isNumberLiteral(tokens[index].type)
|| (inAsm && peekBack2Is(tok!";") && currentIs(tok!"["))
)))
Expand Down Expand Up @@ -337,7 +337,7 @@ private:
immutable l = currentLineLength + betweenParenLength(tokens[index + 1 .. $]);
if (l > config.dfmt_soft_max_line_length)
newline();
else if (peekBackIs(tok!")"))
else if (peekBackIs(tok!")") || peekBackIs(tok!"identifier"))
write(" ");
break;
case always_newline:
Expand All @@ -351,7 +351,7 @@ private:
pushWrapIndent() : pushWrapIndent(tok!"!");
newline();
}
else if (peekBackIs(tok!")"))
else if (peekBackIs(tok!")") || peekBackIs(tok!"identifier"))
write(" ");
break;
case always_newline_indent:
Expand Down Expand Up @@ -646,7 +646,7 @@ private:
}
else if (index < tokens.length && (currentIs(tok!"@")
|| isBasicType(tokens[index].type)
|| currentIs(tok!"identifier") || currentIs(tok!"if"))
|| currentIs(tok!"identifier"))
&& !currentIsIndentedTemplateConstraint())
write(" ");
}
Expand Down Expand Up @@ -1161,6 +1161,7 @@ private:
return index < tokens.length
&& astInformation.constraintLocations.canFindIndex(current.index)
&& (config.dfmt_template_constraint_style == TemplateConstraintStyle.always_newline
|| config.dfmt_template_constraint_style == TemplateConstraintStyle.always_newline_indent
|| currentLineLength >= config.dfmt_soft_max_line_length);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/allman/attribute_constraint.d.ref
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ struct SomeStructName
{
static if (condition)
{
void longFunctionName(AAAAAAAA)(AAAAAAAA a) @property
void longFunctionName(AAAAAAAA)(AAAAAAAA a) @property
if (someThingsAreTrue!AAAAAAAA && long_condition
&& is(elaborate == expression))
{
Expand Down
2 changes: 1 addition & 1 deletion tests/allman/issue0153.d.ref
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Foo(T) : FirstInterfaceWithVeryLongName, SecondInterfaceWithVeryLongName
class Foo(T) : FirstInterfaceWithVeryLongName, SecondInterfaceWithVeryLongName
if (is(T : Bar))
{
void foo()
Expand Down
4 changes: 4 additions & 0 deletions tests/allman/issue0345.d.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Bar(A) : Foo
if (isFloating!A)
{
}
1 change: 1 addition & 0 deletions tests/issue0345.args
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--template_constraint_style=always_newline
1 change: 1 addition & 0 deletions tests/issue0345.d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class Bar(A) : Foo if (isFloating!A){}
2 changes: 1 addition & 1 deletion tests/otbs/attribute_constraint.d.ref
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ struct SomeStructName {
static struct InnerStruct {
version (linux) {
static if (condition) {
void longFunctionName(AAAAAAAA)(AAAAAAAA a) @property
void longFunctionName(AAAAAAAA)(AAAAAAAA a) @property
if (someThingsAreTrue!AAAAAAAA && long_condition
&& is(elaborate == expression)) {
}
Expand Down
2 changes: 1 addition & 1 deletion tests/otbs/issue0153.d.ref
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Foo(T) : FirstInterfaceWithVeryLongName, SecondInterfaceWithVeryLongName
class Foo(T) : FirstInterfaceWithVeryLongName, SecondInterfaceWithVeryLongName
if (is(T : Bar)) {
void foo() {
}
Expand Down
3 changes: 3 additions & 0 deletions tests/otbs/issue0345.d.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Bar(A) : Foo
if (isFloating!A) {
}

0 comments on commit 18eea57

Please sign in to comment.