clang-format's default behavior is to scan the current directory and cd .. until it finds a .clang-format
per this question.
And -style=file
has the exact same behavior per this question, and also based on running clang-format --help:
$ clang-format --help
--style=<string> - Coding style, currently supports:
LLVM, GNU, Google, Chromium, Microsoft, Mozilla, WebKit.
Use -style=file to load style configuration from
.clang-format file located in one of the parent
directories of the source file (or current
directory for stdin).
...
Example
With this .clang-format
file:
IndentWidth: 20
And this err.cpp:
#include <string>
int main(){int i;return;}
Running clang-format err.cpp
and clang-format err.cpp -style=file
with .clang-format
in both .
and ..
(4 scenarios) yields:
#include <string>
int main() {
int i;
return;
}
which is different from the default IndentWidth of 2.
Versions
$ clang-format --version
Homebrew clang-format version 13.0.0
$ clang --version
Homebrew clang version 13.0.0
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin
Question
What does -style=file
do?