Title: Do not rewrite JBang directives: //DEPS becomes // DEPS and the script loses its dependencies · Issue #24 · openjavaformat/open-java-format · GitHub
Open Graph Title: Do not rewrite JBang directives: //DEPS becomes // DEPS and the script loses its dependencies · Issue #24 · openjavaformat/open-java-format
X Title: Do not rewrite JBang directives: //DEPS becomes // DEPS and the script loses its dependencies · Issue #24 · openjavaformat/open-java-format
Description: What happens JBang reads its configuration from line comments that must start with // immediately followed by the keyword: //DEPS, //JAVA, //SOURCES, //FILES, //JAVA_OPTIONS and so on. A script usually also starts with ///usr/bin/env jba...
Open Graph Description: What happens JBang reads its configuration from line comments that must start with // immediately followed by the keyword: //DEPS, //JAVA, //SOURCES, //FILES, //JAVA_OPTIONS and so on. A script usu...
X Description: What happens JBang reads its configuration from line comments that must start with // immediately followed by the keyword: //DEPS, //JAVA, //SOURCES, //FILES, //JAVA_OPTIONS and so on. A script usu...
Opengraph URL: https://github.com/openjavaformat/open-java-format/issues/24
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Do not rewrite JBang directives: //DEPS becomes // DEPS and the script loses its dependencies","articleBody":"### What happens\n\n[JBang](https://www.jbang.dev) reads its configuration from line comments that must start with `//` immediately followed by the keyword: `//DEPS`, `//JAVA`, `//SOURCES`, `//FILES`, `//JAVA_OPTIONS` and so on. A script usually also starts with `///usr/bin/env jbang \"$0\" \"$@\" ; exit $?`, which makes the file runnable from a shell and is still a comment for javac.\n\nThe formatter rewrites all of them. Reproduced with 2.98.0.1, jar and native binary alike:\n\n```java\n///usr/bin/env jbang \"$0\" \"$@\" ; exit $?\n//JAVA 21+\n//DEPS info.picocli:picocli:4.7.6\n//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\n//JAVA_OPTIONS -Xmx512m\n\n```\n\nbecomes\n\n```java\n/// usr/bin/env jbang \"$0\" \"$@\" ; exit $?\n// JAVA 21+\n// DEPS info.picocli:picocli:4.7.6\n// DEPS com.fasterxml.jackson.core:jackson-databind:2.17.2 org.slf4j:slf4j-simple:2.0.13\n// com.squareup.okhttp3:okhttp:4.12.0 org.jsoup:jsoup:1.18.1\n// JAVA_OPTIONS -Xmx512m\n\n```\n\nThree separate things go wrong:\n\n1. **A space is added after the slashes**, so `//DEPS` becomes `// DEPS`. JBang no longer sees the directive: the dependencies, the Java version and the options are silently dropped, and the script stops compiling.\n2. **The first line gets a space too**, `/// usr/bin/env …`, which breaks running the script directly from a shell.\n3. **A long directive is wrapped** at 120 columns. Even without the space, the second half of the dependency list would end up in an ordinary comment.\n\n### Why\n\n`JavaCommentsHelper.wrapLineComments` adds the missing space with `LINE_COMMENT_MISSING_SPACE_PREFIX`, which exempts only `//noinspection` and `//$NON-NLS-n$`, and then wraps every line comment that is too long. `doc/Comment.computeFlat()` adds the same space on the path where the helper is not called at all, see #23.\n\n### Today's workaround\n\nExclude the scripts. The GitHub Action and the pre-commit hook read `.open-java-format-exclude`, and their README uses exactly this case as the example. That keeps CI green but leaves JBang scripts unformatted.\n\n### Proposal\n\nLeave JBang directives and the `///usr/bin/env` line exactly as written: no inserted space, no wrapping.\n\nThe rule has to be narrow. A blanket \"do not touch `//WORD`\" would stop `//TODO` from becoming `// TODO` and change the output of ordinary code. Two ways to keep it narrow:\n\n- a fixed list of JBang keywords, taken from JBang's documentation, or\n- any `//KEYWORD` line, but only in a file that JBang would treat as a script, for example one that starts with the `///usr/bin/env jbang` line or contains `//DEPS` or `//JAVA`.\n\n### Compatibility\n\nFor a JBang script the current output is a broken script, so nobody depends on it. With a narrow rule nothing else changes. It still differs from palantir-java-format 2.98.0 for these files, which the 2.x promise has to allow for explicitly.\n\n### Related\n\n- google/google-java-format#1217, by JBang's author, asks for the same thing there and is open.\n- google/google-java-format#1218 and google/google-java-format#1215 are about the `///` first line.\n- jbangdev/jbang#1194 asked JBang to accept `// DEPS` instead. It was closed with the view that a formatter should not add a space where there was none.\n- #22 brings compact source files and instance `main` methods, which JBang scripts use a lot.\n","author":{"url":"https://github.com/abashev","@type":"Person","name":"abashev"},"datePublished":"2026-09-21T13:51:12Z","url":"https://github.com/openjavaformat/open-java-format/issues/24"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:6773fad0-b650-d6c0-2e68-8cb69a4b8fae |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 898A:8FDF6:5F429E:7EA69D:6AFBC73A |
| html-safe-nonce | ade72df9e6e876b5b491435b3c5b9c65774fb2dc37cd6023ddbba89c09c1e4b8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OThBOjhGREY2OjVGNDI5RTo3RUE2OUQ6NkFGQkM3M0EiLCJ2aXNpdG9yX2lkIjoiMzQ3NzIxMjc5OTI4NTE4NDU4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 8ee488d0deb97801d3ad6223b74a07ff8f80d472ff8db8eab6cf9ada76f8a123 |
| hovercard-subject-tag | issue:5527893858 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/openjavaformat/open-java-format/24/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0e3fe9babde87801629bcdfdf4c9045443e6027c8a54baed32ea0a536ea5b911/openjavaformat/open-java-format/issues/24 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0e3fe9babde87801629bcdfdf4c9045443e6027c8a54baed32ea0a536ea5b911/openjavaformat/open-java-format/issues/24 |
| og:image:alt | What happens JBang reads its configuration from line comments that must start with // immediately followed by the keyword: //DEPS, //JAVA, //SOURCES, //FILES, //JAVA_OPTIONS and so on. A script usu... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | abashev |
| hostname | github.com |
| expected-hostname | github.com |
| None | d440bda0d812801778b27bfe9f7c1ce9ff22420c73f6f95150c4fcbca311c50b |
| turbo-cache-control | no-preview |
| go-import | github.com/openjavaformat/open-java-format git https://github.com/openjavaformat/open-java-format.git |
| octolytics-dimension-user_id | 325177626 |
| octolytics-dimension-user_login | openjavaformat |
| octolytics-dimension-repository_id | 1288055459 |
| octolytics-dimension-repository_nwo | openjavaformat/open-java-format |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | true |
| octolytics-dimension-repository_parent_id | 214273098 |
| octolytics-dimension-repository_parent_nwo | palantir/palantir-java-format |
| octolytics-dimension-repository_network_root_id | 214273098 |
| octolytics-dimension-repository_network_root_nwo | palantir/palantir-java-format |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2c43021aed8695990c86c0eaaedc600bfeffec36 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width