Skip to content

Commit

Permalink
fix(printer): no longer fail to print binary expression with comment …
Browse files Browse the repository at this point in the history
…before first operator
  • Loading branch information
jtkiesel committed Oct 10, 2024
1 parent d18871d commit 7ebe83f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ function moveExpressionTrailingCommentsToNextOperator(
ctx: BinaryExpressionCtx
) {
const binaryOperators = ctx.BinaryOperator;
let binaryOperatorIndex = 1;
let binaryOperatorIndex = 0;
if (binaryOperators?.length) {
ctx.unaryExpression.forEach(unaryExpression => {
if (hasTrailingComments(unaryExpression)) {
while (
binaryOperatorIndex < binaryOperators.length &&
binaryOperatorIndex < binaryOperators.length - 1 &&
unaryExpression.location.endOffset &&
binaryOperators[binaryOperatorIndex].startOffset <
unaryExpression.location.endOffset
Expand Down
3 changes: 1 addition & 2 deletions packages/prettier-plugin-java/test/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ export function testRepositorySample(
});
if (code.status !== 0) {
expect.fail(
`Cannot build ${testFolder}, please check the output below:\n` +
code.error ?? code.stderr
`Cannot build ${testFolder}, please check the output below:\n${code.error ?? code.stderr}`
);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
describe("prettier-java", () => {
testSample(path.resolve(__dirname, "./class"));
testSample(path.resolve(__dirname, "./edge"));
testSample(path.resolve(__dirname, "./expression"));
testSample(path.resolve(__dirname, "./interface"));
testSample(path.resolve(__dirname, "./package"));
testSample(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Example {

void example() {
0 //
+ 1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Example {

void example() {
0 + //
1;
}
}

0 comments on commit 7ebe83f

Please sign in to comment.