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 leaves extra blank line when removing imports #788

Closed
toweroy opened this issue May 19, 2022 · 2 comments
Closed

Formatter leaves extra blank line when removing imports #788

toweroy opened this issue May 19, 2022 · 2 comments

Comments

@toweroy
Copy link

toweroy commented May 19, 2022

What happens

When running the formatter against a class that will remove unused import(s) and would remove all imports of that type, the formatter leaves the surrounding empty lines. So for example:

package com.test;

import java.util.HashSet;
import java.util.Set;

public class ClassA {
  
}

The resulting formatted code leaves an empty line:

package com.test;


public class ClassA {}

Which will cause errors when checking the formatting.

What we expected

Formatter would leave a single empty line instead of two. Like so:

package com.test;

public class ClassA {}

Extra info

The line will be removed if the formatter is executed again.

@tbroyer
Copy link
Contributor

tbroyer commented May 19, 2022

It looks like calling the formatter once again on that resulting file will remove the extra line.

Looks like an ordering issue between the formatter itself (which will remove the extra line) and the "remove unused imports" phase: "remove unused imports" will remove whole lines, but then when removing the whole imports block it leaves the blank lines before and after alone, and this phase is run after the formatter which would collapse the consecutive blank lines. Reversing the two phases would likely fix this issue, but maybe there's a reason to remove unused imports after formatting the file (formatting shouldn't remove code, so unused imports shouldn't change before and after, and it should be safe to reverse the phases IMO)

@cushon
Copy link
Collaborator

cushon commented Dec 11, 2023

#598

@cushon cushon closed this as completed Dec 11, 2023
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

3 participants