Doubts regarding clang-format

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.

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

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

Regards

Saloni

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

  1. 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?

Basically there are some comments that are indented one level more than above line. So I want that these indented comments should not get aligned back with the above line, should remain one level indented. Can you please tell me the file name or path of the file in which these changes should be made so that I can get the desired results?

Thanks
Saloni

Sorry, I don't know where that is - if I were trying to figure it out
I'd create some code with an incorrect indentation, figure out the bit
of clang-format that actually makes changes to the code & set a
breakpoint in a debugger there to see when that's executed and walk
backwards up the stack to see what motivated the change which might
hopefully point to the indentation formatting. (but maybe there's too
much indirection there - perhaps clang-format does all the deciding,
builds a representation of what the code should look like, then runs
that to produce the output (so the intermediate representation would
be the thing you'd want to try to figure out how it's built) - maybe
searching through the code for words like 'comment' might help find
what you're looking for - not sure)

- Dave