Make Clang-Format give detailed error when there is a format problem

As the title suggests I’m running Clang-Format on my code in order for it to show me if there are any format error…

The thing I wanna know is if there is a way to make the output more detailed, because every time it fails it does it with the same error:

error: code should be clang-formatted [-Wclang-format-violation]

like, is there any way for it to show me the specific violation?

I’m running clang like this:

clang-format -style=file --dry-run --Werror

Thank you all in advance :slight_smile:

1 Like


Could you please give more details about your platform/environment?
Because when I run clang-format -style=file test.cpp --dry-run -Werror (version 13, on Windows), I get:

test.cpp:2:16: error: code should be clang-formatted [-Wclang-format-violations]
  float bar() {
test.cpp:3:14: error: code should be clang-formatted [-Wclang-format-violations]
    return 0;

so with the locations of each to-be-done replacement.



First I wanna thank you for you comment!
I can also see the place where the format error occurs but my question was if there is a way for clang to tell me exacly WHAT the problem is… I mean… like “the name of the class isnt formatted well”

I hope you can understand what I truly mean

thank you again!

I don’t think it’s possible directly.
You can try using clang-format -style=file test.cpp --output-replacements-xml that will give you something like:

<?xml version='1.0'?>
<replacements xml:space='preserve' incomplete_format='false'>
<replacement offset='28' length='6'> </replacement>
<replacement offset='43' length='4'> </replacement>

That’s the complete lists of formatting changes to apply. You can work around this with some script probably if you want a nicer output.

Hope this helps.