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

Formatter conflicts with "Only one statement per line" checkstyle rule #17637

Closed
michael-simons opened this issue Jul 25, 2019 · 5 comments
Closed
Labels
for: external-project For an external project and not something we can fix status: superseded An issue that has been superseded by another

Comments

@michael-simons
Copy link
Contributor

michael-simons commented Jul 25, 2019

I have the following code:

try (Session session = this.driver.session();
		Transaction tx = session.beginTransaction()) {
		// Do something
}

Spring Java Format complains

 Formatting violations found in the following files:
 * /Users/msimons/Projects/spring-projects/spring-boot/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/neo4j/Neo4jDriverAutoConfigurationIntegrationTests.java

Run `spring-javaformat:apply` to fix.

Fix turns the snippet into

try (Session session = this.driver.session(); Transaction tx = session.beginTransaction()) {
}

Checkstyle complains OneStatementPerLine.

I have no clue how to format the thing.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 25, 2019
@snicoll snicoll changed the title spring-javaformat:apply not accomplishable. Formatter conflicts with "Only one statement per line" checkstyle rule Jul 25, 2019
@snicoll
Copy link
Member

snicoll commented Jul 25, 2019

@philwebb can you please transfer the issue to the spring-javaformat project?

@michael-simons
Copy link
Contributor Author

There are examples where the formatter accepts this style.

org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfigurationTests#onlyRegisteredOnceWhenThereIsAChildContext

Difference here: The second autoclosable doesn't depend on the first.

@philwebb
Copy link
Member

can you please transfer the issue to the spring-javaformat project?

Apparently not! The GitHub UI doesn't seem to offer it to me. Perhaps it's because it's part of a different organization. I'll do a brute force copy paste.

We actually hit it ourselves (see this comment) and in the end decided that fixing it would take more effort than refactoring the code to use multiple try blocks.

@michael-simons can you use the following form for now?

try (Session session = this.driver.session()) {
    try (Transaction tx = session.beginTransaction()) {
        // Do something
    }
}

@philwebb
Copy link
Member

@michael-simons
Copy link
Contributor Author

michael-simons can you use the following form for now?

Of course.

@wilkinsona wilkinsona added for: external-project For an external project and not something we can fix status: superseded An issue that has been superseded by another and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix status: superseded An issue that has been superseded by another
Projects
None yet
Development

No branches or pull requests

5 participants