This is an archive of the discontinued LLVM Phabricator instance.

clang-format: [JS] ignore comments when wrapping returns.
ClosedPublic

Authored by mprobst on Sep 6 2016, 8:24 AM.

Details

Summary

When code contains a comment between return and the value:

return /* lengthy comment here */ (
    lengthyValueComesHere);

Do not wrap before the comment, as that'd break the code through JS' automatic
semicolon insertion.

Diff Detail

Event Timeline

mprobst updated this revision to Diff 70405.Sep 6 2016, 8:24 AM
mprobst retitled this revision from to clang-format: [JS] ignore comments when wrapping returns..
mprobst updated this object.
mprobst added a reviewer: djasper.
mprobst added a subscriber: cfe-commits.
mprobst added inline comments.Sep 6 2016, 8:25 AM
lib/Format/TokenAnnotator.cpp
2384

Should the entire method generally consider the previous non-comment, instead of just the previous token? Not sure if that makes sense in all cases, and I don't think we always have a previous non-comment token either.

djasper accepted this revision.Sep 6 2016, 11:46 AM
djasper edited edge metadata.

Looks good.

lib/Format/TokenAnnotator.cpp
2384

Lets leave this as is for now. Yes, some of these should likely look past comments, but probably not all of them.

This revision is now accepted and ready to land.Sep 6 2016, 11:46 AM
This revision was automatically updated to reflect the committed changes.