]> granicus.if.org Git - clang/commitdiff
[clang-format] Keep protobuf "package" statement on one line
authorPaul Hoad <mydeveloperday@gmail.com>
Sat, 23 Mar 2019 14:43:41 +0000 (14:43 +0000)
committerPaul Hoad <mydeveloperday@gmail.com>
Sat, 23 Mar 2019 14:43:41 +0000 (14:43 +0000)
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)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356835 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTestProto.cpp

index ccf5e51576d33f153ab5b111e34163648b59d65e..a3000a8fdeb0f9abcde692edc18651f6a98dd151 100644 (file)
@@ -1119,10 +1119,10 @@ public:
       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;
index d5683b5b844fb8905546f46f574d758ab06a8017..fd4870c27f2b9fe22aae37db212c65510c9e25ea 100644 (file)
@@ -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"