Skip to content

Commit 14012c3

Browse files
committed
Properly handle comment after the longest line
1 parent 8ae74f7 commit 14012c3

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/formatter/formatCommaPositions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,5 @@ function trimTrailingCommas(lines: string[]): string[] {
102102
}
103103

104104
function trimTrailingComments(lines: string[]): string[] {
105-
return lines.map(line => line.replace(/--.*/, ''));
105+
return lines.map(line => line.replace(/\s*--.*/, ''));
106106
}

test/options/commaPosition.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ export default function supportsCommaPosition(format: FormatFn) {
128128
const result = format(
129129
`SELECT alpha, --comment1
130130
beta,--comment2
131-
delta, epsilon, iota --comment3`,
131+
delta, epsilon,--comm
132+
iota --comment3`,
132133
{ commaPosition: 'tabular' }
133134
);
134135
expect(result).toBe(
@@ -137,7 +138,7 @@ export default function supportsCommaPosition(format: FormatFn) {
137138
alpha , --comment1
138139
beta , --comment2
139140
delta ,
140-
epsilon,
141+
epsilon, --comm
141142
iota --comment3
142143
`
143144
);

0 commit comments

Comments
 (0)