0

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?

Ross Jacobs
  • 2,962
  • 1
  • 17
  • 27
  • Most default might also be set directly by command line option in most applications... – Jarod42 Oct 27 '21 at 09:00
  • I do not understand this comment. – Ross Jacobs Oct 28 '21 at 00:34
  • 1
    It seems you are surprised that default style can be set directly in command line by `-style=file` but that is also the case for most application. For example, optimization/standard/warning-level/.. flags can be set by gcc/clang/msvc, and they include the default value. – Jarod42 Oct 28 '21 at 07:46
  • That's a good point and thank you for expanding on it. – Ross Jacobs Oct 28 '21 at 19:12
  • 1
    This may also be a question of documentation and why they don't indicate that this is the default behavior. – Ross Jacobs Oct 28 '21 at 19:16

0 Answers0