[clang] clang-format: Add "AllowShortNamespacesOnASingleLine" option (PR #105597)
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Sun Oct 20 18:11:18 PDT 2024
owenca wrote:
> > I'm inclined to think that all the AllowShort options should work the same way whether ColumnLimit is 0. However, a couple of them I checked (AllowShortLoops and AllowShortBlocks) have no effect unless set to false. I suggest that we mark the test as a FIXME or don't include it here.
>
> As an active user of ColumnLimit 0, I disagree. At least for my team we use ColumnLimit of 0 to allow for more customization and variability of the column limit. Treating it like ColumnLimit: Infinity causes huge constructs to be pulled into a single line for some of these 'AllowShort' options, which we actively don't want. Making somewhat arbitrary and contextual decisions about how to do the breaking is a 'feature' in my opinion - although I'm not sure if that's truly the intent and vision behind ColumnLimit 0.
Below is the documentation on [`ColumnLimit`](https://releases.llvm.org/19.1.0/tools/clang/docs/ClangFormatStyleOptions.html#columnlimit):
> A column limit of `0` means that there is no column limit. In this case, clang-format will respect the input’s line breaking decisions within statements unless they contradict other rules.
The term _statements_ above can be loosely interpreted as _unwrapped lines_. Since all the `AllowShort` options involve merging _wrapped_ ines, they should not be ignored even when `ColumnLimit` is set to 0. (See also [`
RemoveEmptyLinesInUnwrappedLines `](https://clang.llvm.org/docs/ClangFormatStyleOptions.html#removeemptylinesinunwrappedlines).)
> My thought here is that this feature should function similarly to how CompactNamespaces interacts with ColumnLimit: 0, which is basically that it allows arbitrary line breaking. So you could have a 1000 character line, or you could break it after every namespace. Forcing it to always pull single statements no matter how long onto a single line would be undesirable in my opinion.
IMO a better way to have arbitrary line breakings is to add a `Leave` suboption.
> I'm definitely open to changing things here, and being consistent if there is some other vision of how features are supposed to interact with ColumnLimit 0, but this has been my mental model so far, and that seems to be the natural behavior that I've observed, so validating that functionality in the tests seems reasonable to me.
I don't think we want to add any tests whose formats are questionable or still under discussion. WDYT @mydeveloperday @HazardyKnusperkeks @rymiel ?
https://github.com/llvm/llvm-project/pull/105597
More information about the cfe-commits
mailing list