[clang] [clang-format]: Add `Custom` to `ShortFunctionStyle`; add new AllowShortFunctionsOnASingleLineOptions for granular setup (PR #134337)
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Mon May 12 00:13:04 PDT 2025
================
@@ -5685,11 +5685,27 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
if (Right.is(tok::r_brace) && Left.is(tok::l_brace) &&
!Left.Children.empty()) {
// Support AllowShortFunctionsOnASingleLine for JavaScript.
- return Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_None ||
- Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_Empty ||
- (Left.NestingLevel == 0 && Line.Level == 0 &&
- Style.AllowShortFunctionsOnASingleLine &
- FormatStyle::SFS_InlineOnly);
+ const auto &shortFuncConfig = Style.AllowShortFunctionsOnASingleLine;
+
+ // SFS_All
+ if (shortFuncConfig.isAll())
+ return false;
+
+ // SFS_None and SFS_Empty
+ if (shortFuncConfig == FormatStyle::ShortFunctionStyle{})
+ return true;
+
+ // SFS_Empty
+ if (shortFuncConfig == FormatStyle::ShortFunctionStyle{/*Empty=*/true,
+ /*Inline=*/false,
+ /*Other=*/false}) {
+ return true;
+ }
+
+ if (Left.NestingLevel == 0 && Line.Level == 0)
+ return shortFuncConfig.Inline && !shortFuncConfig.Other;
+
+ return shortFuncConfig.Other;
----------------
owenca wrote:
```suggestion
if (Left.NestingLevel == 0 && Line.Level == 0)
return !Style.AllowShortFunctionsOnASingleLine.Other;
return !Style.AllowShortFunctionsOnASingleLine.Inline;
```
https://github.com/llvm/llvm-project/pull/134337
More information about the cfe-commits
mailing list