[clang] clang-format: Add "AllowShortNamespacesOnASingleLine" option (PR #105597)

Galen Elias via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 15 15:11:00 PDT 2024


galenelias 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.

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.

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.

https://github.com/llvm/llvm-project/pull/105597


More information about the cfe-commits mailing list