Quantcast

[sonar-dev] Rules with parameters

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[sonar-dev] Rules with parameters

Tamás Kende
Dear all,

I need some help with implementing some violation checking to sonar erlang plugin. Can someone describe me what is the process to add a rule with a parameter, and use the value of the parameter of the rule in a sensor to decide is that a violation or not. (like cyclomatic complexity, I can measure it is 5 but it is only a violation over 10)

I created a rules.xml 
and used with 
And created a default profile, and parsed it. I can see the profile and the rules in Sonar GUI, but the default value is not filled... What did I miss?

I copied the profile, and defined a default value to this rule in the GUI. It worked fine. But in the code, when I got the active profile with:
profile.getActiveRulesByRepository("Erlang");

it contains the rule, but the:
rule.getParam("maximum");
returns with a param without default value... what did I wrong here (on the GUI I can see the value 10, and the profile variable refers to the newly created erlang profile...


Thank you for your help, 

Cheers

Tamas

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [sonar-dev] Rules with parameters

Simon Brandhof
Hi Tamas,

I suppose that you mixed rules and active_rules. The parameter of the active rule should correctly contain the value displayed in quality profile. Do you confirm that the variable  rule.getParam("maximum");
in your email is about the rule repository but not about the profile ?

Simon

On 22 June 2012 16:02, Tamás Kende <[hidden email]> wrote:
Dear all,

I need some help with implementing some violation checking to sonar erlang plugin. Can someone describe me what is the process to add a rule with a parameter, and use the value of the parameter of the rule in a sensor to decide is that a violation or not. (like cyclomatic complexity, I can measure it is 5 but it is only a violation over 10)

I created a rules.xml 
and used with 
And created a default profile, and parsed it. I can see the profile and the rules in Sonar GUI, but the default value is not filled... What did I miss?

I copied the profile, and defined a default value to this rule in the GUI. It worked fine. But in the code, when I got the active profile with:
profile.getActiveRulesByRepository("Erlang");

it contains the rule, but the:
rule.getParam("maximum");
returns with a param without default value... what did I wrong here (on the GUI I can see the value 10, and the profile variable refers to the newly created erlang profile...


Thank you for your help, 

Cheers

Tamas


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [sonar-dev] Rules with parameters

Tamás Kende
Hi Simon,

thank you for your answer... now it is solved, but you are right,  I have mixed the profile -- rule repo stuff... I have to refactor+rewrite that part. 
One more question. When I create the rule for the violation, what is the best way to get the repository key for the given rule? Can I get it from the profile? 
Is it good or bad if I use the same repo key (Erlang) for the dialyzer (analyser tool 1) and refactorerl (analyser tool2) rules? 

Thanks

Tamas

On Fri, Jun 29, 2012 at 10:32 AM, Simon Brandhof <[hidden email]> wrote:
Hi Tamas,

I suppose that you mixed rules and active_rules. The parameter of the active rule should correctly contain the value displayed in quality profile. Do you confirm that the variable  rule.getParam("maximum");
in your email is about the rule repository but not about the profile ?

Simon


On 22 June 2012 16:02, Tamás Kende <[hidden email]> wrote:
Dear all,

I need some help with implementing some violation checking to sonar erlang plugin. Can someone describe me what is the process to add a rule with a parameter, and use the value of the parameter of the rule in a sensor to decide is that a violation or not. (like cyclomatic complexity, I can measure it is 5 but it is only a violation over 10)

I created a rules.xml 
and used with 
And created a default profile, and parsed it. I can see the profile and the rules in Sonar GUI, but the default value is not filled... What did I miss?

I copied the profile, and defined a default value to this rule in the GUI. It worked fine. But in the code, when I got the active profile with:
profile.getActiveRulesByRepository("Erlang");

it contains the rule, but the:
rule.getParam("maximum");
returns with a param without default value... what did I wrong here (on the GUI I can see the value 10, and the profile variable refers to the newly created erlang profile...


Thank you for your help, 

Cheers

Tamas



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [sonar-dev] Rules with parameters

Simon Brandhof
 
One more question. When I create the rule for the violation, what is the best way to get the repository key for the given rule? Can I get it from the profile?

Yes you can get it from profile -> active rules -> rules. It's also possible to use the component RuleFinder :
https://github.com/SonarSource/sonar/blob/master/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleAuditListener.java#L79

 
 
Is it good or bad if I use the same repo key (Erlang) for the dialyzer (analyser tool 1) and refactorerl (analyser tool2) rules? 


It's recommended to use two different repositories to prevent from conflicts of rule keys.

Regards
Loading...