Skip to content

Conversation

@gatesn
Copy link
Contributor

@gatesn gatesn commented Apr 16, 2020

Before this PR

I was refactoring a Gradle plugin to start using Providers and got hit by this too many times.

After this PR

Implicit use of a Provider as a String is forbidden.

Possible downsides?

No auto-fix

@changelog-app
Copy link

changelog-app bot commented Apr 16, 2020

Generate changelog in changelog/@unreleased

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Forbid implicit toString of Gradle Providers.

Check the box to generate changelog(s)

  • Generate changelog entry

@policy-bot policy-bot bot requested a review from CRogers April 16, 2020 08:32
" }",
"}")
.doTest();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I would just add a second test to check that toString on non-providers is not broken.

Copy link
Contributor

@CRogers CRogers left a comment

Choose a reason for hiding this comment

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

Nice, I like this

name = "GradleProviderToString",
summary = "Calling toString on a Provider does not render the contained value",
severity = BugPattern.SeverityLevel.ERROR)
public final class GradleProviderToString extends AbstractToString {
Copy link
Contributor

Choose a reason for hiding this comment

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

oh this is just too easy :D

@Override
protected Optional<Fix> implicitToStringFix(ExpressionTree tree, VisitorState state) {
// We could automatically call Provider#get, but is that always right?
return Optional.empty();
Copy link
Contributor

Choose a reason for hiding this comment

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

if it's right enough of the time, we could do it for convenience. We don't need to automatically apply it.

@stale
Copy link

stale bot commented Apr 30, 2020

This PR has been automatically marked as stale because it has not been touched in the last 14 days. If you'd like to keep it open, please leave a comment or add the 'long-lived' label, otherwise it'll be closed in 7 days.

@stale stale bot added the stale label Apr 30, 2020
@stale stale bot removed the stale label May 6, 2020
@gatesn
Copy link
Contributor Author

gatesn commented May 6, 2020

Think I've addressed comments now

@stale
Copy link

stale bot commented May 20, 2020

This PR has been automatically marked as stale because it has not been touched in the last 14 days. If you'd like to keep it open, please leave a comment or add the 'long-lived' label, otherwise it'll be closed in 7 days.

@stale stale bot added the stale label May 20, 2020
@bulldozer-bot bulldozer-bot bot merged commit 2420fcc into develop May 29, 2020
@bulldozer-bot bulldozer-bot bot deleted the ngates/implicit-provider-to-string branch May 29, 2020 10:26
@svc-autorelease
Copy link
Collaborator

Released 3.17.0

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants