]> granicus.if.org Git - clang/commitdiff
Revert "Revert "[clang-format] Keep protobuf "package" statement on one line""
authorKrasimir Georgiev <krasimir@google.com>
Fri, 10 May 2019 09:15:11 +0000 (09:15 +0000)
committerKrasimir Georgiev <krasimir@google.com>
Fri, 10 May 2019 09:15:11 +0000 (09:15 +0000)
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

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

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

index ddaacaab777511f38e7ff758db2077353ac4ab71..4e255700d4dc08d602ef01209852f607ed52c475 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)) {
         while (CurrentToken)
index ac042316bc29140160a5b6082ad1a9b109362f65..4258c169e884efd7f0ae385814cb5281fa48d40a 100644 (file)
@@ -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"