Improve your C++ code in KDevelop with Clang-Tidy

You might be aware of Clang-Tidy, the clang-based C++ “linter” tool which allows static analysis of your code, including fixing it automatically where possible.
And you remember the introduction of the “Analyzer run mode” with version 5.1 of KDevelop, the extensible cross-platform IDE for C, C++, Python, PHP and other languages.

While development of a separate KDevelop plugin for the integration of Clang-Tidy was started in 2016, named kdev-clang-tidy, activity stalled after some time, with other things in life to do.
One good thing about Copyleft software is that where somebody left others can pick up and continue: with Clang-Tidy getting more and more useful, there has been new motivation to have such integration with KDevelop, and after some bits of code pushing here we are now, looking at the first released versions of kdev-clang-tidy with basic functionality, which already helped to improve some code bases.

The latest release 0.3 enables KDevelop users to do this:

  • running clang-tidy on a single file, subdirectories or the whole project, with the result shown in the Problems tool view, invokable from file context menus and main menu (Analyzer section)
  • per-project config UI:
    • free field for additional command line parameters to clang-tidy
    • checkbox whether to include system headers in the check
    • toggle between using .clang-tidy files or options in the config UI:
      • header filter regular expression
      • opt-in list of checks

See kdev-clang-tidy 0.3 in activity in some screenshots, here with KDevelop 5.3 pre-beta:

Configure Clang-Tidy globally
Configure Clang-Tidy for a project
Running Clang-Tidy on a subdirectory of a project (here the Clazy integration plugin part of upcoming KDevelop 5.3)

(And yes, in the screenshots one can spot upcoming support for another static code analyzer, clazy, which will be shipped as part of upcoming KDevelop 5.3, more on that soon in another blog post)

The current version 0.3 of kdev-clang-tidy can be built against the versions 5.2, upcoming 5.3 and the current development branch (master) of KDevelop.

Learn more about the kdev-clang-tidy plugin from its file, e.g. how to build it, how to package it, how to use it, where to report issues, and what the planned roadmap is.

The latest released kdev-clang-tidy version is currently also included in the Nightly AppImage builds of the current stable KDevelop code version (which already switched to the 5.3 branch).


One thought on “Improve your C++ code in KDevelop with Clang-Tidy

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.