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

incompatibility with google-java-format: File Header not separated by blank line from package statement #14655

Closed
sdavids opened this issue Mar 12, 2024 · 3 comments

Comments

@sdavids
Copy link

sdavids commented Mar 12, 2024

/var/tmp $ curl -L -O -s https://github.com/checkstyle/checkstyle/releases/download/checkstyle-10.14.1/checkstyle-10.14.1-all.jar
/var/tmp $ curl -L -O -s https://github.com/google/google-java-format/releases/download/v1.21.0/google-java-format-1.21.0-all-deps.jar
/var/tmp $ printf '/* File header */\npackage p; class PackageHeader{}\n' > PackageHeader.java
/var/tmp $ cat PackageHeader.java                                                                                                                    
/* File header */
package p; class PackageHeader{}
/var/tmp $ java -jar google-java-format-1.21.0-all-deps.jar --replace PackageHeader.java
/var/tmp $ javac PackageHeader.java
/var/tmp $ cat PackageHeader.java
/* File header */
package p;

class PackageHeader {}
/var/tmp $ RUN_LOCALE="-Duser.language=en -Duser.country=US"
/var/tmp $ java $RUN_LOCALE -jar checkstyle-10.14.1-all.jar -c /google_checks.xml PackageHeader.java
Starting audit...
[WARN] /private/tmp/PackageHeader.java:2:1: 'package' should be separated from previous line. [EmptyLineSeparator]
Audit done.

Code formatted by google-java-format (the de-facto standard Google Java Style formatter) should be compatible with the google_checks.xml configuration out-of-the-box.

@romani
Copy link
Member

romani commented Mar 15, 2024

Life is changing defacto :), few years ago people told same about checkstyle config.

But lets look at style guide
https://google.github.io/styleguide/javaguide.html#s3-source-file-structure

Source file structure
A source file consists of, in order:
License or copyright information, if present
Package statement
Import statements
Exactly one top-level class
Exactly one blank line separates each section that is present.

Pay attention to last sentence. How you can explain it ? May be we should open issue on google-java-format ?

@sdavids
Copy link
Author

sdavids commented Mar 16, 2024

google/google-java-format#1084

@sdavids sdavids changed the title incompatibility with google-java-format: File Header not seperated by space from package statement incompatibility with google-java-format: File Header not separated by blank line from package statement Mar 16, 2024
@romani
Copy link
Member

romani commented Mar 17, 2024

I think we are done here, we can reopen issue if new nuances comes up

@romani romani closed this as completed Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants