[PATCH] D12492: [Clang-Format] Add AlwaysBreakBeforeElse and AlwaysBreakBeforeCatch Style to avoid cuddled else/catch

Daniel Jasper via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 17 02:55:57 PDT 2015


The question is how all the other options should be called and how we can
group them nicely so that we don't flood the options configuration page too
much. Maybe it's time for nesting in the configuration class?
On Sep 17, 2015 11:50 AM, "Paul Hoad" <mydeveloperday at gmail.com> wrote:

> MyDeveloperDay added inline comments.
>
> ================
> Comment at: docs/ClangFormatStyleOptions.rst:247
> @@ -246,1 +246,3 @@
>
> +**AlwaysBreakBeforeElse** (``bool``)
> +  If ``true``, always break before ``else``.
> ----------------
> djasper wrote:
> > Hm, I think these should be grouped in some way and interact with
> BreakBeforeBraces.
> >
> > I theory, I'd like to have a lot of different flags and make
> BreakBeforeBraces select specific presents for them. However, maybe we can
> put all the brace breaking options together in some nice way (don't have a
> very good idea yet).
> >
> > Not saying that you need to do all of this, but pulling these two
> options out from the other BreakBeforeBraces options seems a little
> undesirable. They essentially also just define what we do around braces.
> Well I agree, ideally the BreakBeforeBraces styles should be implemented
> by setting the finite control on each element
>
> Then code like this
>
> if (Style.BreakBeforeBraces == FormatStyle::BS_Allman ||
>         Style.BreakBeforeBraces == FormatStyle::BS_GNU ||
>         Style.BreakBeforeBraces == FormatStyle::BS_Stroustrup ||
>         Style.AlwaysBreakBeforeCatch) {
>          ...
>         }
>
> could become
>
> if (Style.AlwaysBreakBeforeCatch) {
>     ...
> }
>
> This would simply require some code in the initializer that says
>
> if (Style.BreakBeforeBraces == FormatStyle::BS_Allman ||
>         Style.BreakBeforeBraces == FormatStyle::BS_GNU ||
>         Style.BreakBeforeBraces == FormatStyle::BS_Stroustrup)
> {
>     Style.AlwaysBreakBeforeCatch=true;
> }
>
> if (Style.BreakBeforeBraces == FormatStyle::BS_Stroustrup)
> {
>     Style.AlwaysBreakBeforeElse=true;
> }
>
> This would allow those of us not using one of the 5 chosen styles to build
> our teams style guide via the individual capabilities
>
> Removing all the BS_Stroustrup/Allman etc.. from the UnwrappedLineParser
> will greatly improve its readability
>
>
> http://reviews.llvm.org/D12492
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150917/53213785/attachment-0001.html>


More information about the cfe-commits mailing list