This commit is contained in:
Hackerpilot 2015-04-20 00:56:24 -07:00
parent bcc4adb7cc
commit 700aaff7da
6 changed files with 76 additions and 24 deletions

View File

@ -599,7 +599,7 @@ private:
void formatSwitch()
{
if (indents.topIs(tok!"with"))
while (indents.topIs(tok!"with"))
indents.pop();
indents.push(tok!"switch");
writeToken(); // switch
@ -847,15 +847,35 @@ private:
case tok!"..":
case tok!"%":
binary:
if (linebreakHints.canFind(index) || peekIs(tok!"comment", false))
immutable bool isWrapToken = linebreakHints.canFind(index) || peekIs(tok!"comment", false);
if (config.dfmt_split_operator_at_line_end)
{
pushWrapIndent();
newline();
if (isWrapToken)
{
pushWrapIndent();
write(" ");
writeToken();
newline();
}
else
{
write(" ");
writeToken();
write(" ");
}
}
else
{
if (isWrapToken)
{
pushWrapIndent();
newline();
}
else
write(" ");
writeToken();
write(" ");
writeToken();
write(" ");
}
break;
default:
writeToken();

View File

@ -16,7 +16,7 @@ else
import dfmt.formatter : format;
import std.path : buildPath, expandTilde;
import dfmt.editorconfig : getConfigFor;
import std.getopt : getopt;
import std.getopt : getopt, GetOptException;
int main(string[] args)
{
@ -28,10 +28,13 @@ else
void handleBooleans(string option, string value)
{
import dfmt.editorconfig : OptionalBoolean;
import std.exception : enforce;
enforce(value == "true" || value == "false", "Invalid argument");
import std.exception : enforceEx;
enforceEx!GetOptException(value == "true" || value == "false", "Invalid argument");
switch (option)
{
case "align_switch_statements":
optConfig.dfmt_align_switch_statements = value == "true" ? OptionalBoolean.t : OptionalBoolean.f;
break;
case "outdent_attributes":
optConfig.dfmt_outdent_attributes = value == "true" ? OptionalBoolean.t : OptionalBoolean.f;
break;
@ -48,21 +51,29 @@ else
}
}
getopt(args,
"align_switch_statements", &optConfig.dfmt_align_switch_statements,
"brace_style", &optConfig.dfmt_brace_style,
"end_of_line", &optConfig.end_of_line,
"help|h", &showHelp,
"indent_size", &optConfig.indent_size,
"indent_style|t", &optConfig.indent_style,
"inplace", &inplace,
"max_line_length", &optConfig.max_line_length,
"max_line_length", &optConfig.max_line_length,
"outdent_attributes", &handleBooleans,
"outdent_labels", &handleBooleans,
"space_after_cast", &handleBooleans,
"split_operator_at_line_end", &handleBooleans,
"tab_width", &optConfig.tab_width);
try
{
getopt(args,
"align_switch_statements", &handleBooleans,
"brace_style", &optConfig.dfmt_brace_style,
"end_of_line", &optConfig.end_of_line,
"help|h", &showHelp,
"indent_size", &optConfig.indent_size,
"indent_style|t", &optConfig.indent_style,
"inplace", &inplace,
"max_line_length", &optConfig.max_line_length,
"max_line_length", &optConfig.max_line_length,
"outdent_attributes", &handleBooleans,
"outdent_labels", &handleBooleans,
"space_after_cast", &handleBooleans,
"split_operator_at_line_end", &handleBooleans,
"tab_width", &optConfig.tab_width);
}
catch (GetOptException e)
{
stderr.writeln(e.msg);
return 1;
}
if (showHelp)
{

View File

@ -0,0 +1,7 @@
unittest
{
if (some_very_long_expression && some_very_long_expression &&
some_very_long_expression && some_very_long_expression && some_very_long_expression)
{
}
}

1
tests/issue0035.args Normal file
View File

@ -0,0 +1 @@
--split_operator_at_line_end=true

8
tests/issue0035.d Normal file
View File

@ -0,0 +1,8 @@
unittest
{
if (some_very_long_expression && some_very_long_expression
&& some_very_long_expression && some_very_long_expression
&& some_very_long_expression)
{
}
}

View File

@ -0,0 +1,5 @@
unittest {
if (some_very_long_expression && some_very_long_expression &&
some_very_long_expression && some_very_long_expression && some_very_long_expression) {
}
}