Skip to content

Commit 4881a5c

Browse files
feat: make pretty print the default option
- Change default value of pretty option from false to true - Update DeparserOptions interface comment to reflect new default - Update SqlFormatter constructor default parameter to true - Update DeparserContext constructor default parameter to true - Update README documentation to show new default value - Fix entry-point tests to explicitly set pretty: false for backward compatibility - Maintain full backward compatibility - pretty: false still works as expected This makes pretty formatting the default behavior while preserving all existing functionality. Co-Authored-By: Dan Lynch <[email protected]>
1 parent ec88c04 commit 4881a5c

File tree

5 files changed

+14
-14
lines changed

5 files changed

+14
-14
lines changed

packages/deparser/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ The deparser accepts optional configuration for formatting and output control:
9999
import { deparseSync as deparse } from 'pgsql-deparser';
100100

101101
const options = {
102-
pretty: true, // Enable pretty formatting (default: false)
102+
pretty: true, // Enable pretty formatting (default: true)
103103
newline: '\n', // Newline character (default: '\n')
104104
tab: ' ', // Tab/indentation character (default: ' ')
105105
semicolons: true // Add semicolons to statements (default: true)
@@ -110,7 +110,7 @@ const sql = deparse(ast, options);
110110

111111
| Option | Type | Default | Description |
112112
|--------|------|---------|-------------|
113-
| `pretty` | `boolean` | `false` | Enable pretty formatting with indentation and line breaks |
113+
| `pretty` | `boolean` | `true` | Enable pretty formatting with indentation and line breaks |
114114
| `newline` | `string` | `'\n'` | Character(s) used for line breaks |
115115
| `tab` | `string` | `' '` | Character(s) used for indentation |
116116
| `semicolons` | `boolean` | `true` | Add semicolons to SQL statements |

packages/deparser/__tests__/entry-point.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@ describe('Entry Point Refactoring', () => {
1616

1717
describe('ParseResult handling', () => {
1818
it('should handle bare ParseResult (duck-typed)', () => {
19-
const result = Deparser.deparse(parseResult);
19+
const result = Deparser.deparse(parseResult, { pretty: false });
2020
expect(result).toContain('SELECT * FROM users WHERE id = 1');
2121
expect(result).toContain('INSERT INTO logs (message) VALUES (\'test\')');
2222
});
2323

2424
it('should handle wrapped ParseResult', () => {
2525
const wrappedParseResult = { ParseResult: parseResult } as t.Node;
26-
const result = Deparser.deparse(wrappedParseResult);
26+
const result = Deparser.deparse(wrappedParseResult, { pretty: false });
2727
expect(result).toContain('SELECT * FROM users WHERE id = 1');
2828
expect(result).toContain('INSERT INTO logs (message) VALUES (\'test\')');
2929
});
3030

3131
it('should preserve semicolons based on stmt_len', () => {
32-
const result = Deparser.deparse(parseResult);
32+
const result = Deparser.deparse(parseResult, { pretty: false });
3333
// The first statement should have a semicolon if stmt_len is set
3434
const lines = result.split('\n').filter(line => line.trim());
3535
if (parseResult.stmts?.[0]?.stmt_len) {
@@ -42,15 +42,15 @@ describe('Entry Point Refactoring', () => {
4242
it('should handle wrapped RawStmt', () => {
4343
const rawStmt = parseResult.stmts![0];
4444
const wrappedRawStmt = { RawStmt: rawStmt } as t.Node;
45-
const result = Deparser.deparse(wrappedRawStmt);
45+
const result = Deparser.deparse(wrappedRawStmt, { pretty: false });
4646
expect(result).toContain('SELECT * FROM users WHERE id = 1');
4747
});
4848

4949
it('should add semicolon when stmt_len is present', () => {
5050
const rawStmt = parseResult.stmts![0];
5151
if (rawStmt.stmt_len) {
5252
const wrappedRawStmt = { RawStmt: rawStmt } as t.Node;
53-
const result = Deparser.deparse(wrappedRawStmt);
53+
const result = Deparser.deparse(wrappedRawStmt, { pretty: false });
5454
expect(result).toMatch(/;$/);
5555
}
5656
});
@@ -59,14 +59,14 @@ describe('Entry Point Refactoring', () => {
5959
describe('Array handling', () => {
6060
it('should handle array of statements', () => {
6161
const statements = parseResult.stmts!.map(rawStmt => rawStmt.stmt!);
62-
const result = Deparser.deparse(statements);
62+
const result = Deparser.deparse(statements, { pretty: false });
6363
expect(result).toContain('SELECT * FROM users WHERE id = 1');
6464
expect(result).toContain('INSERT INTO logs (message) VALUES (\'test\')');
6565
});
6666

6767
it('should handle array of wrapped nodes', () => {
6868
const wrappedNodes = parseResult.stmts!.map(rawStmt => ({ RawStmt: rawStmt } as t.Node));
69-
const result = Deparser.deparse(wrappedNodes);
69+
const result = Deparser.deparse(wrappedNodes, { pretty: false });
7070
expect(result).toContain('SELECT * FROM users WHERE id = 1');
7171
expect(result).toContain('INSERT INTO logs (message) VALUES (\'test\')');
7272
});
@@ -75,7 +75,7 @@ describe('Entry Point Refactoring', () => {
7575
describe('Single node handling', () => {
7676
it('should handle single statement', () => {
7777
const stmt = parseResult.stmts![0].stmt!;
78-
const result = Deparser.deparse(stmt);
78+
const result = Deparser.deparse(stmt, { pretty: false });
7979
expect(result).toContain('SELECT * FROM users WHERE id = 1');
8080
});
8181
});
@@ -123,4 +123,4 @@ describe('Entry Point Refactoring', () => {
123123
expect(deparser['tree'][0]).toBe(wrapped);
124124
});
125125
});
126-
});
126+
});

packages/deparser/src/deparser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export interface DeparserOptions {
7979
functionDelimiter?: string; // Default: '$$'
8080
// Alternative delimiter when the default is found in the body
8181
functionDelimiterFallback?: string; // Default: '$EOFCODE$'
82-
pretty?: boolean; // Default: false
82+
pretty?: boolean; // Default: true
8383
}
8484

8585
// Type guards for better type safety

packages/deparser/src/utils/sql-formatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export class SqlFormatter {
33
private tabChar: string;
44
private prettyMode: boolean;
55

6-
constructor(newlineChar: string = '\n', tabChar: string = ' ', prettyMode: boolean = false) {
6+
constructor(newlineChar: string = '\n', tabChar: string = ' ', prettyMode: boolean = true) {
77
this.newlineChar = newlineChar;
88
this.tabChar = tabChar;
99
this.prettyMode = prettyMode;

packages/deparser/src/visitors/base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class DeparserContext {
4848

4949
constructor({
5050
indentLevel = 0,
51-
prettyMode = false,
51+
prettyMode = true,
5252
isStringLiteral,
5353
parentNodeTypes = [],
5454
formatter,

0 commit comments

Comments
 (0)