Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: print comment before first binary operator without failing #688

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("prettier-java", () => {
testRepositorySample(
resolve(__dirname, "../../samples/spring-boot"),
"./gradlew",
["clean", "build", "-Ddisable.checks", "-xtest", "--no-scan"]
["compileJava"]
);

jhipsterRepository.forEach(repository => {
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;
}
}
Loading