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

feature: add LogsafeArgName errorprone rule #1459

Merged
merged 4 commits into from
Jul 29, 2020
Merged

Conversation

ferozco
Copy link
Contributor

@ferozco ferozco commented Jul 28, 2020

Before this PR

Occasionally developers would incorrectly tag a known unsafe parameter (ex. branch, username) as safe.

After this PR

==COMMIT_MSG==
add LogsafeArgName errorprone rule which allows users to specify a list of argument names that must always be tagged as unsafe.
==COMMIT_MSG==

This isn't a perfect solution since developers may use a different name for an unsafe value, but this should help catch some cases.

The expectation is that we will configure the set of unsafe arg names internally.

Possible downsides?

N/A

@ferozco ferozco requested a review from carterkozak July 28, 2020 15:42
return buildDescription(tree)
.setMessage("Arguments with name '" + argName + "' must be marked as unsafe.")
.addFix(SuggestedFix.builder()
.replace(tree.getMethodSelect(), "UnsafeArg.of")
Copy link
Contributor

Choose a reason for hiding this comment

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

SuggestedFixes.qualifyType on "com.palantir.logsafe.UnsafeArg" will add the import automagically, or fully qualify the type if there happens to be a foo.bar.UnsafeArg already imported. We can append ".of" to the result.


public final class LogsafeArgNameTest {
private CompilationTestHelper compilationHelper;
private RefactoringValidator refactoringHelper;
Copy link
Contributor

Choose a reason for hiding this comment

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

Slight preference to use factory methods for these, that way we can fluently build the test from the factory.
I recall some of the preconditions tests attempting multiple asserts on a shared helper and getting unexpected results because these guys are stateful!

@ferozco
Copy link
Contributor Author

ferozco commented Jul 28, 2020

I'd like to merge the associated internal PR first so that excavator will correctly apply the fix on baseline upgrades

Copy link
Contributor

@carterkozak carterkozak left a comment

Choose a reason for hiding this comment

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

lgtm, merge when you're ready.

@bulldozer-bot bulldozer-bot bot merged commit 06031fb into develop Jul 29, 2020
@bulldozer-bot bulldozer-bot bot deleted the fo/logsafe-arg-name branch July 29, 2020 14:52
@svc-autorelease
Copy link
Collaborator

Released 3.36.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.

3 participants