-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove unused local variables despite potential side effects after re…
…moving feature flag (#35) * feat(test): added failing test for RemoveUnusedLocalVariables * Enable removal of local variables with side effects * Repeat removal of unused local variables if needed --------- Co-authored-by: Shannon Pamperl <[email protected]> Co-authored-by: Tim te Beek <[email protected]>
- Loading branch information
1 parent
91d1862
commit e481645
Showing
3 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,6 +178,87 @@ void bar() { | |
); | ||
} | ||
|
||
@Test | ||
void removeUnusedLDContextWithBuilder() { | ||
rewriteRun( | ||
// language=java | ||
java( | ||
""" | ||
import com.launchdarkly.sdk.*; | ||
import com.launchdarkly.sdk.server.*; | ||
class Foo { | ||
LDClient client = new LDClient("sdk-key-123abc"); | ||
void bar() { | ||
LDContext context = LDContext.builder("context-key-123abc") | ||
.name("Sandy") | ||
.build(); | ||
if (client.boolVariation("flag-key-123abc", context, false)) { | ||
// Application code to show the feature | ||
System.out.println("Feature is on"); | ||
} | ||
else { | ||
// The code to run if the feature is off | ||
System.out.println("Feature is off"); | ||
} | ||
} | ||
} | ||
""", | ||
""" | ||
import com.launchdarkly.sdk.server.*; | ||
class Foo { | ||
LDClient client = new LDClient("sdk-key-123abc"); | ||
void bar() { | ||
// Application code to show the feature | ||
System.out.println("Feature is on"); | ||
} | ||
} | ||
""" | ||
) | ||
); | ||
} | ||
|
||
@Test | ||
void removeUnusedLDContextWithBuilderContext() { | ||
rewriteRun( | ||
// language=java | ||
java( | ||
""" | ||
import com.launchdarkly.sdk.*; | ||
import com.launchdarkly.sdk.server.*; | ||
class Foo { | ||
LDClient client = new LDClient("sdk-key-123abc"); | ||
void bar() { | ||
LDContext ldContext = LDContext.create("newValue"); | ||
LDContext context = LDContext.builderFromContext(ldContext) | ||
.anonymous(false) | ||
.name("name") | ||
.set("email", "[email protected]") | ||
.build(); | ||
if (client.boolVariation("flag-key-123abc", context, false)) { | ||
// Application code to show the feature | ||
System.out.println("Feature is on"); | ||
} | ||
else { | ||
// The code to run if the feature is off | ||
System.out.println("Feature is off"); | ||
} | ||
} | ||
} | ||
""", | ||
""" | ||
import com.launchdarkly.sdk.server.*; | ||
class Foo { | ||
LDClient client = new LDClient("sdk-key-123abc"); | ||
void bar() { | ||
// Application code to show the feature | ||
System.out.println("Feature is on"); | ||
} | ||
} | ||
""" | ||
) | ||
); | ||
} | ||
|
||
@Test | ||
void enablePermanentlyWithParameters() { | ||
rewriteRun( | ||
|