GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Leave JBang directives at the top of a file as written by abashev · Pull Request #91 · openjavaformat/open-java-format Conversation
Collaborator
Closes #24. The same problem is open upstream as google/google-java-format#1217, raised by JBang's author, and for the first line as google/google-java-format#1215 and google/google-java-format#1218. jbangdev/jbang#1194 asked JBang to accept The bugJBang reads a script's configuration from line comments with the directive name right after the slashes, and a shell runs the first line when the file is executed. The formatter put a space after the slashes of every line comment and wrapped the long ones: /// usr/bin/env jbang "$0" "$@" ; exit $? // JAVA 21+ // DEPS info.picocli:picocli:4.7.6 // DEPS com.fasterxml.jackson.core:jackson-databind:2.17.2 org.slf4j:slf4j-simple:2.0.13 // com.squareup.okhttp3:okhttp:4.12.0 org.jsoup:jsoup:1.18.1 // JAVA_OPTIONS -Xmx512m JBang no longer saw any of it. The dependencies, the Java version and the options were dropped without a word, and a shell tried to run Where directives countJBang's directives reference says a directive "must be in the first comment block of the file (before any code)". Its parser is more lenient: This change follows the documented rule, which keeps the exemption narrow. A directive after the first line of code is formatted like any other comment, as before. The fix
The helper now takes the What stays as before:
Checked
VersionOnly lines that come out broken today, a directive JBang no longer reads or a first line the shell cannot run, format differently. That makes this a bug fix in the 2.x sense, although the output for such files now differs from palantir-java-format 2.98.0.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsJBang reads a script's configuration from line comments with the name right after the slashes, such as //DEPS, //JAVA and //SOURCES, and a shell runs the first line, ///usr/bin/env jbang "$0" "$@" ; exit $?, when the file is executed. The formatter put a space after the slashes of every line comment and wrapped long ones, so JBang silently dropped the dependencies and options, and the file no longer ran from a shell (#24, reported upstream as google/google-java-format#1217). JBang's documentation places directives "in the first comment block of the file (before any code)". There, JavaCommentsHelper now leaves two kinds of line comment exactly as written, with no space and no wrapping: a directive, which is one of the names in JBang's Directives.Names or a name with an integration prefix such as Quarkus's //Q:CONFIG, followed by whitespace or the end of the line; and the first line of the file when its first word is a path, as in ///usr/bin/env, //usr/bin/env or the long self-bootstrapping header. The helper now takes the JavaInput, whose first token marks where the code starts, since comments are numbered along with tokens. After the package declaration, an import or a class, the same text is an ordinary comment again, and //DEPSSS, //deps or //TODO still get their space everywhere. JBang's parser is more lenient than its documentation and reads every line that starts with // at column 0, so a directive after the imports still stops working; that follows the documented rule on purpose. Three goldens cover whole scripts: the one from the issue, one with a package and a license header, and a compact source file. JBangDirectivesTest checks every directive name, the syntax JBang allows after one, and comments that only look like directives. The 15,747 files of the JDK 21 sources format exactly as before; none of them has a directive or a shell line. Uh oh!
There was an error while loading. Please reload this page.
abashev
added a commit
to openjavaformat/docs
that referenced
this pull request
The JBang change of 2.98.0.5 goes on the list as the bug fix it is, although code that palantir-java-format has already formatted keeps its "// DEPS" and does not move: whoever migrates JBang scripts needs to know. The formatter handled a script's header wrongly. The space after the slashes hid //DEPS and the other directives from JBang, and the first line no longer ran from a shell. The item says so, links the JBang page, and says that spaces an earlier run added have to be removed by hand. The corpus paragraph now says the JBang fix changes nothing in the JDK 21 sources, which formatted identically with and without it when the fix was made (openjavaformat/open-java-format#91). The GitHub Action page gives 2.98.0.5 as the default of the version input, as the action's main branch now does (openjavaformat/open-java-format-action@80a52bb).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ReviewersNo reviewsUh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabels
None yet
ProjectsMilestoneNo milestoneDevelopmentSuccessfully merging this pull request may close these issues. Do not rewrite JBang directives: //DEPS becomes // DEPS and the script loses its dependenciesUh oh!
There was an error while loading. Please reload this page. Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later. |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |