Showing posts with label codenarc. Show all posts
Showing posts with label codenarc. Show all posts

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"
}