Я использую формат .clang в своем проекте для настройки своего стиля кодирования. Среди них я настроил параметры сортировки заголовочных файлов с помощью IncludeCategories. Конкретные правила конфигурации следующие:
Код: Выделить всё
IncludeCategories:
- Regex: '^"(?!3rd|vendor).*\.(h|hpp)"$'
Priority: 1
# This category matches project headers, such as "module.h"
- Regex: '^"(3rd|vendor).*\.(h|hpp)"$'
Priority: 2
# This category matches third-party headers, such as "3rd/module.h" or "vendor/module.hpp"
- Regex: '^'
Priority: 3
# This category matches system headers, such as
- Regex: '^]+>$'
Priority: 4
# This category matches standard library, such as
Структура проекта:
Код: Выделить всё
.
├── CMakeLists.txt
├── .clang-format
├── include
│ ├── 3rd
│ │ └── constant.h
│ ├── sub
│ │ ├── sub.h
│ │ └── xx.hpp
│ └── work.h
└── src
├── main.cpp
└── work.cpp
Код: Выделить всё
// main.cpp
#include "sub/sub.h"
#include "work.h"
#include "3rd/util.h"
#include
#include
int main() {
return 0;
}
Код: Выделить всё
// main.cpp
#include "3rd/util.h"
#include
#include
#include "sub/sub.h" //
Источник: [url]https://stackoverflow.com/questions/78157858/about-clang-format-config-includecategories[/url]
Мобильная версия