Skip to content

clang-format for obj-c lines up colons inside @selector #145673

Open
@zmodem

Description

@zmodem

Consider:

$ cat /tmp/a.mm
- (void)setSearchBarText:(NSString*)text {
  _searchBar.text = text;
  if ([_searchBar.delegate respondsToSelector:@selector(searchBar:textDidChange:)]) {
    [_searchBar.delegate searchBar:_searchBar textDidChange:text];
  } 
}

$ build/bin/clang-format /tmp/a.mm
- (void)setSearchBarText:(NSString *)text {
  _searchBar.text = text;
  if ([_searchBar.delegate respondsToSelector:@selector(searchBar:
                                                    textDidChange:)]) {
    [_searchBar.delegate searchBar:_searchBar textDidChange:text];
  }
}

To break the long line, clang-format aligned searchBar: and textDidChange: on the colons, but breaking up the @selector(searchBar:textDidChange:) argument doesn't seem great. Perhaps it would have been better to break the line before respondsToSelector: instead, something like:

- (void)setSearchBarText:(NSString*)text {
  _searchBar.text = text;
  if ([_searchBar.delegate
        respondsToSelector:@selector(searchBar:textDidChange:)]) {
    [_searchBar.delegate searchBar:_searchBar textDidChange:text];
  } 
}

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions