-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[clang-format] Option to insert spaces before the closing */
#162105
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 |
---|---|---|
|
@@ -4684,6 +4684,15 @@ struct FormatStyle { | |
/// \version 17 | ||
bool SpaceBeforeJsonColon; | ||
|
||
/// If ``true``, a space is inserted immediately before the closing ``*/`` in | ||
/// block comments that contain content. | ||
/// \code | ||
/// true: false: | ||
/// /* comment */ vs. /* comment*/ | ||
/// \endcode | ||
/// \version 21 | ||
bool SpaceBeforeClosingBlockComment; | ||
|
||
/// Different ways to put a space before opening parentheses. | ||
enum SpaceBeforeParensStyle : int8_t { | ||
/// This is **deprecated** and replaced by ``Custom`` below, with all | ||
|
@@ -5611,6 +5620,7 @@ struct FormatStyle { | |
SpaceAroundPointerQualifiers == R.SpaceAroundPointerQualifiers && | ||
SpaceBeforeRangeBasedForLoopColon == | ||
R.SpaceBeforeRangeBasedForLoopColon && | ||
SpaceBeforeClosingBlockComment == R.SpaceBeforeClosingBlockComment && | ||
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. Alphabetic ordering please |
||
SpaceBeforeSquareBrackets == R.SpaceBeforeSquareBrackets && | ||
SpaceInEmptyBraces == R.SpaceInEmptyBraces && | ||
SpacesBeforeTrailingComments == R.SpacesBeforeTrailingComments && | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -332,6 +332,53 @@ TEST_F(FormatTestComments, UnderstandsSingleLineComments) { | |
verifyNoCrash(StringRef("/*\\\0\n/", 6)); | ||
} | ||
|
||
TEST_F(FormatTestComments, InsertsSpaceBeforeClosingBlockComment) { | ||
FormatStyle Style = getLLVMStyle(); | ||
Style.SpaceBeforeClosingBlockComment = true; | ||
|
||
verifyFormat("foo(/* comment */);", "foo(/* comment*/);", Style); | ||
verifyFormat("foo(/*Logger= */nullptr);", "foo(/*Logger=*/nullptr);", Style); | ||
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. I think I want to handle this different from comments |
||
verifyFormat("/* comment */", Style); | ||
verifyFormat("/* comment before code */\nint x;", | ||
"/* comment before code*/\nint x;", Style); | ||
verifyFormat("/* comment\n */", "/* comment\n*/", Style); | ||
verifyFormat("/* comment\n */\nint x;", "/* comment\n*/\nint x;", Style); | ||
verifyFormat("/*\ncomment line\n */", "/*\ncomment line\n*/", Style); | ||
verifyFormat("/*\n * comment star\n */", "/*\n * comment star\n*/", Style); | ||
verifyFormat("/* comment line\nnext */", "/* comment line\nnext*/", Style); | ||
verifyFormat("/*\n*/", Style); | ||
verifyFormat("/*\n\n*/", "/*\n \n*/", Style); | ||
verifyFormat("/*This is a multi line comment\n" | ||
"this is the next line\n" | ||
"and this is the 3th line. */", | ||
"/*This is a multi line comment\n" | ||
"this is the next line\n" | ||
"and this is the 3th line.*/", | ||
Style); | ||
verifyFormat( | ||
"/*\n * Another multi line comment\n * this is the next line. */", | ||
"/*\n * Another multi line comment\n * this is the next line.*/", Style); | ||
} | ||
|
||
TEST_F(FormatTestComments, BlockCommentDoesNotForceBreakBeforeFollowingToken) { | ||
FormatStyle Style = getLLVMStyle(); | ||
Style.SpaceBeforeClosingBlockComment = true; | ||
|
||
verifyFormat("switch (n) {\n" | ||
"case 1:\n" | ||
" foo();\n" | ||
"/*FALLTHROUGH */ case 2:\n" | ||
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. Do we want to handle "/*" while we are at it.. |
||
" bar();\n" | ||
"}\n", | ||
"switch (n) {\n" | ||
"case 1:\n" | ||
" foo();\n" | ||
" /*FALLTHROUGH*/ case 2:\n" | ||
" bar();\n" | ||
"}\n", | ||
Style); | ||
} | ||
|
||
TEST_F(FormatTestComments, KeepsParameterWithTrailingCommentsOnTheirOwnLine) { | ||
EXPECT_EQ("SomeFunction(a,\n" | ||
" b, // comment\n" | ||
|
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 think we want options to handle this differently.
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.
Needs to have at least Space, NoSpace, Leave because the default of false is going to now remove spaces everywhere
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.
All options normally go through a phase boolean -> enum -> struct I think in this case we should short circuit straight to struct
struct SpaceInComments
{
AfterOpeningComment = Leave
BeforeClosingComment = Leave
AfterOpeningParamComment = Leave
BeforeCloseingParamComment = No // I think this is the current behavior
}