[clang] [clang-format] Add new option: WrapNamespaceBodyWithNewlines (PR #106145)

Björn Schäpers via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 28 11:27:30 PDT 2024


================
@@ -5057,6 +5057,21 @@ struct FormatStyle {
   /// \version 11
   std::vector<std::string> WhitespaceSensitiveMacros;
 
+  /// Insert a newline at the begging and at the end of namespace definition
+  /// \code
+  ///   false:                           vs.      true:
+  ///
+  ///   namespace a {                             namespace a {
+  ///   namespace b {                             namespace b {
+  ///     function();
+  ///   }                                         function();
+  ///   }
+  ///                                             }
+  ///                                             }
+  /// \endcode
+  /// \version 19
+  bool WrapNamespaceBodyWithNewlines;
----------------
HazardyKnusperkeks wrote:

> Could you confirm my guess about behavior of this options?
> 
>     * Always: fixes all namespaces with 1 additional newline at the begging and at the end of namespace

Sets a minimum of empty lines to 1 (still has to obey max empty lines, if there were more than 1).

>     * Never:   removes all newlines at the begging and at the end of namespace

Yes.

>     * Leave:   doesn't affect this aspect of user code(uses other options for formatting like 'MaxEmptyLinesToKeep')

Yes.


https://github.com/llvm/llvm-project/pull/106145


More information about the cfe-commits mailing list