Search code examples
c#regexsonarqubesonar-runner

SonarQube C# with additional regex match


I have the MsBuild C# plugin up and running with SonarQube, but I would also like to match sub-string words, like "TODO" or "FIXME".

I cant find a way to configure this in the C# plugin, but I found a plugin called text-plugin which does this, but how do I configure SonarQube to run both plugins on the source code?

I have configured a single-line regex in text-plugin and mapped it to all filed types with **/* but it wont run, and if I associate the text-plugin with .cs the SonarQube runner can't determine the language.


Solution

  • The path I would take is to develop a custom Roslyn analyzer for C# which will detect the bad comment patterns. There are plenty of online resources available to get started with writting Roslyn analyzers.

    You can have a look at how to TODO and FIXME analyzers are implemented in SonarAnalyzer for C# to get an idea on how to write an analyzer working on comments.

    Once you have your custom Roslyn analyzer, use the SonarQube Roslyn SDK to make it available in SonarQube.

    This will also enable you to easily add further custom C# rules, without being limited by what the text-plugin can do.