I am trying to use codeNarc on a grails project, after installing it and running it I've have some rulesets violations messages that I would like to understand and resolve. The first on concern "GrailsStatelessService" and the second the "equals() and toString()" methods...
For the first one "GrailsStatelessService" the message I received is:
***************************
Violation in class app.TheServiceName. The class is marked as stateless but contains the non-final field 'aVariableName'
***************************
I've searched a little about that but not found a lot of tricks about that. Can someone please explain me what the real meaning of this ruleset and what I have to do to solve this problem/
About the second kind of ruleSet I found somewhere that it solved by overriding those methods in all the domain classes but is hat an obligation, a need, or do I just have to modify the ruleSet File to avoid those kinds of messages related to those rulesets?
And that introduces my last question: where to find this ruleSet File( the default one within codenarc) or the one i must include myself?
I find that the GrailsStatelessService rule does sometimes catch a real violation, so rather than disabling it, I modify it to ignore my commonly used field names.
BuildConfig.groovy:
codenarc.propertiesFile = 'grails-app/conf/codenarc.properties'
codenarc.properties:
GrailsStatelessService.addToIgnoreFieldNames=grailsApplication,applicationContext,sessionFactory
I am able to configure this CodeNarc rules as follows:
Install CodeNarc plugin [grails install-plugin codenarc]
Add following line in BuildConfig.groovy file [for details configuration]:
codenarc.propertiesFile = 'grails-app/conf/codenarc.properties'
In codenarc.properties - file, I add following rule for ignore few RULEs
codenarc.properties = {
GrailsDomainHasEquals.enabled = false
GrailsDomainHasToString.enabled = false
EmptyMethod.enabled = false
}
Run following command for generating CodeNarc Report: grails codenarc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With