[clang] [clang-format] Fix a regression on BAS_AlwaysBreak (PR #107506)

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 5 19:46:18 PDT 2024


https://github.com/owenca created https://github.com/llvm/llvm-project/pull/107506

Fixes #107401.

>From bd7da6ec9afabd829010db4c33d088590ab68b5a Mon Sep 17 00:00:00 2001
From: Owen Pan <owenpiano at gmail.com>
Date: Thu, 5 Sep 2024 19:44:46 -0700
Subject: [PATCH] [clang-format] Fix a regression on BAS_AlwaysBreak

Fixes #107401.
---
 clang/lib/Format/ContinuationIndenter.cpp | 2 +-
 clang/unittests/Format/FormatTestJS.cpp   | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index 5843571718b3a2..f65c1640a8765a 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -861,7 +861,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
       //  or
       //  caaaaaaaaaaaaaaaaaaaaal(
       //       new SomethingElseeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee());
-      !IsSimpleFunction(Current)) {
+      Current.isNot(tok::comment) && !IsSimpleFunction(Current)) {
     CurrentState.NoLineBreak = true;
   }
 
diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp
index 4b29ba720f6823..a0b663170c7b33 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -2850,5 +2850,13 @@ TEST_F(FormatTestJS, DontBreakFieldsAsGoToLabels) {
                "};");
 }
 
+TEST_F(FormatTestJS, BreakAfterOpenBracket) {
+  auto Style = getGoogleStyle(FormatStyle::LK_JavaScript);
+  EXPECT_EQ(Style.AlignAfterOpenBracket, FormatStyle::BAS_AlwaysBreak);
+  verifyFormat("ctrl.onCopy(/** @type {!WizEvent}*/ (\n"
+               "    {event, targetElement: {el: () => selectedElement}}));",
+               Style);
+}
+
 } // namespace format
 } // end namespace clang



More information about the cfe-commits mailing list