Skip to content

Commit

Permalink
[clang-format] Keep protobuf "package" statement on one line
Browse files Browse the repository at this point in the history
Summary:
Top-level "package" and "import" statements should generally be kept on one
line, for all languages.

Reviewers: sammccall, krasimir, MyDeveloperDay

Reviewed By: MyDeveloperDay

Subscribers: MyDeveloperDay, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D59627

Patch By: dchai (Donald Chai)

llvm-svn: 356835
  • Loading branch information
mydeveloperday committed Mar 23, 2019
1 parent c6deae4 commit f5e5273
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1119,10 +1119,10 @@ class AnnotatingParser {
return LT_ImportStatement;
}

// In .proto files, top-level options are very similar to import statements
// and should not be line-wrapped.
// In .proto files, top-level options and package statements are very
// similar to import statements and should not be line-wrapped.
if (Style.Language == FormatStyle::LK_Proto && Line.Level == 0 &&
CurrentToken->is(Keywords.kw_option)) {
CurrentToken->isOneOf(Keywords.kw_option, Keywords.kw_package)) {
next();
if (CurrentToken && CurrentToken->is(tok::identifier))
return LT_ImportStatement;
Expand Down
6 changes: 6 additions & 0 deletions clang/unittests/Format/FormatTestProto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,12 @@ TEST_F(FormatTestProto, FormatsOptions) {
"};");
}

TEST_F(FormatTestProto, DoesntWrapPackageStatements) {
verifyFormat(
"package"
" some.really.long.package.that.exceeds.the.column.limit00000000;");
}

TEST_F(FormatTestProto, FormatsService) {
verifyFormat("service SearchService {\n"
" rpc Search(SearchRequest) returns (SearchResponse) {\n"
Expand Down

0 comments on commit f5e5273

Please sign in to comment.