facebookarchive / pfff

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

Micro clone detection for boolean expressions #143

Closed rvantonder closed 8 years ago

rvantonder commented 8 years ago

I hope this project is still active enough to take PRs :) I found pfff useful for detecting micro clones (small snippets of repeated expressions or statements). I added support for finding these in PHP boolean expressions. For example:

if ($input_data['type'] != 'scalar' && $input_data['type'] != 'scalar') {...}

These errors are quite common, and it has found over a hundred cases in the top 1,000 PHP repositories on github (many of which are inactive though). Here is a collection of issues in active, popular (lots of stars) PHP github repositories that were fixed or are being fixed. Please see the commit message and files for further description.

Only PHP is supported in this PR, partly because it was most suitable to add this initially to scheck. The approach can be generalized to other languages (I have an experimental branch for Javascript).

There's also lots of room for extensions, including detecting other forms of micro clones (duplicate statements, duplicate conditional bodies, etc.) and generating patches based on detection.

This PR includes tests integrated into scheck -test and make test.

ghost commented 8 years ago

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks!

ghost commented 8 years ago

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

aryx commented 8 years ago

This is great! Thank you.