uber / piranha

A tool for refactoring code related to feature flag APIs
Apache License 2.0
2.29k stars 198 forks source link

can we add string with double quotes in treated function #629

Open eankit opened 1 year ago

eankit commented 1 year ago

Can a string with double quotes be cleaned by polygot poranha, code snipped below, If yes, how ?

void demoMethod(ExperimentAPI experiment){ // Some code if (experiment.isTreated("STALE_FLAG")) { // Do something } else { // Do something else } // Do other things }

ketkarameya commented 1 year ago

https://github.com/uber/piranha/pull/630 I added a demo with your example.
Give it a try

eankit commented 9 months ago

@ketkarameya thanks this works.

can you also help me with this use case as well // Some code if (experiment.isTreated(someObject, "STALE_FLAG")) { // Do something } else { // Do something else } // Do other things }

ketkarameya commented 8 months ago

@eankit i will have to know more about your API to help you. Can you please DM me ?

eankit commented 8 months ago

Hey @ketkarameya My issue is this if (experiment.isTreated(arg1, arg2, "STALE_FLAG")) { // Do something } else { // Do something else } I want to run Piranha on this api. Here we have a simple feature flag string with a few arguments in the function. I tried hardcoding the argument and it worked, but I want to understand how to work with a variable argument list. Also, I saw in rules.toml file that you work on argument list for a simple example, something of a similar solution is expected for the String flag name. _arguments: ((argument_list ([ (fieldaccess field: ()@argument) () @argument ])) )

eankit commented 8 months ago

Also, I want to understand how can I write my own query like the following, do you have any documentation for this? query='cs :[e].isFeatureEnabled("@flag_name")', For example, I want to skip the experiment. in experiment.isTreated("STALE_FLAG") and work with only isTreated("STALE_FLAG") how can that be done

ketkarameya commented 8 months ago

Unfortunately there is no documentation for concrete syntax.

(
(method_invocation (argument_list (string_literal (_) @flag_name) @string_literal)) @mi
(#eq? @flag_name "@flag_name")
)

equivalent concrete syntax is :[r].isTreated(:[a0], :[a1], ":[flag_name]")