Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I tried to use readability-isolate-declaration check in clang-tidy, but nothing fixed. Example of code from test.cpp file:

void f() {
    int a = 0, b = 1, c = 2;
}

What I've done:

clang-tidy -checks='readability-isolate-declaration' -fix test.cpp

Output:

Error while trying to load a compilation database:
Could not auto-detect compilation database for file "test.cpp"
No compilation database found in /home/anzipex/Downloads/clang-test or any parent directory
fixed-compilation-database: Error while opening fixed database: No such file or directory
json-compilation-database: Error while opening JSON database: No such file or directory
Running without flags.
question from:https://stackoverflow.com/questions/65934459/why-clang-tidy-readability-isolate-declaration-not-fixing-code

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
330 views
Welcome To Ask or Share your Answers For Others

1 Answer

There are several problems here:

  1. readability-isolate-declaration check didn't exist in clang-tidy 6. Upgrade to a more recent version
  2. If you don't have a compilation database, you can use --(double dash) to specify compilation options. Even if you specify none, this will tell clang-tidy to compile the file. See the documentation.
  3. You didn't tell clang-tidy to exclude other checks besides the one you want

This is what the command should look like:

clang-tidy -checks='-*,readability-isolate-declaration' test.cpp -fix --

Output:

void f() {
    int a = 0;
    int b = 1;
    int c = 2;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...