CX08$ /home/phi/llvmbuild/bin/clang-tidy -fix-errors -checks=‘readability-braces-around-statements’ c.c
Error while trying to load a compilation database:
Could not auto-detect compilation database for file “c.c”
No compilation database found in /home/phi or any parent directory
json-compilation-database: Error while opening JSON database: No such file or directory
Please, provide more datailed explanation of your issue. Which one of the following is it?
a) You have a compilation database in place and clang-tidy does not detect it.
b) You don’t have a compilation database.
If it’s b) you obviously can get rid of this error by getting a compilation database (on how to refer to Running Clang Tidy on LLVM).
Generally you might not always want to have a compilation database if your goal is just to analyze a single source file: this error doesn’t prevent clang-tidy from inspecting the provided sourcefile, so you’ll still get your diagnostics even if no compilation database is up.
But it didn’t solved anything what I guess is normal .clang.tidy seems to be a configuration file.
I don’t know what is a DB, sonds like I need to run Cmake but I don’t know that at the moment (only know make). I ‘try’ clang-tidy and clang-format, first locally on a couple of files, then later on a bunch of files.
So far I understand that Cmake is related with building llvm, while I try to use clang-tidy on my own .c file not related with llvm (located on my login dir)
But it didn't solved anything what I guess is normal .clang.tidy seems
to be a configuration file.
I don't know what is a DB, sonds like I need to run Cmake but I don't
know that at the moment (only know make). I 'try' clang-tidy and
clang-format, first locally on a couple of files, then later on a bunch
of files.
Thanx Jon
It works !!
One last 'cosmetic' is there a way to have -fix-errors producing another
file instead of trashing the source file, or to have a backup of the
original file, so basically tidy c.c would produce c.c.new and leave c.c
intact OR tidy c.c would backup c.c into c.c.back and patch c.c
I don't remember. I'd check `clang-tidy -help`, or put the relevant source files in version control (or both).
Almost there. From the compilation database docs:
Clang has the ability to generate compilation database fragments via -MJ argument <clang -MJ\<arg>> . You can concatenate those fragments together between [ and ] to create a compilation database.
Thanks! that worked. It is a bit misleading that the error says that the compilation database could not be detected. Maybe it should say that the file has an invalid format or something to that effect.