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

Sort entries of RefasterRuleCollectionTestCase#elidedTypesAndStaticImports #321

Open
1 of 2 tasks
rickie opened this issue Oct 28, 2022 · 0 comments
Open
1 of 2 tasks
Assignees
Labels

Comments

@rickie
Copy link
Member

rickie commented Oct 28, 2022

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

  • 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 participants