clang format: disable ordering includes

Viewed 10759

In our C++ project, the order of our includes is regularly changed. This is a problem since we are using some third-party libraries which require a specific include order to avoid problems.

I know, this is bad but we have to deal with it.

Unfortunately, the order of our includes is regularly changed and I suppose that this is due to clang-format. I found a page where you can specify a variable includeCategories. However, I do not fully understand how it works. I simply want to completely disable the ordering of includes. How can I do this?

2 Answers

To disable sorting for the whole project use SortIncludes:false in .clang-format.

To disable clang-format only for a specific file region, use // clang-format off/on comments.

// clang-format off
#include <b.h>
#include <a.h>
#include <c.h>
// clang-format on
#include <d.h>
#include <e.h>
Related