lo2s icon indicating copy to clipboard operation
lo2s copied to clipboard

Update clang-format file for include grouping

Open bmario opened this issue 11 months ago • 3 comments

We decided to order includes in the following format:

<main file header>

<lo2s group>

<cpp dependencies group>

<std lib group>

<cstr lib group>

extern "C" {
<c dependencies>
}

It's possible to explain that to clang-format:

  • https://clang.llvm.org/docs/ClangFormatStyleOptions.html#includecategories
  • https://clang.llvm.org/docs/ClangFormatStyleOptions.html#includeblocks
  • https://clang.llvm.org/docs/ClangFormatStyleOptions.html#includeismainregex

bmario avatar Mar 14 '24 12:03 bmario

We need https://clang.llvm.org/docs/ClangFormatStyleOptions.html#mainincludechar

Which is Part of clang format 19 ...

bmario avatar Mar 14 '24 12:03 bmario

With clang-format-19 this works. With older versions it doesn't.

MainIncludeChar: Any
IncludeBlocks: Regroup
IncludeCategories:
  - Regex: '^<lo2s/'
    Priority: 2
  - Regex: '(hpp|hxx)>$'
    Priority: 3
  - Regex: '^<([^c][[:alnum:]|_]+|chrono|compare|charconv|complex|condition_variable|codecvt|coroutine|concepts)>$'
    Priority: 4 
  - Regex: '^<c[[:alnum:]|_]+>'
    Priority: 5
  - Regex: '\.h>'
    Priority: 6

bmario avatar Mar 14 '24 12:03 bmario

clang-format 19 is not yet released. So we do have to wait a bit.

tilsche avatar Apr 25 '24 09:04 tilsche