Skip to content

Commit ff4c832

Browse files
committed
New format config for skipping white spaces before and after block parenthese
1 parent 210cb5c commit ff4c832

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

SQL.Formatter/Core/AbstractFormatter.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,10 @@ private string FormatOpeningParentheses(Token token, string query)
191191
if (!inlineBlock.IsActive())
192192
{
193193
indentation.IncreaseBlockLevel();
194-
query = AddNewline(query);
194+
if (!cfg.skipWhitespaceNearBlockParentheses)
195+
{
196+
query = AddNewline(query);
197+
}
195198
}
196199

197200
return query;
@@ -207,7 +210,13 @@ private string FormatClosingParentheses(Token token, string query)
207210
else
208211
{
209212
indentation.DecreaseBlockLevel();
210-
return FormatWithSpaces(token, AddNewline(query));
213+
214+
if (!cfg.skipWhitespaceNearBlockParentheses)
215+
{
216+
return FormatWithSpaces(token, AddNewline(query));
217+
}
218+
219+
return FormatWithoutSpaces(token, query);
211220
}
212221
}
213222

SQL.Formatter/Core/FormatConfig.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,22 @@ public class FormatConfig
1212
public readonly Params parameters;
1313
public readonly bool uppercase;
1414
public readonly int linesBetweenQueries;
15+
public readonly bool skipWhitespaceNearBlockParentheses;
1516

1617
public FormatConfig(
1718
string indent,
1819
int maxColumnLength,
1920
Params parameters,
2021
bool uppercase,
21-
int linesBetweenQueries)
22+
int linesBetweenQueries,
23+
bool skipWhitespaceNearBlockParentheses)
2224
{
2325
this.indent = indent;
2426
this.maxColumnLength = maxColumnLength;
2527
this.parameters = parameters == null ? Params.Empty : parameters;
2628
this.uppercase = uppercase;
2729
this.linesBetweenQueries = linesBetweenQueries;
30+
this.skipWhitespaceNearBlockParentheses = skipWhitespaceNearBlockParentheses;
2831
}
2932

3033
public static FormatConfigBuilder Builder()
@@ -39,6 +42,7 @@ public class FormatConfigBuilder
3942
private Params parameters;
4043
private bool uppercase;
4144
private int linesBetweenQueries;
45+
private bool skipWhitespaceNearBlockParentheses;
4246

4347
public FormatConfigBuilder()
4448
{
@@ -84,10 +88,21 @@ public FormatConfigBuilder LinesBetweenQueries(int linesBetweenQueries)
8488
return this;
8589
}
8690

91+
public FormatConfigBuilder SkipWhitespaceNearBlockParentheses(bool skipWhitespaceNearBlockParentheses)
92+
{
93+
this.skipWhitespaceNearBlockParentheses = skipWhitespaceNearBlockParentheses;
94+
return this;
95+
}
96+
8797
public FormatConfig Build()
8898
{
8999
return new FormatConfig(
90-
indent, maxColumnLength, parameters, uppercase, linesBetweenQueries);
100+
indent,
101+
maxColumnLength,
102+
parameters,
103+
uppercase,
104+
linesBetweenQueries,
105+
skipWhitespaceNearBlockParentheses);
91106
}
92107
}
93108
}

0 commit comments

Comments
 (0)