<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/74947>74947</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-format] Strange Formatting...
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-format
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
StrangeRanger
</td>
</tr>
</table>
<pre>
I'm sorry that the title isn't very descriptive, but I'm unsure how else to word it. Say I have the following code before formatting with clang-format:
```csharp
using System.Collections.Generic;
using System.Linq;
using Xunit.Abstractions;
using Xunit.Sdk;
namespace XUnit.Project.Orderers
{
public class AlphabeticalOrderer : ITestCaseOrderer
{
public IEnumerable<TTestCase> OrderTestCases<TTestCase>(IEnumerable<TTestCase> testCases)
where TTestCase : ITestCase => testCases.OrderBy(testCase => testCase.TestMethod.Method.Name);
}
}
```
Then format it with clang-format, I get the following output:
```csharp
using System.Collections.Generic;
using System.Linq;
using Xunit.Abstractions;
using Xunit.Sdk;
namespace XUnit.Project.Orderers
{
public class AlphabeticalOrderer : ITestCaseOrderer
{
public IEnumerable<TTestCase> OrderTestCases<TTestCase>(IEnumerable<TTestCase> testCases)
where TTestCase : ITestCase => testCases.OrderBy(testCase => testCase.TestMethod.Method.Name); } }
```
Is there a reason why it's formatting the code this way? I've tried changing up my configurations, but it doesn't seem to change anything. Below is the configurations, and is up with clang-format 17.0.6:
```yaml
---
Language: CSharp
# BasedOnStyle: Microsoft
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignConsecutiveAssignments:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: true
AlignConsecutiveBitFields:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: false
AlignConsecutiveDeclarations:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: false
AlignConsecutiveMacros:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: false
AlignConsecutiveShortCaseStatements:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCaseColons: false
AlignEscapedNewlines: Right # Maybe
AlignOperands: Align
AlignTrailingComments:
Kind: Always
OverEmptyLines: 0
AllowAllArgumentsOnNextLine: false # Previously: true
AllowAllParametersOfDeclarationOnNextLine: false # Previously: true
AllowShortBlocksOnASingleLine: Empty # Previously: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: false
#AlwaysBreakAfterDefinitionReturnType: None # Deprecated
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
AttributeMacros:
- __capability
BinPackArguments: false # Previously: true
BinPackParameters: false # Previously: true
BitFieldColonSpacing: Both
BraceWrapping:
AfterCaseLabel: false
AfterClass: true
AfterControlStatement: Always
AfterEnum: true
AfterExternBlock: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: false
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: false # Previously: true
SplitEmptyRecord: false # Previously: true
SplitEmptyNamespace: false # Previously: true
BracedInitializerIndentWidth: 4
BreakAfterAttributes: Never
BreakAfterJavaFieldAnnotations: false
BreakArrays: true
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: Always
BreakBeforeBraces: Custom
BreakBeforeInlineASMColon: OnlyMultiline
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
Priority: 1
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentCaseBlocks: false
IndentCaseLabels: false
IndentExternBlock: AfterExternBlock
IndentGotoLabels: true
IndentPPDirectives: None
IndentRequiresClause: true
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertBraces: false # Documentation Contains WARNING
InsertNewlineAtEOF: true # Previously: false
InsertTrailingCommas: None
IntegerLiteralSeparator:
Binary: 0
BinaryMinDigits: 0
Decimal: 0
DecimalMinDigits: 0
Hex: 0
HexMinDigits: 0
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false # Previously: true
KeepEmptyLinesAtEOF: true # Previously: false
LambdaBodyIndentation: Signature
LineEnding: DeriveLF
MacroBlockBegin: ''
MacroBlockEnd: ''
#Macros: # Unknown
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All # Previously: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PackConstructorInitializers: CurrentLine # Previously: BinPack | TEST MORE
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakOpenParenthesis: 0
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyIndentedWhitespace: 0
PenaltyReturnTypeOnItsOwnLine: 1000
PointerAlignment: Right
PPIndentWidth: -1
QualifierAlignment: Leave # Documentation Contains WARNING
ReferenceAlignment: Pointer
ReflowComments: true
RemoveBracesLLVM: false # Documentation Contains WARNING
RemoveParentheses: Leave # Documentation Contains WARNING
RemoveSemicolon: false # Documentation Contains WARNING
RequiresClausePosition: OwnLine
RequiresExpressionIndentation: OuterScope
SeparateDefinitionBlocks: Leave
ShortNamespaceLines: 1
SortIncludes: CaseSensitive
SortJavaStaticImport: Before
SortUsingDeclarations: LexicographicNumeric
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeJsonColon: false
SpaceBeforeParens: ControlStatements
SpaceBeforeParensOptions:
AfterControlStatements: true
AfterForeachMacros: true
AfterFunctionDefinitionName: false
AfterFunctionDeclarationName: false
AfterIfMacros: true
AfterOverloadedOperator: false
AfterRequiresInClause: false
AfterRequiresInExpression: false
BeforeNonEmptyParentheses: false
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: true # Previously: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInContainerLiterals: true
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParens: Never
SpacesInParensOptions:
InCStyleCasts: false
InConditionalStatements: false
InEmptyParentheses: false
Other: false
SpacesInSquareBrackets: false
Standard: Latest
StatementAttributeLikeMacros:
- Q_EMIT
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 4
#TypeNames: # Unknown
UseTab: Never
VerilogBreakBetweenInstancePorts: true
WhitespaceSensitiveMacros:
- BOOST_PP_STRINGIZE
- CF_SWIFT_NAME
- NS_SWIFT_NAME
- PP_STRINGIZE
- STRINGIZE
...
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWltv47iS_jXKCxHDkdPt5CEPtmz30bRvHTnT5-xLQEtliROK1JBUHO-vX5DUXUo6Z4DF7gHG6LYD1lfFIqtYF0pYShIzgAfny9z5srjCuUq4eAiUwCyGR_0lro48ujz4jjtNkeRCXJBKsEIqAaSIooCIZI47VegVxAVFIENBMkVewXE9dMwVsqw5k7kAlPAzAioBKY7OXESIqBEK8AX5KMGvYMSeOKX8TFiMQh4BOsKJCz0qUqyUHj4TlaCQYhZf21FnMnPGC2dcfn8d23-hTLDI7GAuNWtwkQrSkccphVARzuToGzAQJHQm8wHgmrA_O5R_5oyo0ewolcBWxCAgiF6qcfvNcAoywyGgfz5pxF7wPyBUo52IQICQBXZaMCGEUJYfKQn1WqVEM5ol-AiKhJgWPMiZzJB_AKk8LKEYrNlbshry_CXLUxD4SMGZeIeS35kskZFRDsgO1XHvPmBVFZd7355Wf84JCEAVQ1tz5EwWLRF2U-YXx71T72BGmnkDKuHRqPjZ4hT05JM5KhRwpotyWxcd52ia5pAAKzwMETXgYK6HfBSD6jgoz1WW_-1-f7tfz_2mC_Sxy_lS-5IAhJEALDlD5-SCiHLcqWwGO-1wJg6qhEh0xhdnsjIxVUdLQSBCYYJZrKF5htILCjk7kTgX2DpHEYWJQhGHIlRLgFRHYMMJCLOLSgiLR2gOlJ8RkcWsXUGYRZqYZ_0Tgm6mo_Ho63tH4YJTaoeur6_tH2vM4hzHoC1RfLygPjCOO0FzLCHasUBdqIFtSCi45CdlIbMwBCk3PCInAmJ3OknQZxFduwWdkpjNTgrELgM2Fzh8sQBDaGKEwJfdKVAiD1UutOPN0JYzaGA8ziSEuc5sM5M2U2BKVutFS6adMmqsBp0wlVC64kyrLpdppi5rwuwUAwCPp6XgDtkqkWY8Z8UsLf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