Skip to content

Commit

Permalink
New format config for skipping white spaces before and after block pa…
Browse files Browse the repository at this point in the history
…renthese
  • Loading branch information
hogimn committed Apr 15, 2024
1 parent 2dc6a7d commit 21bc903
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
13 changes: 11 additions & 2 deletions SQL.Formatter/Core/AbstractFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ private string FormatOpeningParentheses(Token token, string query)
if (!inlineBlock.IsActive())
{
indentation.IncreaseBlockLevel();
query = AddNewline(query);
if (!cfg.skipWhitespaceNearBlockParentheses)
{
query = AddNewline(query);
}
}

return query;
Expand All @@ -207,7 +210,13 @@ private string FormatClosingParentheses(Token token, string query)
else
{
indentation.DecreaseBlockLevel();
return FormatWithSpaces(token, AddNewline(query));

if (!cfg.skipWhitespaceNearBlockParentheses)
{
return FormatWithSpaces(token, AddNewline(query));
}

return FormatWithoutSpaces(token, query);
}
}

Expand Down
19 changes: 17 additions & 2 deletions SQL.Formatter/Core/FormatConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@ public class FormatConfig
public readonly Params parameters;
public readonly bool uppercase;
public readonly int linesBetweenQueries;
public readonly bool skipWhitespaceNearBlockParentheses;

public FormatConfig(
string indent,
int maxColumnLength,
Params parameters,
bool uppercase,
int linesBetweenQueries)
int linesBetweenQueries,
bool skipWhitespaceNearBlockParentheses)
{
this.indent = indent;
this.maxColumnLength = maxColumnLength;
this.parameters = parameters == null ? Params.Empty : parameters;
this.uppercase = uppercase;
this.linesBetweenQueries = linesBetweenQueries;
this.skipWhitespaceNearBlockParentheses = skipWhitespaceNearBlockParentheses;
}

public static FormatConfigBuilder Builder()
Expand All @@ -39,6 +42,7 @@ public class FormatConfigBuilder
private Params parameters;
private bool uppercase;
private int linesBetweenQueries;
private bool skipWhitespaceNearBlockParentheses;

public FormatConfigBuilder()
{
Expand Down Expand Up @@ -84,10 +88,21 @@ public FormatConfigBuilder LinesBetweenQueries(int linesBetweenQueries)
return this;
}

public FormatConfigBuilder SkipWhitespaceNearBlockParentheses(bool skipWhitespaceNearBlockParentheses)
{
this.skipWhitespaceNearBlockParentheses = skipWhitespaceNearBlockParentheses;
return this;
}

public FormatConfig Build()
{
return new FormatConfig(
indent, maxColumnLength, parameters, uppercase, linesBetweenQueries);
indent,
maxColumnLength,
parameters,
uppercase,
linesBetweenQueries,
skipWhitespaceNearBlockParentheses);
}
}
}
Expand Down

0 comments on commit 21bc903

Please sign in to comment.