Let clang-format sort includes.
After this, `git cl format` will reorder includes in blocks of #includes that are not separated by newlines. This works in almost all cases, but it can break some code e.g. #include <windows.h> #include <shellapi.h> clang-format will reorder these now, but shellapi.h only compiles if windows.h was included first. Relying on this is brittle, so replace code like this with #include <windows.h> // Must be after windows.h: #include <shellapi.h> Since clang-format doesn't reorder across blocks, this will do the right thing. This also means you're still on the hook of putting blocks with user headers, C++ headers, and C headers in the right order. This will hopefully replace src/tools/sort-headers.py which contains some hacky heuristics -- but just inserting newlines between includes when needed (with a comment) seems like a better tradeoff anyhow. And the automatic integration with `git cl format` is nice. (clang-format has IncludeIsMainRegex and IncludeCategories for adding heuristics, but we shouldn't use these, they're too complicated.) BUG=688155 TBR=brettw Review-Url: https://codereview.chromium.org/2669263003 Cr-Commit-Position: refs/heads/master@{#447875}
This commit is contained in:
@ -6,6 +6,10 @@ BasedOnStyle: Chromium
|
||||
# 'vector<vector<int>>'. ('Auto' means that clang-format will only use
|
||||
# 'int>>' if the file already contains at least one such instance.)
|
||||
Standard: Cpp11
|
||||
|
||||
# TODO(thakis): Default this to true in -style=Chromium if we decide to keep it.
|
||||
SortIncludes: true
|
||||
|
||||
# Make sure code like:
|
||||
# IPC_BEGIN_MESSAGE_MAP()
|
||||
# IPC_MESSAGE_HANDLER(WidgetHostViewHost_Update, OnUpdate)
|
||||
|
Reference in New Issue
Block a user