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
…rentheses
  • Loading branch information
hemlac committed Jan 10, 2024
1 parent 1f53305 commit bef5380
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ private String formatOpeningParentheses(Token token, String query) {

if (!this.inlineBlock.isActive()) {
this.indentation.increaseBlockLevel();
query = this.addNewline(query);
if (!cfg.skipWhitespaceNearBlockParentheses) {
query = this.addNewline(query);
}
}
return query;
}
Expand All @@ -179,7 +181,11 @@ private String formatClosingParentheses(Token token, String query) {
return this.formatWithSpaceAfter(token, query);
} else {
this.indentation.decreaseBlockLevel();
return this.formatWithSpaces(token, this.addNewline(query));
if (!cfg.skipWhitespaceNearBlockParentheses) {
return this.formatWithSpaces(token, this.addNewline(query));
} else {
return this.formatWithoutSpaces(token, query);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@ public class FormatConfig {
public final Params params;
public final boolean uppercase;
public final Integer linesBetweenQueries;
public final boolean skipWhitespaceNearBlockParentheses;

FormatConfig(
String indent,
int maxColumnLength,
Params params,
boolean uppercase,
Integer linesBetweenQueries) {
Integer linesBetweenQueries,
boolean skipWhitespaceNearBlockParentheses) {
this.indent = indent;
this.maxColumnLength = maxColumnLength;
this.params = params == null ? Params.EMPTY : params;
this.uppercase = uppercase;
this.linesBetweenQueries = linesBetweenQueries;
this.skipWhitespaceNearBlockParentheses = skipWhitespaceNearBlockParentheses;
}

/**
Expand All @@ -44,6 +47,7 @@ public static class FormatConfigBuilder {
private Params params;
private boolean uppercase;
private Integer linesBetweenQueries;
private boolean skipWhitespaceNearBlockParentheses;

FormatConfigBuilder() {}

Expand Down Expand Up @@ -108,14 +112,30 @@ public FormatConfigBuilder linesBetweenQueries(int linesBetweenQueries) {
return this;
}

/**
* @param skipWhitespaceNearBlockParentheses skip adding whitespace before and after block
* Parentheses
* @return This
*/
public FormatConfigBuilder skipWhitespaceNearBlockParentheses(
boolean skipWhitespaceNearBlockParentheses) {
this.skipWhitespaceNearBlockParentheses = skipWhitespaceNearBlockParentheses;
return this;
}

/**
* Returns an instance of FormatConfig created from the fields set on this builder.
*
* @return FormatConfig
*/
public FormatConfig build() {
return new FormatConfig(
this.indent, this.maxColumnLength, this.params, this.uppercase, this.linesBetweenQueries);
this.indent,
this.maxColumnLength,
this.params,
this.uppercase,
this.linesBetweenQueries,
this.skipWhitespaceNearBlockParentheses);
}
}
}

0 comments on commit bef5380

Please sign in to comment.