error-prone-support icon indicating copy to clipboard operation
error-prone-support copied to clipboard

Sort entries of `RefasterRuleCollectionTestCase#elidedTypesAndStaticImports`

Open rickie opened this issue 1 year ago • 0 comments

Problem

For every Refaster Rule collection we have a corresponding *Test{Input,Output}.java file where we test the Refaster rules. These test classes implement the RefasterRuleCollectionTestCase interface that contains the elidedTypesAndStaticImports method. This method exists to ensure that the same import statements are (still) required in the *TestOutput file. Without this, the import(s) could become unused due to the patching of Refaster rules (and therefore removed when running the formatter).

We highly value consistency and therefore always sort the arguments that are passed to the ImmutableSet#of (see example below). To enforce this, I propose to make changes to the RefasterRuleCollection class and verify the sorting of these arguments there. If the sorting is incorrect, it should suggest the correct order as fix.

Description of the proposed new feature

  • [x] Support a stylistic preference.
  • [ ] Avoid a common gotcha, or potential problem.

I would like to rewrite the following code:

@Override
public ImmutableSet<?> elidedTypesAndStaticImports() {
  return ImmutableSet.of(Lists.class, Iterables.class);
}

to:

@Override
public ImmutableSet<?> elidedTypesAndStaticImports() {
return ImmutableSet.of(Iterables.class, Lists.class);
}

Considerations

This check is rather specific to Error Prone Support itself.

The content of the ImmutableSet can be basically everything, that might make the sorting a bit challenging?

Maybe we should go one step further and ensure that the expression of the elidedTypesAndStaticImports is always return ImmutableSet.of(...);?

Participation

This request can be picked up by anyone willing to work on it.

rickie avatar Oct 28 '22 11:10 rickie