-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[clang-format] Add BreakFunctionDeclarationParameters option #158745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2389,6 +2389,20 @@ struct FormatStyle { | |
/// \version 19 | ||
bool BreakFunctionDefinitionParameters; | ||
|
||
/// If ``true``, clang-format will always break before function declaration | ||
/// parameters. | ||
/// \code | ||
/// true: | ||
/// void functionDeclaration( | ||
/// int A, int B); | ||
/// | ||
/// false: | ||
/// void functionDeclaration(int A, int B); | ||
/// | ||
/// \endcode | ||
/// \version 22 | ||
bool BreakFunctionDeclarationParameters; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please sort the option (here and elsewhere) alphabetically. |
||
|
||
/// Break after each annotation on a field in Java files. | ||
/// \code{.java} | ||
/// true: false: | ||
|
@@ -5497,6 +5511,8 @@ struct FormatStyle { | |
BreakConstructorInitializers == R.BreakConstructorInitializers && | ||
BreakFunctionDefinitionParameters == | ||
R.BreakFunctionDefinitionParameters && | ||
BreakFunctionDeclarationParameters == | ||
R.BreakFunctionDeclarationParameters && | ||
BreakInheritanceList == R.BreakInheritanceList && | ||
BreakStringLiterals == R.BreakStringLiterals && | ||
BreakTemplateDeclarations == R.BreakTemplateDeclarations && | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1083,6 +1083,8 @@ template <> struct MappingTraits<FormatStyle> { | |
Style.BreakConstructorInitializers); | ||
IO.mapOptional("BreakFunctionDefinitionParameters", | ||
Style.BreakFunctionDefinitionParameters); | ||
IO.mapOptional("BreakFunctionDeclarationParameters", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to add a parsing test for this. |
||
Style.BreakFunctionDeclarationParameters); | ||
IO.mapOptional("BreakInheritanceList", Style.BreakInheritanceList); | ||
IO.mapOptional("BreakStringLiterals", Style.BreakStringLiterals); | ||
IO.mapOptional("BreakTemplateDeclarations", | ||
|
@@ -1617,6 +1619,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) { | |
LLVMStyle.BreakBinaryOperations = FormatStyle::BBO_Never; | ||
LLVMStyle.BreakConstructorInitializers = FormatStyle::BCIS_BeforeColon; | ||
LLVMStyle.BreakFunctionDefinitionParameters = false; | ||
LLVMStyle.BreakFunctionDeclarationParameters = false; | ||
LLVMStyle.BreakInheritanceList = FormatStyle::BILS_BeforeColon; | ||
LLVMStyle.BreakStringLiterals = true; | ||
LLVMStyle.BreakTemplateDeclarations = FormatStyle::BTDS_MultiLine; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8143,6 +8143,39 @@ TEST_F(FormatTest, BreakFunctionDefinitionParameters) { | |
Input, Style); | ||
} | ||
|
||
TEST_F(FormatTest, BreakFunctionDeclarationParameters) { | ||
StringRef Input = "void functionDecl(paramA, paramB, paramC);\n" | ||
"void emptyFunctionDefinition() {}\n" | ||
"void functionDefinition(int A, int B, int C) {}\n" | ||
"Class::Class(int A, int B) : m_A(A), m_B(B) {}"; | ||
verifyFormat(Input); | ||
|
||
FormatStyle Style = getLLVMStyle(); | ||
EXPECT_FALSE(Style.BreakFunctionDeclarationParameters); | ||
Style.BreakFunctionDeclarationParameters = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. your documentation suggest that having this as false, doesn't break, but actually almost looks like it "joins" the lines, but looking at the code I can't see that is the case, does false really mean "Leave" or "join"...could you add a test if you mean Join but also move it to an enum so we can have a "Leave" case.. How does this interact with other options? doing similar things.. |
||
verifyFormat("void functionDecl(\n" | ||
" paramA, paramB, paramC);\n" | ||
"void emptyFunctionDefinition() {}\n" | ||
"void functionDefinition(int A, int B, int C) {}\n" | ||
"class Class {\n" | ||
" Class(\n" | ||
" int A, int B);\n" | ||
"};\n", | ||
Input, Style); | ||
|
||
// Test the style where all parameters are on their own lines. | ||
Style.AllowAllParametersOfDeclarationOnNextLine = false; | ||
Style.BinPackParameters = FormatStyle::BPPS_OnePerLine; | ||
verifyFormat("void functionDecl(\n" | ||
" paramA,\n" | ||
" paramB,\n" | ||
" paramC);\n" | ||
"void emptyFunctionDefinition() {}\n" | ||
"void functionDefinition(int A, int B, int C) {}\n" | ||
"Class::Class(int A, int B) : m_A(A), m_B(B) {}", | ||
Input, Style); | ||
} | ||
|
||
TEST_F(FormatTest, BreakBeforeInlineASMColon) { | ||
FormatStyle Style = getLLVMStyle(); | ||
Style.BreakBeforeInlineASMColon = FormatStyle::BBIAS_Never; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't quite tell but it feel like true is "AlwaysBreakFunctionDeclarationParameters" because false doesn't feel like NeverBreak... just depends on what is there currently?