[cfe-dev] Doubts regarding clang-format

David Blaikie via cfe-dev cfe-dev at lists.llvm.org
Mon Apr 26 22:10:55 PDT 2021


On Mon, Apr 26, 2021 at 9:13 PM saloni goyal via cfe-dev
<cfe-dev at lists.llvm.org> wrote:
>
>  Hello!
>
> I am working on a clang format. I want to customize it:
>
> 1. For if-else condition I want that for one line statement written in multiple lines should get wrapped in braces and also if there are only nested if-else then that code should be wrapped in braces. I have seen clang-tidy and in that google-readability-braces-around-statements.ShortStatementLines with value 2 gives expected results to me but I want that it should be done with clang-format.

clang-format only changes whitespace, it doesn't add or remove
punctuation - that's what clang-tidy is for (well, that's not entirely
true - line wrapping comments requires adding more comment characters,
and reordering #includes does more than add/remove whitespace - but
let's say clang-format is very selective about the punctuation it
modifies, and adding/removing braces is probably out of scope for
clang-format)

> 2. For some comments the indent level should be more or the clang-format should accept some comment intend level as it.

I guess clang-format already does some indent handling for comments (I
think it generally aligns it with the code/indent of the surrounding
elements) - so you might be able to modify the logic that chooses and
performs that comment indentation to do what you want?

> I want to make these changes in my clang-format. Please can you suggest some way to get these results?

- Dave


More information about the cfe-dev mailing list