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

Introduce BugCheckerRules Refaster rule collection #526

Merged
merged 5 commits into from
Mar 23, 2023

Conversation

Ptijohn
Copy link
Contributor

@Ptijohn Ptijohn commented Mar 10, 2023

Suggested commit message:

Introduce `BugCheckerRule` refaster rules (#526)


/** Refaster rules related to BugChecker classes. */
@OnlineDocumentation
final class BugCheckerRules {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly not sure about the reach of this class 🤔
I could also limit it to BugCheckerRefactoringTestHelper, but then it's also quite closed.
That would also impact docs and all.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good question. In the past we have dodged questions such as this one by locating single rules in AssortedRules. I'll add an extra rule so that the new rule isn't feeling lonely ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hahaha, yeah I saw this class and hesitated, but felt like doing this was cleaner ;)
Thanks for the added rule 💪

@Ptijohn Ptijohn requested a review from rickie March 10, 2023 09:36
@github-actions
Copy link

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link
Member

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a commit. Suggested commit message:

Introduce `BugCheckerRules` Refaster rule collection (#526)

@@ -37,7 +37,6 @@
<dependency>
<groupId>${groupId.error-prone}</groupId>
<artifactId>error_prone_test_helpers</artifactId>
<scope>test</scope>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to pull in test dependencies at runtime; this should become provided.

* Drop {@link BugCheckerRefactoringTestHelper#setFixChooser(FixChooser)} when set to the default
* {@link FixChoosers#FIRST}.
*/
static final class SetFixChooserDefault {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that with our upcoming automated Refaster rule naming scheme this class would be named BugCheckerRefactoringTestHelperIdentity. (Due to side-effects this isn't fully accurate, but alas.) We can extend this rule to cover .setImportOrder("static-first").

}

BugCheckerRefactoringTestHelper testSetFixChooserDefault() {
return BugCheckerRefactoringTestHelper.newInstance(StringCaseLocaleUsage.class, getClass())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return BugCheckerRefactoringTestHelper.newInstance(StringCaseLocaleUsage.class, getClass())
return BugCheckerRefactoringTestHelper.newInstance(BugChecker.class, getClass())


/** Refaster rules related to BugChecker classes. */
@OnlineDocumentation
final class BugCheckerRules {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good question. In the past we have dodged questions such as this one by locating single rules in AssortedRules. I'll add an extra rule so that the new rule isn't feeling lonely ;)

@github-actions
Copy link

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Comment on lines +37 to +39
// XXX: This rule assumes that the full source code is specified as a single string, e.g. using a
// text block. Support for multi-line source code input would require a `BugChecker`
// implementation instead.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now this rule won't match, but after #198 it'll be relevant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Stephan202 💪

@Stephan202 Stephan202 added this to the 0.9.0 milestone Mar 12, 2023
@rickie rickie force-pushed the bdiederichs/fix-choosers-first branch from 74a3a4d to 68fac51 Compare March 22, 2023 17:30
Copy link
Member

@rickie rickie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a commit with Javadoc tweak and rebased.

Maybe we can consider adding something for BugCheckerRefactoringTestHelper#setArgs for the case where we pass an ImmutableList and have only one string. Could be nicer to drop immutableList in that case. If the setArgs is called with multiple strings we can opt for the ImmutableList variant. WDYT? (out of scope in any case though)

Apart from that, it looks really good 👍🏻, nice to see that it drops a few of these occurrences 😄.

Thanks for picking up @Ptijohn 🚀 !

private BugCheckerRules() {}

/**
* Avoid calling {@link BugCheckerRefactoringTestHelper#setFixChooser(FixChooser)} with the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should update this to also account for setImportOrder. Will propose something :).

@github-actions
Copy link

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@Stephan202
Copy link
Member

Changes LGTM 👍

W.r.t. setArgs: yes, that one is on my list of things to do. That case is not really Refaster-compatible (using @Repeated won't work); instead I'm thinking of introducing a bug checker that simplifies unary methods calls with an ImmutableList.of/Arrays.asList (or similar) argument, for which a varargs overload exists.

@rickie rickie force-pushed the bdiederichs/fix-choosers-first branch from 68fac51 to 7e05c73 Compare March 22, 2023 17:56
@rickie
Copy link
Member

rickie commented Mar 22, 2023

Nice, sounds like a good idea 👍🏻 . Rebased, will merge once 🟢.

@github-actions
Copy link

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@rickie rickie changed the title Introduce BugCheckerRule refaster rules Introduce BugCheckerRules Refaster rule collection Mar 23, 2023
@rickie rickie merged commit 8f1d1df into master Mar 23, 2023
@rickie rickie deleted the bdiederichs/fix-choosers-first branch March 23, 2023 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants