Is it possible to apply profile only for specific paths in big project?

I have big project in my sonar server. I created custom rules and attached them to new profile. Now I want to add this profile to the project, but I want it will be applied only for specific paths, and not the entire project. is it possible to do it?

Hey there.

Quality Profiles cannot be applied per-path. However, you can still configure certain rules to only apply to certain file paths. See the docs here.

@Colin
I will give an example, please tell me if I’m right.

  1. I have project called “Test1”
  2. I have few java custom rules which contains the string “Test class”, “Test method” and “Tests should”
  3. I want to apply these rules on this path in the project Test1: ariel1/src/poc

Please confirm that this is the correct way is to create the entries at project level (for the project Test1) in Restrict Scope of Coding Rules:
Entry 1:
Rule Key Pattern: java:Test class*
File Path Pattern: ariel1/src/poc

Entry 2:
Rule Key Pattern: java:Test method*
File Path Pattern: ariel1/src/poc

Entry 3:
Rule Key Pattern: java:Tests should*
File Path Pattern: ariel1/src/poc

Your rule key will have a very specific pattern, without spaces. You can see it when you browse the rule in SonarQube. You probably defined it yourself when you developed the rule!

So in this examle, the rule key pattern is the rule key itself, cpp:S3805. If you want to have this rule only apply on rules in ariel1/src/poc, you should define ariel1/src/poc/**/* as the file path pattern.

Understood. so in the other case, when I want to apply specific java rule (instead of custom) on all files under ariel1/src/poc, how can I do it? using Restrict Scope of Coding Rules?
for example: Rule ID: java:S2189
is this the right way?

Rule Key Pattern: java:S2189
File Path Pattern: ariel1/src/poc/**/*

That’s correct.

1 Like

Great. tnx a lot. very useful information

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.