Skip to content

Commit

Permalink
feat: add "commaBreak" option
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus authored Jun 12, 2021
2 parents 8e81c72 + 63acb6f commit a25830a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type UserConfigurationType = {|
+spaces?: number,
+stripComments?: boolean,
+tabs?: boolean,
+commaBreak?: boolean,
|};

type ConfigurationType = {|
Expand All @@ -30,6 +31,7 @@ type ConfigurationType = {|
+spaces: number,
+stripComments: boolean,
+tabs: boolean,
+commaBreak?: boolean,
|};

const executablePath = resolve(__dirname, 'pg-formatter/pg_format');
Expand Down Expand Up @@ -96,6 +98,10 @@ const createCommandLineArgs = (configuration: ConfigurationType): string => {
args.push('--tabs');
}

if (configuration.commaBreak) {
args.push('--comma-break');
}

return args.join(' ');
};

Expand Down
8 changes: 8 additions & 0 deletions test/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,11 @@ test('{noRcFile: true}', (t) => {
process.env.HOME = home;
}
});

test('{commaBreak: true}', (t) => {
const result = format('INSERT INTO shoes(type, color, price) VALUES ("sneaker", "white", 99)', {
commaBreak: true,
});

t.is(result, 'INSERT INTO shoes (\n type,\n color,\n price)\nVALUES (\n "sneaker",\n "white",\n 99)\n');
});

0 comments on commit a25830a

Please sign in to comment.