diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c3966a1cc..a1b9c83a6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -159,7 +159,7 @@ jobs: # One explicit job per target, so every binary we ship is traceable to a named run. native: - name: native (${{ matrix.platform }}) + name: native (${{ matrix.runner }}) needs: build runs-on: ${{ matrix.runner }} timeout-minutes: 90 @@ -170,17 +170,15 @@ jobs: strategy: fail-fast: false matrix: - include: - - platform: linux-x86-64 - runner: ubuntu-latest - - platform: linux-aarch64 - runner: ubuntu-24.04-arm - - platform: macos-aarch64 - runner: macos-15 - - platform: macos-x86-64 - runner: macos-15-intel - - platform: windows-x86-64 - runner: windows-latest + runner: + - ubuntu-latest + - ubuntu-24.04-arm + # macOS arm64 is left out: GitHub's runners for it are scarce, and from 17 to 19 November 2026 it found + # none for 13 of the job's 21 pull-request runs, each failing after 15 minutes of waiting. The release + # still builds it. + # - macos-15 + - macos-15-intel + - windows-latest steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 diff --git a/README.md b/README.md index 5e3d29ef2..9ee8a279d 100644 --- a/README.md +++ b/README.md @@ -192,10 +192,10 @@ mise run ci:native # actually run the linux-aarch64 native job Two caveats: -- **act cannot containerise macOS**, so the `macos-aarch64` leg has to be checked by building the +- **act cannot containerise macOS**, so the `macos-15-intel` leg has to be checked by building the native image on a Mac. - **On an Apple Silicon host** the `ubuntu-24.04` container runs as arm64, so the job labelled - `linux-x86-64` produces an aarch64 binary locally. Fine for exercising the workflow, not a + `ubuntu-latest` produces an aarch64 binary locally. Fine for exercising the workflow, not a substitute for real CI. ## License and attribution diff --git a/buildSrc/src/main/groovy/open-java-format.error-prone-conventions.gradle b/buildSrc/src/main/groovy/open-java-format.error-prone-conventions.gradle index 0b8e66b63..66fc8ab26 100644 --- a/buildSrc/src/main/groovy/open-java-format.error-prone-conventions.gradle +++ b/buildSrc/src/main/groovy/open-java-format.error-prone-conventions.gradle @@ -25,6 +25,7 @@ tasks.withType(JavaCompile).configureEach { nullaway { handleTestAssertionLibraries = true } + error('AlmostJavadoc') error('CanonicalAnnotationSyntax') error('CollectorMutability') error('DefaultCharset') diff --git a/mise.toml b/mise.toml index 3f89f0094..0dc300c06 100644 --- a/mise.toml +++ b/mise.toml @@ -18,7 +18,7 @@ run = "act push --job build --env JAVA_HOME=/opt/hostedtoolcache/Java_Temurin-Ho [tasks."ci:native"] description = "Run the linux-aarch64 native job locally in Docker" -run = "act push --job native --matrix platform:linux-aarch64" +run = "act push --job native --matrix runner:ubuntu-24.04-arm" # ---- GitHub Actions secrets ---- # Read from 1Password at apply time; nothing secret is stored in the repo. Requires gh diff --git a/open-java-format/src/main/java/com/palantir/javaformat/java/javadoc/CharStream.java b/open-java-format/src/main/java/com/palantir/javaformat/java/javadoc/CharStream.java index f74d8eccf..d16bc3103 100644 --- a/open-java-format/src/main/java/com/palantir/javaformat/java/javadoc/CharStream.java +++ b/open-java-format/src/main/java/com/palantir/javaformat/java/javadoc/CharStream.java @@ -42,7 +42,9 @@ boolean tryConsume(String expected) { return true; } - /* + /** + * Like {@link #tryConsume}, but for a match of the pattern at the start of the remaining input. + * * @param pattern the pattern to search for, which must be anchored to match only at position 0 */ boolean tryConsumeRegex(Pattern pattern) { diff --git a/open-java-format/src/main/java/com/palantir/javaformat/java/javadoc/JavadocLexer.java b/open-java-format/src/main/java/com/palantir/javaformat/java/javadoc/JavadocLexer.java index f7fcfe2e7..4c36fdb62 100644 --- a/open-java-format/src/main/java/com/palantir/javaformat/java/javadoc/JavadocLexer.java +++ b/open-java-format/src/main/java/com/palantir/javaformat/java/javadoc/JavadocLexer.java @@ -173,7 +173,8 @@ private List generateTokens() throws LexException { result = joinAdjacentLiteralsAndAdjacentWhitespace(result); result = inferParagraphTags(result); result = optionalizeSpacesAfterLinks(result); - return deindentPreCodeBlocks(result); + result = deindentPreCodeBlocks(result); + return removeTrailingParagraphTags(result); } private Token readToken() throws LexException { @@ -574,6 +575,35 @@ private static void deindentPreCodeBlock(List output, PeekingIterator} tags at the end of the comment, and the whitespace and {@code

} tags among them. + * Nothing follows such a tag, but the writer would still put it on a line of its own after a blank one. + * + *

A {@code

} with attributes stays: its {@code id} may be the target of a link. + */ + private static List removeTrailingParagraphTags(List input) { + // The last token is always END_JAVADOC, and the scan stops at BEGIN_JAVADOC at the latest. + int end = input.size() - 1; + int cut = end; + for (int i = end - 1; i >= 0; i--) { + Token token = input.get(i); + if (token.getType() == PARAGRAPH_OPEN_TAG + && BARE_PARAGRAPH_OPEN_PATTERN.matcher(token.getValue()).matches()) { + cut = i; + } else if (token.getType() != WHITESPACE && token.getType() != PARAGRAPH_CLOSE_TAG) { + break; + } + } + if (cut == end) { + return input; + } + var output = new ArrayList(input.subList(0, cut)); + output.add(input.get(end)); + return List.copyOf(output); + } + + private static final Pattern BARE_PARAGRAPH_OPEN_PATTERN = compile("", CASE_INSENSITIVE); + private static final CharMatcher NEWLINE = CharMatcher.is('\n'); private static boolean hasMultipleNewlines(String s) { @@ -617,15 +647,15 @@ private static boolean hasMultipleNewlines(String s) { private static final Pattern BR_PATTERN = openTagPattern("br"); private static final Pattern SNIPPET_TAG_OPEN_PATTERN = compile("^[{]@snippet\\b"); private static final Pattern INLINE_TAG_OPEN_PATTERN = compile("^[{]@\\w*"); - /* - * We exclude < so that we don't swallow following HTML tags. This lets us fix up "foo

" (~400 - * hits in Google-internal code). We will join unnecessarily split "words" (like "foobar") - * in a later step. There's a similar story for braces. I'm not sure I actually need to exclude @ - * or *. TODO(cpovirk): Try removing them. + /** + * We exclude {@code <} so that we don't swallow following HTML tags. This lets us fix up {@code foo

} (~400 + * hits in Google-internal code). We will join unnecessarily split "words" (like {@code foobar}) in a later + * step. There's a similar story for braces. I'm not sure I actually need to exclude {@code @} or {@code *}. + * TODO(cpovirk): Try removing them. * - * Thanks to the "rejoin" step in joinAdjacentLiteralsAndAdjacentWhitespace(), we could get away - * with matching only one character here. That would eliminate the need for the regex entirely. - * That might be faster or slower than what we do now. + *

Thanks to the "rejoin" step in {@link #joinAdjacentLiteralsAndAdjacentWhitespace}, we could get away with + * matching only one character here. That would eliminate the need for the regex entirely. That might be faster or + * slower than what we do now. */ private static final Pattern LITERAL_PATTERN = compile("^.[^ \t\n@<{}*]*", DOTALL); diff --git a/open-java-format/src/test/java/com/palantir/javaformat/java/JavadocFormattingTest.java b/open-java-format/src/test/java/com/palantir/javaformat/java/JavadocFormattingTest.java index 0643bfce0..320e3d5d2 100644 --- a/open-java-format/src/test/java/com/palantir/javaformat/java/JavadocFormattingTest.java +++ b/open-java-format/src/test/java/com/palantir/javaformat/java/JavadocFormattingTest.java @@ -1028,6 +1028,73 @@ void removeInitialParagraphTag() { doFormatTest(input, expected); } + @Test + void removeTrailingParagraphTag() { + String[] input = { + "/**", // + " * The client's first name.", + " *", + " *

", + " */", + "class Test {}", + }; + String[] expected = { + "/** The client's first name. */", // + "class Test {}", + }; + doFormatTest(input, expected); + } + + @Test + void removeEveryTrailingParagraphTag() { + String[] input = { + "class Test {", + " /**", + " * Returns nothing.", + " *", + " * @param x the x", + " *

", + " */", + " void f(int x) {}", + "", + " /**", + " * Closed and repeated.", + " *", + " *

", + " *

", + " */", + " void g() {}", + "}", + }; + String[] expected = { + "class Test {", + " /**", + " * Returns nothing.", + " *", + " * @param x the x", + " */", + " void f(int x) {}", + "", + " /** Closed and repeated. */", + " void g() {}", + "}", + }; + doFormatTest(input, expected); + } + + @Test + void keepTrailingParagraphTagWithAttributes() { + String[] input = { + "/**", // + " * Ends with an anchor.", + " *", + " *

", + " */", + "class Test {}", + }; + doFormatTest(input, input); + } + @Test void inferParagraphTags() { String[] input = {