facebookincubator / Bowler

Safe code refactoring for modern Python.
https://pybowler.io/
MIT License
1.53k stars 89 forks source link

`modify_argument` loses the trailing `,` in call arguments #147

Open perrinjerome opened 1 year ago

perrinjerome commented 1 year ago

With this code:

funccall(
  a='1',
  b='2',
  c='3',
)

and running this codmod:

$ bowler do 'Query(".").select_function("funccall").modify_argument("a", "aa")'
--- ./bug.py
+++ ./bug.py
@@ -1,6 +1,6 @@

 funccall(
-  a='1',
+  aa='1',
   b='2',
-  c='3',
+  c='3'
 )

the trailing comma on c=3, is not kept. I would expect that it is kept.

If we agree that would be the expected behavior and that you are willing to review a pull request I can try to take a look.

I think this happens around here: https://github.com/facebookincubator/Bowler/blob/92c9eeb7eebab8a1b65a989d0cf3b4947773ea2b/bowler/imr.py#L238

and that this code could be changed to check if self.capture['function_arguments'][0].children[-1] is a comma and add it to arguments if that's the case.

Thanks !

pioneerHitesh commented 9 months ago

@perrinjerome can you assign this to me?

perrinjerome commented 9 months ago

@pioneerHitesh I cannot, I think only people with write access can do this