jamesfredley opened a new pull request, #15404:
URL: https://github.com/apache/grails-core/pull/15404

   ## Summary
   
   Adds a new "Code Quality with CodeNarc" section to the Testing chapter of 
the Grails documentation, covering Gradle plugin setup, the GORM AST 
transformer compatibility issue with ruleset imports, and the recommended 
individual-rule configuration approach.
   
   ## Problem
   
   When Grails developers integrate CodeNarc for static analysis, the natural 
approach is to import pre-built rulesets:
   
   ```groovy
   ruleset {
       ruleset('rulesets/basic.xml')
       ruleset('rulesets/formatting.xml')
   }
   ```
   
   This fails in Grails projects because some CodeNarc rules ("enhanced" rules) 
perform semantic analysis at Groovy compiler phase 4. These rules attempt to 
resolve GORM AST-transformed classes (`OrderedGormTransformation`, 
`ServiceTransformation`) that are not available on CodeNarc's classpath. The 
result is `ClassNotFoundException` or `NoClassDefFoundError` during analysis.
   
   Adding `compilationClasspath` to the CodeNarc Gradle task helps with basic 
class resolution but does not make GORM's transformation processors available, 
so enhanced rules still fail.
   
   There is currently no mention of CodeNarc anywhere in the Grails 
documentation.
   
   ## Solution
   
   The new `codeQuality.adoc` section documents:
   
   1. **Gradle plugin setup** - applying the CodeNarc plugin with the correct 
`-groovy-4.0` artifact variant
   2. **GORM AST compatibility** - explains why `ruleset()` imports fail in 
Grails projects
   3. **Recommended configuration** - lists individual rules explicitly 
(avoiding enhanced rules entirely), with a complete working example based on 
grails-core's own CodeNarc config
   4. **Separate test ruleset** - guidance on configuring a more lenient 
ruleset for Spock specs
   5. **Reference** - links to grails-core's own CodeNarc config as the 
canonical starting point
   
   ## Files Changed
   
   - `grails-doc/src/en/guide/toc.yml` - Added `codeQuality` entry under 
`testing:` section
   - `grails-doc/src/en/guide/testing/codeQuality.adoc` - New documentation file
   
   ## Verification
   
   The Grails framework's own build at 
`build-logic/plugins/src/main/resources/META-INF/org.apache.grails.buildsrc.codestyle/codenarc/codenarc.groovy`
 uses this exact individual-rule approach with 57 rules, confirming this is the 
intended pattern.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to