Skip to content

sonar.cxx.gcc.regex

guwirth edited this page Jan 27, 2021 · 2 revisions

For text files, a regular expression can be defined to read the text. The regular expressions follow the Java convention.

Hint: You have to escape the backslash (\-> \\) for the regex parameter in the configuration file!

For the assignment of the individual parameters named-capturing groups are used. A capturing group (...) can also be assigned a "name", a named-capturing group e.g. (?<file>.*): The following named-capturing groups are defined:

named-capturing group description
<file> filename part of the issue
<line> line number of the issue
<column> column number of the issue
<id> rule id of the issue
<message> message text of the issue

Sample:

If the following regular expression is defined

sonar.cxx.xyz.regex=(?<file>.*):(?<line>[0-9]+):[0-9]+:\\x20warning:\\x20(?<message>.*)\\x20\\[(?<id>.*)\\]

and the sensor reads this text

src/zipmanager.cpp:141:10: warning: conversion to 'unsigned char' from 'unsigned int' may alter its value [-Wconversion]

then the text is split up as follows:

pattern description match
(?<file>.*): filename part of the issue src/zipmanager.cpp
(?<line>[0-9]+): line number of the issue 141
[0-9]+:\\x20warning:\\x20 ignoring column and warning text
(?<message>.*)\x20 message text of the issue conversion to 'unsigned char' from 'unsigned int' may alter its value
\\[(?<id>.*)\\] rule id of the issue -Wconversion
Clone this wiki locally