I'm on Ubuntu 18.04 with clang-format 9.
I've read the clang-format documentation where it says:
clang-format supports two ways to provide custom style options: directly specify style configuration in the -style= command line option or use -style=file and put style configuration in the .clang-format or _clang-format file in the project directory.
When using -style=file, clang-format for each input file will try to find the .clang-format file located in the closest parent directory of the input file. When the standard input is used, the search is started from the current directory.
No matter how I create the .clang_format file (I've tried with clang-format -style=google -dump-config > .clang_format) or where I put it, if I execute clang-format -style=file <file> it doesn't format anything.
Anyone that have the same issue?
For example, if I have a file hello.cpp:
#include <stdio>
std::string s=" VERY BAD"
"FORMATTING";
int   main()   {
  std::cout<< "Hello world!"<<'\n';
  return 0;
}
If I run:
$ clang-format -style=mozilla -dump-config > .clang_format
and even if I don't edit the .clang_format file, then
$ clang-format -style=file hello.cpp
I get the default LLVM formatting style instead of the Mozilla style:
#include <stdio>
std::string s = " VERY BAD"
                "FORMATTING";
int main() {
  std::cout << "Hello world!" << '\n';
  return 0;
}
but if I run $ clang-format -style=mozilla hello.cpp then I get
#include <stdio>
std::string s = " VERY BAD"
                "FORMATTING";
int
main()
{
  std::cout << "Hello world!" << '\n';
  return 0;
}
and the same happens if I move the previously generated .clang_format in the parent directory of the hello.cpp directory.
I've tried anything but it seems that I have to stick with preconfigured styles.
Anyone with the same problem?
Can I get some sort of logging from clang-format?
SOLUTION:
the name of the file must be .clang-format, not .clang_format!
I was creating a configuration file with a wrong name.
It must be named .clang-format, not .clang_format.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With