llvm / llvm/llvm-project

[clang-tidy] It would be helpful for llvm-include-order to respect include sorting options from .clang-format files

Open
#201,422 13 comments 0 reactions 0 assignees View on GitHub
clang-format clang-tidy enhancement
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

> > Can't you just run the `llvm-include-order` clang-tidy check instead?
>
> Does that take `IncludeBlocks` and `IncludeCategories` from `.clang-format` into account?

I don't think so, but it shouldn't be impossible to teach clang-tidy.

_Originally posted by @philnik777 in https://github.com/llvm/llvm-project/issues/137617#issuecomment-2838677027_

This idea was initially floated in a rejected Pull Request concerning clang-format no longer able to only do include sorting with no other unwanted formatting. Some codebases desire to only sort includes and cannot just run clang-format directly on their source files due to the carnage it will cause since there are a huge amount of formatting options, too many to practically disable manually, and some of which cannot even be turned off at all, and many of the formatting options will clash with the style the existing code is written in. Given this, clang-tidy's llvm-include-order check seems like the next best candidate, but it doesn't seem to take .clang-format files into account for both checking if the include order is correct or the actual fixes themselves even when FormatStyle: file. As such, could we make this check respect the include sorting options in .clang-format files? I've heard that clang-tidy really just delegates back to the formatting engine that powers clang-format when FormatStyle: file, so hopefully this shouldn't be too much work, as the original comment suggests.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.