[cfe-dev] [clang-format] sort includes and group per category

Oleksii Vilchanskyi via cfe-dev cfe-dev at lists.llvm.org
Tue Oct 24 04:02:45 PDT 2017


As a clang-format user, I'd love to see this kind of sort. This is the
general way many people structure their includes, so that they don't
introduce any hidden dependencies. One thing I'd propose is putting the
respective header of a given file on the top (or introduce a feature for
it).
For example, for file `foo.c`:

#include "foo.h"

/* Other "" includes */

/* Other <> includes which are inside the build tree, for example MOC
headers */

/* less common libs, i.e. home-made ones */

/* boost, Qt, whatever else headers */

/* standard library headers */

On 23.10.2017 21:22, Wim Leflere via cfe-dev wrote:
> To fix bugĀ 28203 and improve the includes sorting, I would like to add
> an includes grouping feature.
> 
> A 'GroupIncludes (bool)' format option could be added to group the
> includes per category.
> The includes could be grouped with a empty line between every group.
> 
> Example priorities: system includes 3, boost 2, other 1
> before:
> #include <memory>
> #include <boost/make_shared.hpp>
> #include "Device.h"
> 
> after:
> #include "Device.h"
> 
> #include <boost/make_shared.hpp>
> 
> #include <memory>
> 
> What do you think of the proposal?
> 
> Regards,
> 
> Wim
> 
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
> 

-- 
Regards,
Oleksii Vilchanskyi
PGP:0x8D3A0E046BDE941F2A53867CE3FD952D48C0B338



More information about the cfe-dev mailing list