How to configure clang-tidy checks using InspectCode Command-Line Tool

I am running inspectcode.exe against a solution file. I have put .editorconfig in the root and this seems to be picking up checks. I have set checks for function size warning from clang-tidy: https://clang.llvm.org/extra/clang-tidy/checks/readability/function-size.html

# Resharper inspectcode settings
[*]
resharper_cpp_clang_tidy_readability_function_size_highlighting=warning
resharper_cpp_clang_tidy_google_readability_function_size_highlighting=warning

I am not getting any warnings from my code. I am trying to set the threshold using a .clang-tidy file in the root:

---
Checks: '-*,readability-function-size'
CheckOptions:
  - key: readability-function-size.LineThreshold
    value: 100

This config is not being picked up. How do I set the parameters for clang-tidy checks when running InspectCode Command-Line Tool?

0
7 comments

Turns out I was wrong and the settings in .clang-tidy are respected by clang-tidy checks done in inspectcode.exe. You don't get the full details, e.g. for readability-function-size.LineThreshold how long the function actually was that exceeded the function length limit, but it raises a warning nevertheless. Clang-tidy checks done by Visual Studio do output this information.

0

Hello David,

Could you please elaborate how Visual Studio outputs this additional information? In the VS editor I only see the main message, not the additional notes.

It's true that some clang-tidy checks output additional notes which R# does not show. I've filed a feature request -  RSCPP-34840

Thanks!

0

Hi Igor,

I ran the checks in CI, using MSBuild:

  1. I inject the EnableClangTidyCodeAnalysis element into the project vcxproj XML file before running analysis, using a custom RunClangTidy condition
  2. I then ran msbuild /p:RunCodeAnalysis=true /p:PreferredToolArchitecture=x64 /p:RunClangTidy=true /p:Configuration=Release /p:Platform=x86 -m $project to run analysis on the project
  3. The analysis would output analysis to standard output and \Release\<project>.ClangTidy.log.

The <project>.ClangTidy.log file is not XML which is a pain, but it does contain entries with additional information like:

C:\source\project\Groups.cpp:41:17: warning: function 'IsMemberOf' exceeds recommended size/complexity thresholds [readability-function-size]
BOOL Groups::IsMemberOf(const char *szGroup)
               ^
C:\source\project\Groups.cpp:124:7: note: nesting level 6 starts here (threshold 5)
                                               {
                                               ^
…

C:\source\project\Draw.cpp:2190:18: warning: function 'DrawRegen' exceeds recommended size/complexity thresholds [readability-function-size]
void Draw::DrawRegen(CDC &dc, CAxis *pAx, CRect &b)
                ^
C:\source\project\Draw.cpp:2190:18: note: 572 lines including whitespace and comments (threshold 500)

This additional information like the actual size of the function is useful for targeting where to start. 

Running InspectCode.exe I get an XML report, but only contains initial info, no indication of what threshold was breached and by how much, like this:

<Issue TypeId="CppClangTidyReadabilityFunctionSize" File="Draw.cpp" Offset="79555-79576" Line="2190" Message="Function 'DrawRegen' exceeds recommended size/complexity thresholds [readability-function-size]" />
0

Clang-tidy checks done by Visual Studio

Just clarifying I meant clang-tidy checks done via Project Properties > Code Analysis > Clang-Tidy, not via Resharper. 

0

Thanks! Yes, I see VS indeed does print the notes to the log. I don't think R#'s inspect code supports printing additional information apart from the message. But then these notes might also be beneficial when they're included into the message in the editor. We'll consider how this can be implemented.

0

I don't know if it's worth necro'ing this post but I have the same problem with Inspect Code 2025.3.1. This is for C++ projects.

If I run clang-tidy analysis on msbuild, it'll respect .clang-tidy in my repository root: msbuild /p:RunCodeAnalysis=true /p:EnableClangTidyCodeAnalysis=true  .\SubDir\MyProject.vcxproj

If I use inspectcode.exe it's ignored: inspectcode.exe .\SubDir\MyProject.vcxproj

Inspect Code will run and output a report, but for a whole lot of checks I don't want and none of the ones I do want that I've specified in .clang-tidy. I tried using a .DotSettings file but that's ignored as well.

.clang-tidy:

Checks: '-*,readability-function-size,readability-function-cognitive-complexity'
CheckOptions:
 - key: readability-function-cognitive-complexity.Threshold
   value: 25
 - key: readability-function-size.LineThreshold
   value: 100
 - key: readability-function-size.NestingThreshold
   value: 5

InspectCode.DotSettings, it'll read this file with --settings, because inspectcode will complain if it's missing when --settings is used:

<wpf:ResourceDictionary
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:sys="clr-namespace:System;assembly=mscorlib">
  <!-- Enable clang-tidy integration -->
  <sys:Boolean x:Key="/Default/CodeInspection/CxxClangTidy/EnableClangTidy/@EntryValue">
    True
  </sys:Boolean>
  <!-- Force clang-tidy to use the repo-root .clang-tidy file -->
  <sys:String x:Key="/Default/CodeInspection/CxxClangTidy/ClangTidyConfigFile/@EntryValue">
    .clang-tidy
  </sys:String>
  <sys:String x:Key="/Default/CodeInspection/CxxClangTidy/Checks/@EntryValue">
  </sys:String>

</wpf:ResourceDictionary>
0

ReSharper still does not support reading enabled checks from .clang-tidy if this file is present. The tracking issue is RSCPP-30593, we'll try to get to it in 2026.

0

Please sign in to leave a comment.