Skip to content

CXX Rules

Günter Wirth edited this page May 1, 2021 · 11 revisions

The cxx plugin has a few built-in rules. These are available in the repository cxx. Rules for static code analysis are intentionally omitted and users are referred to external tools such as Cppcheck and Clang-Tidy.

category rule id description
api UndocumentedApi To check if public APIs are documented.
error ParsingError To display CXX parser errors.
error ParsingErrorRecovery To display CXX parser errors with resulting error recovery.
file FileEncoding To check if all characters of a file can be represented in a character set.
file MissingNewLineAtEndOfFile To check for files with missing new line at the end.
file TabCharacter To check if a file contains a tab.
metrics ClassComplexity To check the cyclomatic complexity of a class against a threshold.
metrics FileComplexity To check the cyclomatic complexity of a file against a threshold.
metrics FunctionCognitiveComplexity To check the cognitive complexity of a function against a threshold.
metrics FunctionComplexity To check the cyclomatic complexity of a function against a threshold.
metrics TooLongLine To check if a line of source code is too long.
metrics TooManyLinesOfCodeInFile To check if a file has too many lines.
metrics TooManyLinesOfCodeInFunction To check if a function has too many lines.
metrics TooManyParameters To check if a function has too many parameters.
metrics TooManyStatementsPerLine To check the number of statements in a line.
naming ClassName To check a class name against a naming convention.
naming FileName To check a filename against a naming convention.
naming FunctionName To check a function name against a naming convention.
naming MethodName To check a method name against a naming convention.
regex CommentRegularExpression To search for a regular expression within a comment. This rule template can be used to define your own custom rules.
regex FileHeader To check if each file contains a file header.
regex FileRegularExpression To search for a regular expression within a file. This rule template can be used to define your own custom rules.
regex FixmeTagPresence To check if a file contains a FIXME comment.
regex LineRegularExpression To search for a regular expression within a line. This rule template can be used to define your own custom rules.
regex NoSonar To check if a file contains a //NOSONAR comment.
regex TodoTagPresence To check if a file contains a TODO comment.
xpath XPath For defining and checking XPath expressions. This rule template can be used to define your own custom rules.

Regex Rules

All regex rules are using Java regular expressions.

There is a set of special characters also known as metacharacters present in a regular expression. When you want to allow the characters as is instead of interpreting them with their special meanings, you need to escape them. By escaping these characters, you force them to be treated as ordinary characters when matching a string with a given regular expression.

The metacharacters that we usually need to escape in this manner are:

<([{\^-=$!|]})?*+.>"

Use an online regex tool like https://regex101.com/ to create and test your regex (flavor=Java).

Hint: The backslash character \ does not have to be doubled when entering a regular expression in the SonarQube UI!

Clone this wiki locally