No space after keywords

Readme update

test files
This commit is contained in:
Robert Schadek 2023-07-21 16:20:16 +02:00 committed by Robert burner Schadek
parent 470e65f7cc
commit edd40b8f64
8 changed files with 67 additions and 4 deletions

View File

@ -59,6 +59,7 @@ found there.
* `--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)*
* `--space_after_keywords`: *see dfmt_space_after_keywords [below](#dfmt-specific-properties)*
### Example
```
@ -121,6 +122,7 @@ dfmt_space_before_aa_colon | `true`, **`false`** | Adds a space after an associa
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.
dfmt_space_after_keywords | **`true`**, `false` | Insert space after keywords (if,while,foreach,for, etc.).
## Terminology
* Braces - `{` and `}`

View File

@ -65,6 +65,8 @@ struct Config
OptionalBoolean dfmt_single_indent;
///
OptionalBoolean dfmt_reflow_property_chains;
///
OptionalBoolean dfmt_space_after_statement_keyword;
mixin StandardEditorConfigFields;

View File

@ -257,7 +257,9 @@ private:
if (indents.length == 0 || !indents.topIsOneOf(tok!"switch", tok!"with"))
indents.push(tok!"with");
writeToken();
write(" ");
if (config.dfmt_space_after_keywords) {
write(" ");
}
if (hasCurrent && currentIs(tok!"("))
writeParens(false);
if (hasCurrent && !currentIs(tok!"switch") && !currentIs(tok!"with")
@ -266,7 +268,9 @@ private:
newline();
}
else if (hasCurrent && !currentIs(tok!"{"))
{
write(" ");
}
}
else if (currentIs(tok!"switch"))
{
@ -1118,7 +1122,10 @@ private:
indents.pop();
indents.push(tok!"switch");
writeToken(); // switch
write(" ");
if (config.dfmt_space_after_keywords)
{
write(" ");
}
}
void formatBlockHeader()
@ -1149,16 +1156,26 @@ private:
if (currentIs(tok!"("))
{
write(" ");
if (config.dfmt_space_after_keywords)
{
write(" ");
}
writeParens(false);
}
if (hasCurrent)
{
if (currentIs(tok!"switch") || (currentIs(tok!"final") && peekIs(tok!"switch")))
write(" ");
{
if (config.dfmt_space_after_keywords)
{
write(" ");
}
}
else if (currentIs(tok!"comment"))
{
formatStep();
}
else if (!shouldPushIndent)
{
if (!currentIs(tok!"{") && !currentIs(tok!";"))

View File

@ -101,6 +101,9 @@ else
case "reflow_property_chains":
optConfig.dfmt_reflow_property_chains = optVal;
break;
case "space_after_keywords":
optConfig.dfmt_space_after_keywords = optVal;
break;
default:
assert(false, "Invalid command-line switch");
}
@ -123,6 +126,7 @@ else
"soft_max_line_length", &optConfig.dfmt_soft_max_line_length,
"outdent_attributes", &handleBooleans,
"space_after_cast", &handleBooleans,
"space_after_keywords", &handleBooleans,
"selective_import_space", &handleBooleans,
"space_before_function_parameters", &handleBooleans,
"split_operator_at_line_end", &handleBooleans,
@ -338,6 +342,7 @@ Formatting Options:
--outdent_attributes
--space_after_cast
--space_before_function_parameters
--space_after_keywords
--selective_import_space
--single_template_constraint_indent
--split_operator_at_line_end

View File

@ -0,0 +1,15 @@
void main(string[] args)
{
for(int i = 0; i < 10; ++i)
{
if(i == 9)
break;
}
while(false)
{
}
foreach(i; 0 .. 9)
{
}
}

View File

@ -0,0 +1,11 @@
void main(string[] args) {
for(int i = 0; i < 10; ++i) {
if(i == 9)
break;
}
while(false) {
}
foreach(i; 0 .. 9) {
}
}

View File

@ -0,0 +1 @@
--space_after_keywords=false

View File

@ -0,0 +1,10 @@
void main(string[] args)
{
for (int i = 0; i < 10; ++i) {
if (i == 9) break;
}
while (false) {}
foreach (i; 0 .. 9) {
}
}