Skip to content

Commit 940ce79

Browse files
Merge pull request #33 from ogirardot/master
Add a FormatConfig parameter to change max column length default
2 parents 24f6525 + 442e40d commit 940ce79

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

src/main/java/com/github/vertical_blank/sqlformatter/core/FormatConfig.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
public class FormatConfig {
44

55
public static final String DEFAULT_INDENT = " ";
6+
public static final int DEFAULT_COLUMN_MAX_LENGTH = 50;
67

78
public final String indent;
9+
public final int maxColumnLength;
810
public final Params.Holder params;
911

10-
FormatConfig(String indent, Params.Holder params) {
12+
FormatConfig(String indent, int maxColumnLength, Params.Holder params) {
1113
this.indent = indent;
14+
this.maxColumnLength = maxColumnLength;
1215
this.params = params;
1316
}
1417

@@ -18,6 +21,7 @@ public static FormatConfigBuilder builder() {
1821

1922
public static class FormatConfigBuilder {
2023
private String indent;
24+
private int maxColumnLength = DEFAULT_COLUMN_MAX_LENGTH;
2125
private Params.Holder params;
2226

2327
FormatConfigBuilder() {
@@ -28,13 +32,19 @@ public FormatConfigBuilder indent(String indent) {
2832
return this;
2933
}
3034

35+
36+
public FormatConfigBuilder maxColumnLength(int maxColumnLength) {
37+
this.maxColumnLength = maxColumnLength;
38+
return this;
39+
}
40+
3141
public FormatConfigBuilder params(Params.Holder params) {
3242
this.params = params;
3343
return this;
3444
}
3545

3646
public FormatConfig build() {
37-
return new FormatConfig(indent, params);
47+
return new FormatConfig(indent, maxColumnLength, params);
3848
}
3949
}
4050
}

src/main/java/com/github/vertical_blank/sqlformatter/core/Formatter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class Formatter {
2222
*/
2323
public Formatter(FormatConfig cfg, Tokenizer tokenizer) {
2424
this.indentation = new Indentation(cfg.indent);
25-
this.inlineBlock = new InlineBlock();
25+
this.inlineBlock = new InlineBlock(cfg.maxColumnLength);
2626
this.params = new Params(cfg.params);
2727
this.tokenizer = tokenizer;
2828
this.previousReservedWord = null;

src/main/java/com/github/vertical_blank/sqlformatter/core/InlineBlock.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
/**
77
* Bookkeeper for inline blocks.
88
* <p>
9-
* Inline blocks are parenthized expressions that are shorter than INLINE_MAX_LENGTH.
9+
* Inline blocks are parenthized expressions that are shorter than maxColumnLength.
1010
* These blocks are formatted on a single line, unlike longer parenthized
1111
* expressions where open-parenthesis causes newline and increase of indentation.
1212
*/
1313
class InlineBlock {
1414

15-
private static final int INLINE_MAX_LENGTH = 50;
16-
1715
private int level;
16+
private final int maxColumnLength;
1817

19-
InlineBlock() {
18+
InlineBlock(int maxColumnLength) {
19+
this.maxColumnLength = maxColumnLength;
2020
this.level = 0;
2121
}
2222

@@ -65,7 +65,7 @@ private boolean isInlineBlock(List<Token> tokens, int index) {
6565
length += token.value.length();
6666

6767
// Overran max length
68-
if (length > INLINE_MAX_LENGTH) {
68+
if (length > maxColumnLength) {
6969
return false;
7070
}
7171

0 commit comments

Comments
 (0)