google / google/error-prone

Feature - Option to remove associated whitespace for SuggestedFix.Builder `replace` and `delete`

Open
#2,500 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
7.2k
Forks
820
Avg merge
5h 9m
Merged PRs (30d)
50

Description

OK so I want to start out by saying I understand the philosophy behind error-prone and it not wanting to replace the usage of a tool like a code formatter.

That said, there are some minor issues that a code formatter can't solve.

Lets say I had some code like the following and we found an unused variable, as an example bug checker:
```java
public class Person {
private String favoritePhrase = "Hello World!";
private int favoriteFlavor = "Strawberry"; // unused
private int favoriteNumber = 45;

private double height = 4.5;
private double weight = 100;
...
}
```

OK so error prone analyzes my code and gives me something like the following output:
```java
public class Person {
private String favoritePhrase = "Hello World!";

private int favoriteNumber = 45;

private double height = 4.5;
private double weight = 100;
...
}
```

But now the code has lost its organization. `favorite` related fields now have an extra line break between them, and a code formatter can't detect this to clean it up.

I would love for this to be a configurable option for error prone, to allow for cleanup of that extra whitespace, but please let me know if this is something out of scope for error-prone to do.

Happy to submit a PR myself, but I will need to check with y'all first if my corporate Google CLA is good for error-prone, since it wasn't specifically signed for error-prone.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.