<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62676>62676</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-format] Consistent style options for lists
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Stadly
</td>
</tr>
</table>
<pre>
There is a lack of consistency when it comes to the way lists can be formatted by Clang-Format. This applies both to how the styles are configured and which styles are supported.
For example, parameter lists can be bin-packed with the style option `BinPackParameters`, member initializer lists with `PackConstructorInitializers: BinPack`, while inheritance lists cannot be bin-packed.
I envision full consistency for styling lists, so options for alignment, breaking, indentation, and packing can be set consistently for all types of lists. This would simplify both the implementation, documentation and configuration, and make Clang-Format both more flexible and easier to maintain.
My thinking is to create nested configuration flags for each list type. Here is an example for member initializer lists (could also be called constructor initializer lists if we want to):
```
MemberInitializerList:
Align: boolean
Break: BeforeColon/BeforeComma/AfterColon/AfterComma
IndentWidth: unsigned
Pack: Never/BinPack/CurrentLine/NextLine/NextLineOnly
```
- `Align` provides alignment similar to `AlignAfterOpenBracket: Align` for functions.
- `Break` replaces `BreakConstructorInitializers`
- `IndentWidth` replaces `ConstructorInitializerIndentWidth`
- `Pack` replaces `PackConstructorInitializers`, with the additional option `AfterComma`
We would have similar nested configuration flags for the other lists types. For example parameter lists:
```
ParameterList:
Align: boolean
Break: BeforeParens/BeforeComma/AfterParens/AfterComma
IndentWidth: unsigned
Pack: Never/BinPack/CurrentLine/NextLine/NextLineOnly
```
- `Align` and `Break` together replaces `AlignAfterOpenBracket`, but provides greater flexibility
- `Pack: BinPack` replaces `BinPackParameters`
- `Pack: NextLine` replaces `AllowAllParametersOfDeclarationOnNextLine`
We should support at least these different types of lists:
- Argument lists
- Enumerator lists
- Inheritance lists
- Initializer lists
- Member initializer lists
- Parameter lists
This change would lead to improvements for:
- Documentation and configuration
- Get rid of inconsistencies like
- `ConstructorInitializerIndentWidth` also applies to inheritance lists
- `BinPackParameters: true` for parameter lists, but `PackConstructorInitializers: BinPack` for member initializer lists
- `BreakInheritanceList` has option `AfterComma`, while `BreakConstructorInitializers` doesn't
- `OfDeclaration` is part of the name `AllowAllParametersOfDeclarationOnNextLine` but not `BinPackParameters`
- No more searching around for the style options applicable for a list type; all the options are grouped as nested configurations
- No more wondering which style options are supported for a list type; they all support the same set of options (with tiny variations like `BeforeColon` vs `BeforeParens`)
- Implementation
- The implementation can be generic and not need separate handling for each list type. By looking at the context it is in, the appropriate set of style options can be loaded, and then the algorithm can be agnostic to which type of list it is working on.
- Maintenance and future enhancements
- Adding a new feature to one of the list types would add support for all list types
- Fixing a bug in one of the list types would fix it for all list types
The change would deprecate the following style options:
- `AlignAfterOpenBracket`
- `AllowAllArgumentsOnNextLine`
- `AllowAllParametersOfDeclarationOnNextLine`
- `AllowShortEnumsOnASingleLine`
- `BinPackArguments`
- `BinPackParameters`
- `BracedInitializerIndentWidth`
- `BreakConstructorInitializers`
- `BreakInheritanceList`
- `ConstructorInitializerIndentWidth`
- `PackConstructorInitializers`
It might also be possible to deprecate these options:
- `BreakArrays`
- `ObjCBinPackProtocolList`
We might have to update `ExperimentalAutoDetectBinPacking` to work with the new style options.
What do you think?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWN1u27gSfhr5ZhDDlWPFufCFk6zPKbBtCrRArylxJHFDkQI5iqPz9AdD_Vhy7LS7VwsUaUIO54_ffDOU8F4VBnEXbR6izdNCNFRat_tOQup2kVrZ7n6U6BCUBwFaZC9gc8is8coTmqyFY4kGFEFmK_RAFqhEOIoWtPLkIRMGUoTcukoQoYS0hUctTHFzCEtL-FGy7rrWCj2klkpWUtpjUOSp1ehBOGSjuSoahxKEkXAsVVZO931T19YRymW0eopW--7nwTrAN1HVGqP4EWrhRIWEbu5eqsxNLbIXlHBU7MFgGmxNyhqIktWDMt9E9vJt0OCjZMUqK6xSdKCMIiW0-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