Open mcandre opened 1 year ago
@llvm/issue-subscribers-clang-format
Personally, I'm not really fond of adding this to clang-format. First of all, it's not its responsibility, let's focus on doing one thing but well. Secondly, there are other ways as you mentioned yourself. Have a look at https://stackoverflow.com/questions/28896909/how-to-call-clang-format-over-a-cpp-project-folder. I also wrote a python script to do what you ask for, it should work on all common platforms: https://github.com/mkurdej/run-clang-format. Just my 2 cents.
@mkurdej: Will be good idea to include your scrip into LLVM repository, likerun-clang-tidy
.
Sure, I will submit a patch.
I don't want to depend on Python to run clang-format or clang-tidy.
Are you endorsing a particular solution mentioned on that Stack Overflow post? I've already seen that article. The answers consist of people explicitly complaining about the lack of recursion in clang-format, or else posting non-portable, broken shell commands. It's a lot of needless copy & paste for workarounds that vendor lock to specifically GNU/Linux, and are likely to break in BSD, let alone Windows environments.
Clang-tidy is also not recursive, but run-clang-tidy
is (using compile database).
Review: https://reviews.llvm.org/D149088.
What's the status on this? Last update was a year ago.
what is the counter argument to have a -r or --recursive option ?
A formatter should really be able to format more than a single file at once and recurse into directories. I know that clang-format
has a --files
option, but that takes in a file with each filename one a single line, which still would require some sort of preprocessing to generate. Adding the ability to recurse through directories wouldn't modify any current behavior -- only extend it -- and is a common feature with modern formatters (see Black for comparison).
I also agree with @mcandre in that I don't want to depend on Python in order to format my C++ code.
It's not its responsibility, let's focus on doing one thing but well.
I don't see how adding the ability to recurse through a directory and format all found source files would prevent clang-format
from "doing one thing but well".
Here's a workaround:
https://github.com/mcandre/sail
The file pattern data is probably imperfect. Because I'm not a C/C++ expert. It's not my responsibility, but something that clang(-format) is positioned well to manage.
@mcandre Hi, in your first message you mentioned there's a CMake workaround.
I'm not great with CMake but I do use it. Would it be possible if you could include the example CMake lines in your original message to "use" Clang format?
Here is my cmake configuration.
https://github.com/mcandre/snek/blob/master/CMakeLists.txt
Indeed, there is a cmake specific workaround. However, in practice many engineers do not use cmake for 100% of C/C++ projects. For example, many Linux centric components require autotools instead. Most Windows C/C++ projects use Visual Studio build systems directly without the cmake wrapper. Some Unix programmers use the compiler directly.
Please implement directory recursion for Clang-Format. This helps to quickly format large C/C++ project directories.
As a workaround, UNIX users can write a custom shell script. But that would force WSL for Windows C/C++ developers.
As a workaround, cmake users can use a
file
...GLOB_RECURSE
... directive. But not all C/C++ users use cmake.Really, I would like to see cpplint do this work automatically.
Start with the conventional filenames:
.c
,.cpp
,.h
,.hpp
, and introduce other common file extensions such as.cc
,.cxx
,.hxx
, case insensitivity, and so on.