File filter in clang format configuration (original) (raw)

September 26, 2023, 8:58am 1

Hi!

When trying to retroactively introduce clang-format into our codebase, I found it inconvenient that it’s not possible to to configure file should not be touched by the formatter. I am aware of ignoring a whole directory and an individual file with a comment but those are not the solutions that I’m looking for.

My question is if any similar solution was ever considered and if it would potentially be accepted if some work towards it was done.

Regards, Tomek

We use gitattributes to control which files get looked at by clang-format. Granted, we have a robot that does this enforcement (and can automatically fix commits as well), but I think this is more scalable than making .clang-format files know about such things as which paths may “matter” as it depends on where they live and such.

Thanks for the answer!
Yes, I see that would make sense in CI and when using a script to orchestrate the run. What I’m trying to prevent is the code being formatted when using an IDE

I think adding /* clang-format off */ to the top of the file may be the most effective solution here (might need the on comment at the bottom too).

owenpan December 12, 2023, 8:55pm 5

We’ll add .clang-format-ignore files. See here.