Repository: sql-formatter-org/sql-formatter (ts)

Issue:
[FORMATTING] LIMIT format error
**Input data**
select * from account limit 10;
Indentation style: Tabular, Left
**Expected Output**

```sql
select    *
from      account
limit       10;
```

**Actual Output**

```sql
select    *
from      account
limit
          10;
```

**Usage**

- How are you calling / using the library?  I using https://sql-formatter-org.github.io/sql-formatter/
- What SQL language(s) does this apply to? SQL
- Which SQL Formatter version are you using? 10.0.0


Pull request description:
Fix tabular style formatting of LIMIT clause
Fixes #412

Patch:
diff --git a/src/formatter/ExpressionFormatter.ts b/src/formatter/ExpressionFormatter.ts
index 8c0fb11f..9bcb42a7 100644
--- a/src/formatter/ExpressionFormatter.ts
+++ b/src/formatter/ExpressionFormatter.ts
@@ -170,13 +170,17 @@ export default class ExpressionFormatter {
     this.layout.add(WS.NEWLINE, WS.INDENT, this.showKw(node.name));
     this.layout.indentation.increaseTopLevel();
 
-    if (node.offset) {
+    if (isTabularStyle(this.cfg)) {
+      this.layout.add(WS.SPACE);
+    } else {
       this.layout.add(WS.NEWLINE, WS.INDENT);
+    }
+
+    if (node.offset) {
       this.layout = this.formatSubExpression(node.offset);
       this.layout.add(WS.NO_SPACE, ',', WS.SPACE);
       this.layout = this.formatSubExpression(node.count);
     } else {
-      this.layout.add(WS.NEWLINE, WS.INDENT);
       this.layout = this.formatSubExpression(node.count);
     }
     this.layout.indentation.decreaseTopLevel();
diff --git a/src/formatter/tabularStyle.ts b/src/formatter/tabularStyle.ts
index 0745b463..75bc8a75 100644
--- a/src/formatter/tabularStyle.ts
+++ b/src/formatter/tabularStyle.ts
@@ -35,6 +35,7 @@ export function isTabularToken(type: TokenType): boolean {
     type === TokenType.RESERVED_COMMAND ||
     type === TokenType.RESERVED_SELECT ||
     type === TokenType.RESERVED_SET_OPERATION ||
-    type === TokenType.RESERVED_JOIN
+    type === TokenType.RESERVED_JOIN ||
+    type === TokenType.LIMIT
   );
 }


Test patch:
diff --git a/test/features/limiting.ts b/test/features/limiting.ts
index 1afe4fbe..a6a33d5c 100644
--- a/test/features/limiting.ts
+++ b/test/features/limiting.ts
@@ -49,6 +49,16 @@ export default function supportsLimiting(format: FormatFn, types: LimitingTypes)
             6;
       `);
     });
+
+    // Regression test for #412
+    it('formats LIMIT in tabular style', () => {
+      const result = format('SELECT * FROM tbl LIMIT 5, 6;', { indentStyle: 'tabularLeft' });
+      expect(result).toBe(dedent`
+        SELECT    *
+        FROM      tbl
+        LIMIT     5, 6;
+      `);
+    });
   }
 
   if (types.limit && types.offset) {