This is an archive of the discontinued LLVM Phabricator instance.

clang-format: [JS] remove trailing lines in arrow functions.
ClosedPublic

Authored by mprobst on Nov 17 2017, 7:56 AM.

Details

Summary

clang-format already removes lines trailing at the end of blocks:

function x() {
  foo();  // next line will be removed.

}

However because JS arrow functions are parsed as expressions, the existing logic
to remove empty lines in UnwrappedLineFormatter doesn't handle them. This code
special cases arrow functions in ContinuationIndenter to remove any trailing
spaces:

x = () => {
  foo();  // next line will (now) be removed.

};

Event Timeline

mprobst created this revision.Nov 17 2017, 7:56 AM
djasper edited edge metadata.Nov 17 2017, 8:29 AM

Is this different for C++ lambdas? I would think that we never should add an empty line before the "}" of a child block.

mprobst updated this revision to Diff 123367.Nov 17 2017, 9:42 AM
  • handle C++ lambdas
  • handle preceding empty lines

Is this different for C++ lambdas? I would think that we never should add an empty line before the "}" of a child block.

Actually indeed turns out to be identical for C++ lambdas. Fixed as we discussed offline.

mprobst updated this revision to Diff 123368.Nov 17 2017, 9:48 AM
  • reduce test cases a bit, no need to separate before/after cases
djasper accepted this revision.Nov 17 2017, 9:49 AM

Looks good. There is a chance that some people do not want this in their coding style. But if so, we can add an option later.

This revision is now accepted and ready to land.Nov 17 2017, 9:49 AM
mprobst updated this revision to Diff 123370.Nov 17 2017, 9:58 AM
  • document the meaning if Children.size() == 0 in this context.
mprobst updated this revision to Diff 123371.Nov 17 2017, 9:59 AM
  • prefer !x.empty() over .size() > 0.
This revision was automatically updated to reflect the committed changes.