Skip to content
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
7 changes: 6 additions & 1 deletion packages/java-parser/src/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,12 @@ function attachComments(
// prettier ignore support
for (let i = 0; i < nodeLeadingComments.length; i++) {
if (isPrettierIgnoreComment(nodeLeadingComments[i])) {
mostEnclosiveCstNodeByStartOffset[startOffset].ignore = true;
const node = mostEnclosiveCstNodeByStartOffset[startOffset];
const ignoreNode =
node.name === "blockStatements"
? node.children.blockStatement[0]
: node;
ignoreNode.ignore = true;
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package tech.jhipster;

import java.util.Map;

public class StrangePrettierIgnore {

private StrangePrettierIgnore() {}

public static void drinkBeers() {
// prettier-ignore
Map<String, String> beers = Map.of(
"beer1", "Gulden Draak",
"beer2", "Piraat",
"beer3", "Kapittel"
);

System.out.println(beers); // not well formated here
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package tech.jhipster;

import java.util.Map;

public class StrangePrettierIgnore {

private StrangePrettierIgnore() {}

public static void drinkBeers() {
// prettier-ignore
Map<String, String> beers = Map.of(
"beer1", "Gulden Draak",
"beer2", "Piraat",
"beer3", "Kapittel"
);

System.out.println(beers); // not well formated here
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { testSample } from "../../test-utils";
import * as path from "path";

describe("prettier-java: try catch", () => {
testSample(path.resolve(__dirname, "./block"));
testSample(path.resolve(__dirname, "./classDeclaration"));
testSample(path.resolve(__dirname, "./method"));
testSample(path.resolve(__dirname, "./multiple-ignore"));
Expand Down