-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[clang-format]: Add Custom
to ShortFunctionStyle
; add new AllowShortFunctionsOnASingleLineOptions for granular setup
#134337
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
Open
irymarchyk
wants to merge
15
commits into
llvm:main
Choose a base branch
from
irymarchyk:add_custom_AllowShortFunctionsOnASingleLine
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
df25a8b
[clang-format]: Add `Custom` to `ShortFunctionStyle`; add new AllowSh…
e9e4e92
PR-134337: fixed PR comments
b1fd412
Updated configuration with new suggestion - reuse existing option
7f80e4a
fixed documentation error
bbe2273
Fixed PR comments
5ff5810
marked options as deprecated
70eafea
fixed PR comments
dd6493d
added usage of 'other'
03fd9e9
Merge remote-tracking branch 'origin/main' into add_custom_AllowShort…
3c0fa14
fixed ShortFunctionStyle.Other case for JS
7825f53
fixed first comment - simplified code
9dbd674
removed code related to Only Other option
9917b99
fixed PR comments
d7ad2a8
added one forgotten change
323f38b
Merge branch 'main' into add_custom_AllowShortFunctionsOnASingleLine
irymarchyk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -613,15 +613,38 @@ template <> struct ScalarEnumerationTraits<FormatStyle::ShortBlockStyle> { | |||||
} | ||||||
}; | ||||||
|
||||||
template <> struct ScalarEnumerationTraits<FormatStyle::ShortFunctionStyle> { | ||||||
static void enumeration(IO &IO, FormatStyle::ShortFunctionStyle &Value) { | ||||||
IO.enumCase(Value, "None", FormatStyle::SFS_None); | ||||||
IO.enumCase(Value, "false", FormatStyle::SFS_None); | ||||||
IO.enumCase(Value, "All", FormatStyle::SFS_All); | ||||||
IO.enumCase(Value, "true", FormatStyle::SFS_All); | ||||||
IO.enumCase(Value, "Inline", FormatStyle::SFS_Inline); | ||||||
IO.enumCase(Value, "InlineOnly", FormatStyle::SFS_InlineOnly); | ||||||
IO.enumCase(Value, "Empty", FormatStyle::SFS_Empty); | ||||||
template <> struct MappingTraits<FormatStyle::ShortFunctionStyle> { | ||||||
static void enumInput(IO &IO, FormatStyle::ShortFunctionStyle &Value) { | ||||||
IO.enumCase(Value, "None", FormatStyle::ShortFunctionStyle({})); | ||||||
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
Ditto below and in other files as well. |
||||||
IO.enumCase(Value, "Empty", | ||||||
FormatStyle::ShortFunctionStyle({/*Empty=*/true, | ||||||
/*Inline=*/false, | ||||||
/*Other=*/false})); | ||||||
IO.enumCase(Value, "Inline", | ||||||
FormatStyle::ShortFunctionStyle({/*Empty=*/true, | ||||||
/*Inline=*/true, | ||||||
/*Other=*/false})); | ||||||
IO.enumCase(Value, "InlineOnly", | ||||||
FormatStyle::ShortFunctionStyle({/*Empty=*/false, | ||||||
/*Inline=*/true, | ||||||
/*Other=*/false})); | ||||||
IO.enumCase(Value, "All", | ||||||
FormatStyle::ShortFunctionStyle({/*Empty=*/true, | ||||||
/*Inline=*/true, | ||||||
/*Other=*/true})); | ||||||
|
||||||
// For backward compatibility. | ||||||
IO.enumCase(Value, "true", | ||||||
FormatStyle::ShortFunctionStyle({/*Empty=*/true, | ||||||
/*Inline=*/true, | ||||||
/*Other=*/true})); | ||||||
IO.enumCase(Value, "false", FormatStyle::ShortFunctionStyle({})); | ||||||
owenca marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} | ||||||
|
||||||
static void mapping(IO &IO, FormatStyle::ShortFunctionStyle &Value) { | ||||||
IO.mapOptional("Empty", Value.Empty); | ||||||
IO.mapOptional("Inline", Value.Inline); | ||||||
IO.mapOptional("Other", Value.Other); | ||||||
} | ||||||
}; | ||||||
|
||||||
|
@@ -1500,7 +1523,10 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) { | |||||
LLVMStyle.AllowShortCaseLabelsOnASingleLine = false; | ||||||
LLVMStyle.AllowShortCompoundRequirementOnASingleLine = true; | ||||||
LLVMStyle.AllowShortEnumsOnASingleLine = true; | ||||||
LLVMStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All; | ||||||
LLVMStyle.AllowShortFunctionsOnASingleLine = | ||||||
FormatStyle::ShortFunctionStyle({/*Empty=*/true, | ||||||
owenca marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
/*Inline=*/true, | ||||||
/*Other=*/true}); | ||||||
LLVMStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never; | ||||||
LLVMStyle.AllowShortLambdasOnASingleLine = FormatStyle::SLS_All; | ||||||
LLVMStyle.AllowShortLoopsOnASingleLine = false; | ||||||
|
@@ -1787,7 +1813,10 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) { | |||||
GoogleStyle.AlignOperands = FormatStyle::OAS_DontAlign; | ||||||
GoogleStyle.AlignTrailingComments = {}; | ||||||
GoogleStyle.AlignTrailingComments.Kind = FormatStyle::TCAS_Never; | ||||||
GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty; | ||||||
GoogleStyle.AllowShortFunctionsOnASingleLine = | ||||||
FormatStyle::ShortFunctionStyle({/*Empty=*/true, | ||||||
/*Inline=*/false, | ||||||
/*Other=*/false}); | ||||||
GoogleStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never; | ||||||
GoogleStyle.AlwaysBreakBeforeMultilineStrings = false; | ||||||
GoogleStyle.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment; | ||||||
|
@@ -1797,7 +1826,10 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) { | |||||
} else if (Language == FormatStyle::LK_JavaScript) { | ||||||
GoogleStyle.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak; | ||||||
GoogleStyle.AlignOperands = FormatStyle::OAS_DontAlign; | ||||||
GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty; | ||||||
GoogleStyle.AllowShortFunctionsOnASingleLine = | ||||||
FormatStyle::ShortFunctionStyle({/*Empty=*/true, | ||||||
/*Inline=*/false, | ||||||
/*Other=*/false}); | ||||||
// TODO: still under discussion whether to switch to SLS_All. | ||||||
GoogleStyle.AllowShortLambdasOnASingleLine = FormatStyle::SLS_Empty; | ||||||
GoogleStyle.AlwaysBreakBeforeMultilineStrings = false; | ||||||
|
@@ -1814,7 +1846,10 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) { | |||||
GoogleStyle.NamespaceIndentation = FormatStyle::NI_All; | ||||||
GoogleStyle.SpacesInContainerLiterals = false; | ||||||
} else if (Language == FormatStyle::LK_Proto) { | ||||||
GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty; | ||||||
GoogleStyle.AllowShortFunctionsOnASingleLine = | ||||||
FormatStyle::ShortFunctionStyle({/*Empty=*/true, | ||||||
/*Inline=*/false, | ||||||
/*Other=*/false}); | ||||||
GoogleStyle.AlwaysBreakBeforeMultilineStrings = false; | ||||||
// This affects protocol buffer options specifications and text protos. | ||||||
// Text protos are currently mostly formatted inside C++ raw string literals | ||||||
|
@@ -1833,7 +1868,10 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) { | |||||
GoogleStyle.IncludeStyle.IncludeBlocks = | ||||||
tooling::IncludeStyle::IBS_Preserve; | ||||||
} else if (Language == FormatStyle::LK_CSharp) { | ||||||
GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty; | ||||||
GoogleStyle.AllowShortFunctionsOnASingleLine = | ||||||
FormatStyle::ShortFunctionStyle({/*Empty=*/true, | ||||||
/*Inline=*/false, | ||||||
/*Other=*/false}); | ||||||
GoogleStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never; | ||||||
GoogleStyle.BreakStringLiterals = false; | ||||||
GoogleStyle.ColumnLimit = 100; | ||||||
|
@@ -1892,7 +1930,10 @@ FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language) { | |||||
ChromiumStyle.AllowShortLoopsOnASingleLine = false; | ||||||
} else { | ||||||
ChromiumStyle.AllowAllParametersOfDeclarationOnNextLine = false; | ||||||
ChromiumStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline; | ||||||
ChromiumStyle.AllowShortFunctionsOnASingleLine = | ||||||
FormatStyle::ShortFunctionStyle({/*Empty=*/true, | ||||||
/*Inline=*/true, | ||||||
/*Other=*/false}); | ||||||
ChromiumStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never; | ||||||
ChromiumStyle.AllowShortLoopsOnASingleLine = false; | ||||||
ChromiumStyle.BinPackParameters = FormatStyle::BPPS_OnePerLine; | ||||||
|
@@ -1906,7 +1947,10 @@ FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language) { | |||||
FormatStyle getMozillaStyle() { | ||||||
FormatStyle MozillaStyle = getLLVMStyle(); | ||||||
MozillaStyle.AllowAllParametersOfDeclarationOnNextLine = false; | ||||||
MozillaStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline; | ||||||
MozillaStyle.AllowShortFunctionsOnASingleLine = | ||||||
FormatStyle::ShortFunctionStyle({/*Empty=*/true, | ||||||
/*Inline=*/true, | ||||||
/*Other=*/false}); | ||||||
MozillaStyle.AlwaysBreakAfterDefinitionReturnType = | ||||||
FormatStyle::DRTBS_TopLevel; | ||||||
MozillaStyle.BinPackArguments = false; | ||||||
|
@@ -1988,7 +2032,7 @@ FormatStyle getMicrosoftStyle(FormatStyle::LanguageKind Language) { | |||||
Style.BraceWrapping.BeforeWhile = false; | ||||||
Style.PenaltyReturnTypeOnItsOwnLine = 1000; | ||||||
Style.AllowShortEnumsOnASingleLine = false; | ||||||
Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; | ||||||
Style.AllowShortFunctionsOnASingleLine = FormatStyle::ShortFunctionStyle({}); | ||||||
Style.AllowShortCaseLabelsOnASingleLine = false; | ||||||
Style.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never; | ||||||
Style.AllowShortLoopsOnASingleLine = false; | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Should we expose this option to user? I am not sure what it means if we set only Other, but not Inline and not Empty - then C/C++ code will behave like SFS_All. Probably we should set it when user chooses 'All' in configuration.