This is an archive of the discontinued LLVM Phabricator instance.

clang-format: Builder closing paren must be a call
Needs ReviewPublic

Authored by ono on May 4 2015, 5:34 AM.

Details

Reviewers
djasper
Summary

We should somehow ensure that builder type call segment is preceded by a
closing parenthesis that comes from a call not a type cast or anything else.

Before:

(aaaa)
    .aaaaaaaaaaaaaaa()
    .aaaaaaaaaaaaaaa()
    .aaaaaaaaaaaaaaa()
    .aaaaaaaaaaaaaaa()
    .aaaaaaaaaaaaaaa();

After:

(aaaa).aaaaaaaaaaaaaaa()
    .aaaaaaaaaaaaaaa()
    .aaaaaaaaaaaaaaa()
    .aaaaaaaaaaaaaaa()
    .aaaaaaaaaaaaaaa();

Some more real life example:

Before:

- (bool)isALabelWithText:(NSString *)anyCaseText {
  return [((UILabel *)self)
              .someLabelText isEqualToString:[anyCaseText toVeryUpperCase]];
}

After:

- (bool)isALabelWithText:(NSString *)anyCaseText {
  return [((UILabel *)self).someLabelText
      isEqualToString:[anyCaseText toVeryUpperCase]];
}

Diff Detail

Event Timeline

ono updated this revision to Diff 24876.May 4 2015, 5:34 AM
ono retitled this revision from to clang-format: Builder closing paren must be a call.
ono updated this object.
ono edited the test plan for this revision. (Show Details)
ono added a reviewer: djasper.
ono added subscribers: ono, curdeius, klimek, Unknown Object (MLST).
ono updated this object.May 4 2015, 5:35 AM
djasper edited edge metadata.May 4 2015, 6:24 AM

I am not sure this is the right direction. We have actually considered going the other way, i.e. do builder-type wrapping even after the first element, i.e.:

aaaaaaaa
    .aaaaaa()
    .bbbbbb();

There were some edge cases where I got stuck a bit, so I haven't proceeded. But engraining this more seems wrong. The given example seems wrong for other reasons, in particular, we should force wrapping the parameters/selectors if the callee spans multiple lines.

ono added a comment.May 4 2015, 8:13 AM

I am not sure this is the right direction. We have actually considered going the other way, i.e. do builder-type wrapping even after the first element, i.e.:

aaaaaaaa
    .aaaaaa()
    .bbbbbb();

There were some edge cases where I got stuck a bit, so I haven't proceeded. But engraining this more seems wrong. The given example seems wrong for other reasons, in particular, we should force wrapping the parameters/selectors if the callee spans multiple lines.

I may agree with that if it is constrained to something, like either a break if preceded with a real call or it is followed by real call. Current implementation expects (looking at the tests) that element preceding dot (and the break) if the call.

Now you give a sample that actually the stuff following a break and dot is a call. Either or is okay, but not:

aaaaaaaaa
    .bbbbbbbbb
    .cccccccccc

This is just accessing fields, not builder call.