[Codenarc-user] CodeNarc: Adding Custom Rules in a Grails project
Brought to you by:
chrismair
From: Jan K. <ja...@fa...> - 2011-04-29 08:31:24
|
Hello, I am new to CodeNarc but rather experienced in Static Code Analysis. I am working on a Grails project where we want to apply static code analysis to scan for some project specific patterns. Adding the CodeNarc plugin to Grails and running codenarc (Plugin 0.12, CodeNarc 0.13) was really simple. I am wondering if it is possible to create CodeNarc Rules local to my Grails project. I read the documentation and watched the screencast on creating new rules. But this all refers to creating new rules in the context of the codenarc project. Is it possible to create a rule in a grails project and reference it from the ruleset? I am a bit stuck right now and any hint or help is greatly appreciated. 1) Changing from the standard ruleset (somehow part of the CodeNarc for grails Plugin) to my ruleset using this configuration in Config.groovy: codenarc.ruleSetFiles="file:grails-app/conf/MyRuleSet.groovy" Causes all violations to disappear from the generated report. I have the standard groovy ruleset configured and all these rules get listed in the report, but no violation is generated. Commenting out the ruleSetFile configuration and running grails codenarc brings back the violations. Is this a Grails Plugin issue or a CodeNarc Issue? Any idea or suggestion how I could test this outside of the Grails context? 2) I have created my own simple test rule and put it into the src/groovy folder in the Grails project structure. I am not sure if this is a valid approach, but it seems to violate some implicit assumptions. Adding my rule to the ruleset and running 'grails codenarc' leads to the following error: Running CodeNarc ... FAILED -- java.lang.AssertionError: No such rule named [MyRule]. Expression: ruleClass. Values: ruleClass = null Seems that the Rule script could not be found by CodeNarc. Again, am I missing something? Is it possible at to create and use a Grails project local rule? Again, any hints or help is greatly appreciated. I would really like to get this to work, as the combination of Groovy and the CodeNarc API for AST-analysis seem to be pretty powerful for writing static code checks. Best regards, Jan |