Saturday 22 September 2012

Excluding classes in the CodeNarc Grails plugin

Sometimes you don't want CodeNarc to inspect certain classes, for example, the domain classes the Spring Security Core Plugin creates.

There is a property called doNotApplyToClassNames that you can use to omit those classes you don't want to be inspected for a given CodeNarc rule.

If you want to use it you will only have to put the name of the rule followed by the doNotApplyToClassNames literal and the specify the names of the classes you don´t want to be inspected for that particular rule.

NameOfTheRule.doNotApplyToClassNames="ClassOne, ClassTwo"

In this particular situation I didn't want CodeNarc to bother me about the lack of equals and hashcode methods in those domain classes so I wrote the following lines in my CodeNarc configuration (inside BuildConfig.groovy)

GrailsDomainHasEquals.doNotApplyToClassNames="Role, User, UserRole"
GrailsDomainHasToString.doNotApplyToClassNames="Role, User, UserRole"


Here's the codenarc closure configuration:

codenarc.properties = {
          GrailsPublicControllerMethod.enabled = false

          GrailsDomainHasEquals.doNotApplyToClassNames="Role, User, UserRole"
          GrailsDomainHasToString.doNotApplyToClassNames="Role, User, UserRole"
}

2 comments:

  1. Hola! Buenísimo el tip, pero ¿conocés alguna forma de excluir de todas las reglas ciertos archivos? Quiero excluir, por ejemplo, el LoginController de todas las reglas (estoy usando Spring Security).
    Gracias!

    ReplyDelete
  2. ERPTREE handles oracle fusion HCM training and its modules maintaining classroom based training with
    the self-paced videos. An expert having ten plus years of self-experience handles the training period through online and explains each and every point perfectly. We recently launched our institute in the USA and getting the best reputation over there.


    Oracle fusion HCM Online Training

    Oracle Fusion HCM Training

    ReplyDelete