Skip to content
This repository has been archived by the owner on Jun 4, 2019. It is now read-only.

Commit

Permalink
spatch: remove trailing comment when everything else in the line was …
Browse files Browse the repository at this point in the history
…removed

Summary: Just added unit tests, the previous diff already handled this case.

Test Plan:
unit test included
$ ./spatch -test

Reviewers: pieter, ptarjan, julienv, zoel

Reviewed By: pieter

CC: rmcelroy, ahupp

Differential Revision: https://phabricator.fb.com/D651188
  • Loading branch information
pad committed Dec 7, 2012
1 parent f7141ea commit b7a6b33
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lang_php/parsing/unparse_php.ml
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ let drop_esthet_between_removed xs =
in
outside_remove xs

(* note that it will also remove comments in the line if everthing else
* was removed, which is what we want most of the time
*)
let drop_whole_line_if_only_removed xs =
let (before_first_newline, xxs) = xs +> Common.group_by_pre (function
| Esthet Newline -> true | _ -> false)
Expand All @@ -251,13 +254,13 @@ let drop_whole_line_if_only_removed xs =
let has_a_remove =
elts_after_newline +> List.exists (function
| Removed _ -> true | _ -> false) in
let only_remove_or_space =
let only_remove_or_esthet =
elts_after_newline +> List.for_all (function
| Esthet _ | Removed _ -> true
| Added _ | OrigElt _ -> false
)
in
has_a_remove && only_remove_or_space
has_a_remove && only_remove_or_esthet
)
in
before_first_newline ++
Expand Down
8 changes: 8 additions & 0 deletions tests/php/spatch/remove_trailing_comment.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

1;
2;
3;
4;
// this should be kept
// this should be kept too
14 changes: 14 additions & 0 deletions tests/php/spatch/remove_trailing_comment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

1;
foo(1); // I'm a clown
2;
foo(
1);
3;
foo(1); /* I'm a
really bad clown */
4;
// this should be kept
foo(1); // this should be removed
// this should be kept too
1 change: 1 addition & 0 deletions tests/php/spatch/remove_trailing_comment.spatch
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- foo(X);

0 comments on commit b7a6b33

Please sign in to comment.