VS Code C++ Linter

Viewed 7393

I am using vs code to write my C++ code now. However, I don't know how to set up a C++ linter for my vs code environment. I find one called C++ advanced lint but its setting seems a little complicated and I spend a lot of time but still didn't get success. Want to ask someone who also using vs code to write c++ that which c++ linter do you use? and how to use it? Thanks.

c++ advanced lint

1 Answers

I am using clang-tidy on ubuntu. First of all download it from package manager:

sudo apt-get install clang-tidy

Then install the clang-tidy extension in vscode (Clang-Tidy notskm.clang-tidy). Once installed click on the extension settings

Settings location

Locate Clang-tidy: Checks, click on Edit in settings.json.

In your settings.json file will be generated this code:

"clang-tidy.checks": [

]

You can paste here the checks that you want to enable.

To see the available checks you can run this command from terminal:

clang-tidy --list-checks -checks='*'

For example you could take all the modernize checks, and you would end up with something like this:

"clang-tidy.checks": [
    "modernize-*"
]

Save your settings.json and go to your code. When saving a file the linter should now tell you what are the problems in your code.

Clang-tidy sample

Related