Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clang format: disable ordering includes

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?

like image 936
user7431005 Avatar asked Feb 21 '20 07:02

user7431005


2 Answers

Have you tried: SortIncludes: false?

You can generate a .clang-format with preview here: https://zed0.co.uk/clang-format-configurator/

like image 169
Martin Morterol Avatar answered Oct 31 '22 09:10

Martin Morterol


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>
like image 40
Tarek Dakhran Avatar answered Oct 31 '22 08:10

Tarek Dakhran