facebookarchive / pfff

Tools for code analysis, visualizations, or style-preserving source transformation.
http://github.com/facebook/pfff/wiki/Main
Other
2.44k stars 205 forks source link

[spatch] Meta variables reformatted during patching #140

Closed aik099 closed 5 years ago

aik099 commented 8 years ago

Patch code:

-X = $this->Application->recallObject(Y1, Y2, Y3);
+X =& $this->Application->recallObject(Y1, Y2, Y3);

Code that is patched:

<?php

$var = $this->Application->recallObject('test', null, array('key' => true));

After fixing the array('key' => true) becomes array('key'=>true) (spaces before and after => are removed). I think this is incorrect to reformat code, that shouldn't be fixed as part of the patching.

aryx commented 8 years ago

Yes, this issue is mentioned on the wiki: https://github.com/facebook/pfff/wiki/Spatch#spacing-issues

You can avoid the issue by rewriting the patch as X

aik099 commented 8 years ago

@aryx , can you please use fenced code blocks, because GitHub has formatted your suggestion as Markdown and I get what was changed.

Also I'm not sure, but using (...) doesn't work and error is displayed. Because of that I hard to create 2 patches: one for mandatory arguments and one for mandatory + optional arguments.

aik099 commented 8 years ago

I've tried rewriting patch like so:

-X = $this->Application->recallObject(Y1, Y2, Y3)
+X =&
 $this->Application->recallObject(Y1, Y2, Y3)

but I'm getting an error:

Fatal error: exception Failure("could not parse: X = $this->Application->recallObject(Y1, Y2, Y3)\n\n$this->Application->recallObject(Y1, Y2, Y3)\n")
aik099 commented 8 years ago

The following patch:

-X
+X =&
 $this->Application->recallObject(Y1, Y2, Y3)

gives this error:

Fatal error: exception Failure("could not parse: X\n\n $this->Application->recallObject(Y1, Y2, Y3)\n")
aryx commented 8 years ago
  X
- =
+ =& 
  $this->Application->recallObject(Y1, Y2, Y3);
aik099 commented 8 years ago

Thanks, that worked perfectly.

I'm not sure why, but following was also done (spaces after comma in list(...) construct):

list(
-               $product_id, $backorder, $qty, $price, , , , $order_item_id, $options_salt, $item_data, $cost
+               $product_id, $backorder, $qty, $price,,,, $order_item_id, $options_salt, $item_data, $cost
                ) = $operation_row;