[clang] [clang-format] Add FilesBeforeFolders option to SortIncludes (PR #208954)
Björn Schäpers via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 24 13:50:06 PDT 2026
HazardyKnusperkeks wrote:
> > While I absolutely share this sorting, it is already possible with the regexes and the priorities without any doubt or confusion.
>
> @HazardyKnusperkeks I have tried to achieve this using regexes and priorities but could only go far due to the iterative nature of this sorting. This is what we have, which fails to replicate the desired logic:
>
> ```
> IncludeCategories:
> - Regex: '^[^/]*$'
> SortPriority: 0
> - Regex: '^[^/]*/[^/]*$'
> SortPriority: 1
> - Regex: '^[^/]*(/[^/]*){2}$'
> SortPriority: 2
> - Regex: '^[^/]*(/[^/]*){3}$'
> SortPriority: 3
> - Regex: '^[^/]*(/[^/]*){4}$'
> SortPriority: 4
> - Regex: '^[^/]*(/[^/]*){5}$'
> SortPriority: 5
> ```
>
> Is it possible for you to share your clang format settings? I would be so happy if this is really possible with the regexes and sort priorities
This is what I have for that priority:
```
- Regex: '^"\.\./\.\./.*'
Priority: 10
SortPriority: 14
CaseSensitive: false
- Regex: '^"\.\./[^/]+/.*'
Priority: 10
SortPriority: 13
CaseSensitive: false
- Regex: '^"\.\./.*'
Priority: 10
SortPriority: 12
CaseSensitive: false
- Regex: '^".*/'
Priority: 10
SortPriority: 11
CaseSensitive: false
- Regex: '^".*'
Priority: 10
SortPriority: 10
CaseSensitive: false
```
Yeah of course that is repetitive, depending on how many levels you want to support. But on any given code base the levels are finite, you could even write a small script to generate the needed configuration.
https://github.com/llvm/llvm-project/pull/208954
More information about the cfe-commits
mailing list