Skip to content

Commit

Permalink
Revert "Revert "[clang-format] Keep protobuf "package" statement on o…
Browse files Browse the repository at this point in the history
…ne line""

Summary:
Top-level "package" and "import" statements should generally be kept on
one line, for all languages.

----

This reverts commit rL356912.
The regression from rL356835 was fixed via rC358275.

Reviewers: krasimir, sammccall, MyDeveloperDay, xinz, dchai, klimek

Reviewed By: krasimir, xinz, dchai

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 360411
  • Loading branch information
krasimirgg authored and MrSidims committed May 17, 2019
1 parent c6c893c commit a25fddc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions clang/lib/Format/TokenAnnotator.cpp
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)) {
while (CurrentToken)
Expand Down
10 changes: 10 additions & 0 deletions clang/unittests/Format/FormatTestProto.cpp
Expand Up @@ -397,6 +397,16 @@ TEST_F(FormatTestProto, FormatsOptions) {
"};");
}

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

TEST_F(FormatTestProto, TrailingCommentAfterPackage) {
verifyFormat("package foo.pkg; // comment\n");
}

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

0 comments on commit a25fddc

Please sign in to comment.