Sonar Qube Ignore specific rule on files contains specific string (by regular expression) - sonarqube

I wanted to configure my SonarQube [v8.9.6.50800] scan to ignore Specific rule e.g. squid:S1172 from classes which contains a specific string e.g. implements BillingApi.
To set this up I need to use some configuration?! that will accept a regular expression, let's say: .* implements [^{]*Api and rule.
I'm aware of the option to exclude specific rule for file path pattern as explained here: SonarQube define "Ignore Issues on Multiple Criteria" in maven build
Or the option to exclude all rules in a file as explained here: sonar project.properties to ignore files containing a regular expression
But I need to narrow the scope to exclude specific rule from file contains some regex.

Related

add only certain rules for sonar scanner instead of excluding

Instead of excluding or ignore rules in sonar's property file, I'd like to have only a few certain rules for sonar to analyse, so I don't need to exclude a large number of rules out of 344 rules for c++. How can I do that? (I'm not adding customized rules)
I imageine the syntax would be: (in .properties file)
sonar.issue.include.multicriteria=***
sonar.issue.include.multicriteria.***.ruleKey=cpp:S984
....
EDIT:
1, I need to configure this in a CLI environment.
2, It's about one project, two rule sets. one rule sets for local use and the other one for CI/CD use.
You need to craft a Quality Profile that contains only your rules of interest, and then either make it the default profile for C++, or explicitly assign your project to it.
BTW, correctly setting exclusions in properties (versus through the UI) is quite tricky. I'm not sure about the correctness of the ruleKey field name, and you're probably missing another field in there, but your syntax seems to be on the right track.

Apache camel regex pattern for txt files

I would like to use apache camel with regex pattern for txt files, but the problem is the correct pattern and how to use it in from() method. The documentation mentions only about the keyword include and exclude. Which is the easiest way to use a pattern in order to check if filename matches the regex pattern? Thank you in advance.
The easiest might be the one you've mentioned (include parameter on the file endpoint). Example (include every txt):
from("file://input/directory?include=.*\\.txt")
Other option is to implement a GenericFileFilter.
Since you're only checking for the file name, you can do something like this for files appearing in a specific folder and choose what to do with them using a predicate:
from("file://fooFileFolder/")
.choice()
.when(header("CamelFileNameOnly").regex("fooPattern")).to("mock:fooHere")
.otherwise().to("mock:fooThere")
.end();
It's up to you to use the regex suitable for the matching pattern in the currently read file name you're looking to apply the test to. You can also use regex with Camel's Simple dialect.

How to specify space or tab as separator in teamcity multiple parameter specification

I want to add ability to teamcity user specify several maven goals for build configuration.
Sample of maven syntax for several goals is
mvn clean package
goals separated by space
How to specify space as separator in teamcity multiple value separator.
It seems configuration webform trims user input values.
I found solution, use edit parameter window
and specify double spaces as value separator

SonarQube: Copy of Quality Profile is Missing Rules

I tried to create an exact copy of of our default SonarQube quality profile by clicking on the "Copy" link in the "Quality Profiles" page, but some of the rules are not copied. We use SonarQube version 4.5.6 and the profile I tried to copy does not inherit from any other profiles.
According to the SonarQube documentation, the new profile is an exact copy of the original profile, including inheritance (parent) relationships. However, my copied profile is missing the following 9 rules out of 487 and I don't see any reason why (they are all 'checkstyle' rules, but there's many more with the same label that got copied correctly):
Boolean Expression Complexity (checkstyle)
Comment pattern matcher (checkstyle)
Constant Name (checkstyle)
Hidden Field (checkstyle)
Inner Assignment (checkstyle)
Local Variable Name (checkstyle)
Magic Number (checkstyle)
Member name (checkstyle)
Static Variable Name (checkstyle)
The rules you name are all template rules, i.e. rule "cookie cutters" from which you can stamp many rule variations. Unfortunately, rules created from templates, a.k.a. "custom rules", aren't properly handled in profile backup and restore.
This is currently scheduled for the 6.x series. The Jira ticket is SONAR-5366.

sonarqube xpath rule match multiple file patterns

I'am building custom rules in SonarQube 5.1.2 and I can't find out how to apply a rule to multiple file types.
I've seen that ant-style file pattern is only one pattern, not a list.
Specifically I want my rule to match **/*.wsdl and **/*.WSDL and eventually files with other extensions.
Is there a better way to do this than replicating the rule?
thanks.

Resources