mirror of
https://github.com/dlang-community/dfmt.git
synced 2025-04-25 21:00:03 +03:00
fix #236 - Allow constraints to be indented by a single tab merged-on-behalf-of: BBasile <BBasile@users.noreply.github.com>
This commit is contained in:
parent
95905cdbf1
commit
b01c624ef0
15 changed files with 68 additions and 8 deletions
|
@ -4,9 +4,6 @@ set -e
|
|||
|
||||
if [[ $BUILD == dub ]]; then
|
||||
dub build --build=release
|
||||
|
||||
mkdir bin
|
||||
mv dfmt ./bin
|
||||
elif [[ $DC == ldc2 ]]; then
|
||||
git submodule update --init --recursive
|
||||
make ldc -j2
|
||||
|
|
|
@ -41,6 +41,7 @@ found in .editorconfig files.
|
|||
* **--max_line_length**: See **max_line_length** below
|
||||
* **--soft_max_line_length**: See **dfmt_soft_max_line_length** below
|
||||
* **--outdent_attributes**: See **dfmt_outdent_attributes** below
|
||||
* **--single_template_constraint_indent**: See **dfmt_template_constraint_style** below
|
||||
* **--space_after_cast**: See **dfmt_space_after_cast** below
|
||||
* **--space_before_function_parameters**: See **dfmt_space_before_function_parameters** below
|
||||
* **--split_operator_at_line_end**: See **dfmt_split_operator_at_line_end** below
|
||||
|
@ -105,6 +106,7 @@ dfmt_space_before_function_parameters | `true`, `false` | `false` | Insert space
|
|||
dfmt_selective_import_space | `true`, `false` | `true` | Insert space after the module name and before the `:` for selective imports.
|
||||
dfmt_compact_labeled_statements | `true`, `false` | `true` | Place labels on the same line as the labeled `switch`, `for`, `foreach`, or `while` statement.
|
||||
dfmt_template_constraint_style | `conditional_newline_indent` `conditional_newline` `always_newline` `always_newline_indent` | `conditional_newline_indent` | Control the formatting of template constraints.
|
||||
dfmt_single_template_constraint_indent | `true`, `false` | `false` | Set if the constraints are indented by a single tab instead of two. Has only an effect for if indentation style if set to `always_newline_indent` or `conditional_newline_indent`.
|
||||
|
||||
## Terminology
|
||||
* Braces - `{` and `}`
|
||||
|
|
4
dub.json
4
dub.json
|
@ -5,5 +5,7 @@
|
|||
"license": "BSL-1.0",
|
||||
"dependencies": {
|
||||
"libdparse": "~>0.8.0-alpha.5"
|
||||
}
|
||||
},
|
||||
"targetPath" : "bin/",
|
||||
"targetName" : "dfmt",
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit ee0fa01ab74b6bf27bed3c7bdb9d6fb789963342
|
||||
Subproject commit 687c0ca751747ebe498c183da1a3ee3119d57932
|
|
@ -53,6 +53,8 @@ struct Config
|
|||
OptionalBoolean dfmt_compact_labeled_statements;
|
||||
///
|
||||
TemplateConstraintStyle dfmt_template_constraint_style;
|
||||
///
|
||||
OptionalBoolean dfmt_single_template_constraint_indent;
|
||||
|
||||
mixin StandardEditorConfigFields;
|
||||
|
||||
|
@ -79,6 +81,7 @@ struct Config
|
|||
dfmt_selective_import_space = OptionalBoolean.t;
|
||||
dfmt_compact_labeled_statements = OptionalBoolean.t;
|
||||
dfmt_template_constraint_style = TemplateConstraintStyle.conditional_newline_indent;
|
||||
dfmt_single_template_constraint_indent = OptionalBoolean.f;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -324,6 +324,7 @@ private:
|
|||
|
||||
void formatConstraint()
|
||||
{
|
||||
import dfmt.editorconfig : OB = OptionalBoolean;
|
||||
with (TemplateConstraintStyle) final switch (config.dfmt_template_constraint_style)
|
||||
{
|
||||
case unspecified:
|
||||
|
@ -342,15 +343,19 @@ private:
|
|||
immutable l = currentLineLength + betweenParenLength(tokens[index + 1 .. $]);
|
||||
if (l > config.dfmt_soft_max_line_length)
|
||||
{
|
||||
pushWrapIndent(tok!"!");
|
||||
config.dfmt_single_template_constraint_indent == OB.t ?
|
||||
pushWrapIndent() : pushWrapIndent(tok!"!");
|
||||
newline();
|
||||
}
|
||||
else if (peekBackIs(tok!")"))
|
||||
write(" ");
|
||||
break;
|
||||
case always_newline_indent:
|
||||
pushWrapIndent(tok!"!");
|
||||
newline();
|
||||
{
|
||||
config.dfmt_single_template_constraint_indent == OB.t ?
|
||||
pushWrapIndent() : pushWrapIndent(tok!"!");
|
||||
newline();
|
||||
}
|
||||
break;
|
||||
}
|
||||
// if
|
||||
|
|
|
@ -113,6 +113,9 @@ else
|
|||
case "compact_labeled_statements":
|
||||
optConfig.dfmt_compact_labeled_statements = optVal;
|
||||
break;
|
||||
case "single_template_constraint_indent":
|
||||
optConfig.dfmt_single_template_constraint_indent = optVal;
|
||||
break;
|
||||
default:
|
||||
assert(false, "Invalid command-line switch");
|
||||
}
|
||||
|
@ -139,6 +142,7 @@ else
|
|||
"space_before_function_parameters", &handleBooleans,
|
||||
"split_operator_at_line_end", &handleBooleans,
|
||||
"compact_labeled_statements", &handleBooleans,
|
||||
"single_template_constraint_indent", &handleBooleans,
|
||||
"tab_width", &optConfig.tab_width,
|
||||
"template_constraint_style", &optConfig.dfmt_template_constraint_style);
|
||||
// dfmt on
|
||||
|
@ -329,6 +333,7 @@ Formatting Options:
|
|||
--space_after_cast
|
||||
--space_before_function_parameters
|
||||
--selective_import_space
|
||||
--single_template_constraint_indent
|
||||
--split_operator_at_line_end
|
||||
--compact_labeled_statements
|
||||
--template_constraint_style
|
||||
|
|
9
tests/allman/constraint_singe_tab.d.ref
Normal file
9
tests/allman/constraint_singe_tab.d.ref
Normal file
|
@ -0,0 +1,9 @@
|
|||
void foo()()
|
||||
if (dogs && pigs && birds && ants && foxes && flies && cats && bugs && bees
|
||||
&& cows && sheeps && monkeys && whales)
|
||||
{
|
||||
}
|
||||
|
||||
void foo()() if (dogs && pigs && birds)
|
||||
{
|
||||
}
|
10
tests/allman/constraint_singe_tab2.d.ref
Normal file
10
tests/allman/constraint_singe_tab2.d.ref
Normal file
|
@ -0,0 +1,10 @@
|
|||
void foo()()
|
||||
if (dogs && pigs && birds && ants && foxes && flies && cats && bugs && bees
|
||||
&& cows && sheeps && monkeys && whales)
|
||||
{
|
||||
}
|
||||
|
||||
void foo()()
|
||||
if (dogs && pigs && birds)
|
||||
{
|
||||
}
|
2
tests/constraint_singe_tab.args
Normal file
2
tests/constraint_singe_tab.args
Normal file
|
@ -0,0 +1,2 @@
|
|||
--template_constraint_style=conditional_newline_indent
|
||||
--single_template_constraint_indent=true
|
4
tests/constraint_singe_tab.d
Normal file
4
tests/constraint_singe_tab.d
Normal file
|
@ -0,0 +1,4 @@
|
|||
void foo()() if (dogs && pigs && birds && ants && foxes && flies && cats && bugs && bees && cows && sheeps && monkeys && whales)
|
||||
{}
|
||||
|
||||
void foo()() if (dogs && pigs && birds) {}
|
2
tests/constraint_singe_tab2.args
Normal file
2
tests/constraint_singe_tab2.args
Normal file
|
@ -0,0 +1,2 @@
|
|||
--template_constraint_style=always_newline_indent
|
||||
--single_template_constraint_indent=true
|
4
tests/constraint_singe_tab2.d
Normal file
4
tests/constraint_singe_tab2.d
Normal file
|
@ -0,0 +1,4 @@
|
|||
void foo()() if (dogs && pigs && birds && ants && foxes && flies && cats && bugs && bees && cows && sheeps && monkeys && whales)
|
||||
{}
|
||||
|
||||
void foo()() if (dogs && pigs && birds) {}
|
7
tests/otbs/constraint_singe_tab.d.ref
Normal file
7
tests/otbs/constraint_singe_tab.d.ref
Normal file
|
@ -0,0 +1,7 @@
|
|||
void foo()()
|
||||
if (dogs && pigs && birds && ants && foxes && flies && cats && bugs && bees
|
||||
&& cows && sheeps && monkeys && whales) {
|
||||
}
|
||||
|
||||
void foo()() if (dogs && pigs && birds) {
|
||||
}
|
8
tests/otbs/constraint_singe_tab2.d.ref
Normal file
8
tests/otbs/constraint_singe_tab2.d.ref
Normal file
|
@ -0,0 +1,8 @@
|
|||
void foo()()
|
||||
if (dogs && pigs && birds && ants && foxes && flies && cats && bugs && bees
|
||||
&& cows && sheeps && monkeys && whales) {
|
||||
}
|
||||
|
||||
void foo()()
|
||||
if (dogs && pigs && birds) {
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue