Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grails-CodeNarc and Service Stateless ruleSet

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?

like image 976
KAdjevi Avatar asked Dec 19 '25 23:12

KAdjevi


2 Answers

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
like image 99
doelleri Avatar answered Dec 21 '25 23:12

doelleri


I am able to configure this CodeNarc rules as follows:

  1. Install CodeNarc plugin [grails install-plugin codenarc]

  2. Add following line in BuildConfig.groovy file [for details configuration]:

    codenarc.propertiesFile = 'grails-app/conf/codenarc.properties'
    
  3. In codenarc.properties - file, I add following rule for ignore few RULEs

    codenarc.properties = {
    
      GrailsDomainHasEquals.enabled = false
    
      GrailsDomainHasToString.enabled = false
    
      EmptyMethod.enabled = false
    
    }
    
  4. Run following command for generating CodeNarc Report: grails codenarc

like image 33
abanmitra Avatar answered Dec 21 '25 23:12

abanmitra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!