diff --git a/README.md b/README.md index 9d357d9..4a2d909 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,8 @@ found there. * `--tab_width`: *see tab_width [below](#standard-editorconfig-properties)* * `--template_constraint_style`: *see dfmt_template_constraint_style [below](#dfmt-specific-properties)* * `--keep_line_breaks`: *see dfmt_keep_line_breaks [below](#dfmt-specific-properties)* +* `--single_indent`: *see dfmt_single_indent [below](#dfmt-specific-properties)* +* `--reflow_property_chains`: *see dfmt_property_chains [below](#dfmt-specific-properties)* ### Example ``` @@ -117,6 +119,7 @@ dfmt_single_template_constraint_indent | `true`, **`false`** | Set if the constr dfmt_space_before_aa_colon | `true`, **`false`** | Adds a space after an associative array key before the `:` like in older dfmt versions. dfmt_keep_line_breaks | `true`, **`false`** | Keep existing line breaks if these don't violate other formatting rules. dfmt_single_indent | `true`, **`false`** | Set if the code in parens is indented by a single tab instead of two. +dfmt_reflow_property_chains | **`true`**, `false` | Recalculate the splitting of property chains into multiple lines. ## Terminology * Braces - `{` and `}` diff --git a/src/dfmt/config.d b/src/dfmt/config.d index d6f31b7..ce0fbd5 100644 --- a/src/dfmt/config.d +++ b/src/dfmt/config.d @@ -63,6 +63,8 @@ struct Config OptionalBoolean dfmt_keep_line_breaks; /// OptionalBoolean dfmt_single_indent; + /// + OptionalBoolean dfmt_reflow_property_chains; mixin StandardEditorConfigFields; @@ -93,6 +95,7 @@ struct Config dfmt_space_before_aa_colon = OptionalBoolean.f; dfmt_keep_line_breaks = OptionalBoolean.f; dfmt_single_indent = OptionalBoolean.f; + dfmt_reflow_property_chains = OptionalBoolean.t; } /** diff --git a/src/dfmt/formatter.d b/src/dfmt/formatter.d index 34d5eaf..2078a7c 100644 --- a/src/dfmt/formatter.d +++ b/src/dfmt/formatter.d @@ -1458,7 +1458,8 @@ private: break; case tok!".": regenLineBreakHintsIfNecessary(index); - immutable bool ufcsWrap = astInformation.ufcsHintLocations.canFindIndex(current.index); + immutable bool ufcsWrap = config.dfmt_reflow_property_chains == OptionalBoolean.t + && astInformation.ufcsHintLocations.canFindIndex(current.index); if (ufcsWrap || linebreakHints.canFind(index) || onNextLine || (linebreakHints.length == 0 && currentLineLength + nextTokenLength() > config.max_line_length)) { diff --git a/src/dfmt/main.d b/src/dfmt/main.d index ccf407b..a332a93 100644 --- a/src/dfmt/main.d +++ b/src/dfmt/main.d @@ -98,6 +98,9 @@ else case "single_indent": optConfig.dfmt_single_indent = optVal; break; + case "reflow_property_chains": + optConfig.dfmt_reflow_property_chains = optVal; + break; default: assert(false, "Invalid command-line switch"); } @@ -129,7 +132,8 @@ else "tab_width", &optConfig.tab_width, "template_constraint_style", &optConfig.dfmt_template_constraint_style, "keep_line_breaks", &handleBooleans, - "single_indent", &handleBooleans); + "single_indent", &handleBooleans, + "reflow_property_chains", &handleBooleans); // dfmt on } catch (GetOptException e) @@ -341,6 +345,7 @@ Formatting Options: --template_constraint_style --space_before_aa_colon --single_indent + --reflow_property_chains `, optionsToString!(typeof(Config.dfmt_template_constraint_style))); } diff --git a/tests/allman/issue0503.d.ref b/tests/allman/issue0503.d.ref new file mode 100644 index 0000000..a939b68 --- /dev/null +++ b/tests/allman/issue0503.d.ref @@ -0,0 +1,15 @@ +string f() +{ + return duration.total!"seconds".to!string; +} + +string g() +{ + return duration.total!"seconds"().to!string; +} + +string h() +{ + return duration.total!"seconds"().to!string.to!string.to!string.to!string.to!string.to!string + .to!string.to!string.to!string; +} diff --git a/tests/issue0503.args b/tests/issue0503.args new file mode 100644 index 0000000..9df0b74 --- /dev/null +++ b/tests/issue0503.args @@ -0,0 +1 @@ +--reflow_property_chains=false diff --git a/tests/issue0503.d b/tests/issue0503.d new file mode 100644 index 0000000..1025464 --- /dev/null +++ b/tests/issue0503.d @@ -0,0 +1,14 @@ +string f() +{ + return duration.total!"seconds".to!string; +} + +string g() +{ + return duration.total!"seconds"().to!string; +} + +string h() +{ + return duration.total!"seconds"().to!string.to!string.to!string.to!string.to!string.to!string.to!string.to!string.to!string; +} diff --git a/tests/knr/issue0503.d.ref b/tests/knr/issue0503.d.ref new file mode 100644 index 0000000..a939b68 --- /dev/null +++ b/tests/knr/issue0503.d.ref @@ -0,0 +1,15 @@ +string f() +{ + return duration.total!"seconds".to!string; +} + +string g() +{ + return duration.total!"seconds"().to!string; +} + +string h() +{ + return duration.total!"seconds"().to!string.to!string.to!string.to!string.to!string.to!string + .to!string.to!string.to!string; +} diff --git a/tests/otbs/issue0503.d.ref b/tests/otbs/issue0503.d.ref new file mode 100644 index 0000000..b27874e --- /dev/null +++ b/tests/otbs/issue0503.d.ref @@ -0,0 +1,12 @@ +string f() { + return duration.total!"seconds".to!string; +} + +string g() { + return duration.total!"seconds"().to!string; +} + +string h() { + return duration.total!"seconds"().to!string.to!string.to!string.to!string.to!string.to!string + .to!string.to!string.to!string; +}