-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[clang-format] Add ObjCSpaceBeforeMethodDeclColon option to control space before Objective-C method return type #170579
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
5961395
f373c40
f10f688
dedca65
9818413
7664855
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 |
|---|---|---|
|
|
@@ -3936,6 +3936,16 @@ struct FormatStyle { | |
| /// \version 3.7 | ||
| bool ObjCSpaceAfterProperty; | ||
|
|
||
| /// Add or remove a space between the '-'/'+' and the return type in | ||
| /// Objective-C method declarations. i.e | ||
| /// \code{.objc} | ||
| /// false: true: | ||
| /// | ||
| /// -(void)method vs. - (void)method | ||
| /// \endcode | ||
| /// \version 22 | ||
| bool ObjCSpaceBeforeMethodDeclColon; | ||
|
|
||
| /// Add a space in front of an Objective-C protocol list, i.e. use | ||
| /// ``Foo <Protocol>`` instead of ``Foo<Protocol>``. | ||
| /// \version 3.7 | ||
|
|
@@ -5772,6 +5782,7 @@ struct FormatStyle { | |
| R.ObjCBreakBeforeNestedBlockParam && | ||
| ObjCPropertyAttributeOrder == R.ObjCPropertyAttributeOrder && | ||
| ObjCSpaceAfterProperty == R.ObjCSpaceAfterProperty && | ||
| ObjCSpaceBeforeMethodDeclColon == R.ObjCSpaceBeforeMethodDeclColon && | ||
|
Contributor
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. Still one line up. :) |
||
| ObjCSpaceBeforeProtocolList == R.ObjCSpaceBeforeProtocolList && | ||
| OneLineFormatOffRegex == R.OneLineFormatOffRegex && | ||
| PackConstructorInitializers == R.PackConstructorInitializers && | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -15623,6 +15623,22 @@ TEST_F(FormatTest, FormatForObjectiveCMethodDecls) { | |||||||||||||||
| verifyGoogleFormat("- foo:(int)foo;"); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| TEST_F(FormatTest, SpaceBeforeObjCMethodDeclColon) { | ||||||||||||||||
| FormatStyle Style = getLLVMStyle(); | ||||||||||||||||
| verifyFormat("- (void)method;", "-(void)method;", Style); | ||||||||||||||||
|
Contributor
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.
Suggested change
Should suffice, or what is the benefit of the other tests? |
||||||||||||||||
| verifyFormat("+ (int)foo:(int)x;", "+ (int) foo:(int)x;", Style); | ||||||||||||||||
| verifyFormat("- foo;", "-foo;", Style); | ||||||||||||||||
| verifyFormat("- foo:(int)f;", "-foo:(int)f;", Style); | ||||||||||||||||
|
|
||||||||||||||||
|
Comment on lines
+15627
to
+15632
Contributor
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.
Suggested change
|
||||||||||||||||
| Style.ObjCSpaceBeforeMethodDeclColon = false; | ||||||||||||||||
| verifyFormat("-(void)method;", "- (void) method;", Style); | ||||||||||||||||
|
Contributor
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.
Suggested change
Same here.
Author
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. Just wanted to confirm that these changes don’t impact any other code paths. I aimed to cover all possible combinations. |
||||||||||||||||
| verifyFormat("+(int)foo:(int)x;", "+ (int)foo:(int)x;", Style); | ||||||||||||||||
| verifyFormat("+(int)foo:(int)x;", "+ (int)foo:(int)x;", Style); | ||||||||||||||||
|
|
||||||||||||||||
| verifyFormat("-foo;", "- foo;", Style); | ||||||||||||||||
| verifyFormat("-foo:(int)f;", "- foo:(int)f;", Style); | ||||||||||||||||
|
Comment on lines
+15635
to
+15639
Contributor
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. Delete. |
||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| TEST_F(FormatTest, BreaksStringLiterals) { | ||||||||||||||||
| // FIXME: unstable test case | ||||||||||||||||
| EXPECT_EQ("\"some text \"\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.
How about
ObjCSpaceAfterMethodDeclarationPrefixinstead?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.
Its good suggestion i will update it thanks :)