Copilot commented on code in PR #15404: URL: https://github.com/apache/grails-core/pull/15404#discussion_r2817864762
########## grails-doc/src/en/guide/testing/codeQuality.adoc: ########## @@ -0,0 +1,177 @@ +//// +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + +https://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +//// + +https://codenarc.org/[CodeNarc] is a static analysis tool for Groovy that finds defects, poor coding practices, inconsistencies, style issues, and more. Grails projects can integrate CodeNarc via the Gradle https://docs.gradle.org/current/userguide/codenarc_plugin.html[CodeNarc plugin]. + +==== Adding CodeNarc to Your Build + +Apply the CodeNarc plugin in your `build.gradle`: + +[source,groovy] +---- +plugins { + id 'codenarc' +} + +dependencies { + codenarc 'org.codenarc:CodeNarc:3.7.0-groovy-4.0' +} + +codenarc { + configFile = file('config/codenarc/codenarc.groovy') + ignoreFailures = true Review Comment: In this sample configuration, `ignoreFailures = true` means the `maxPriority1Violations = 0` threshold will never fail the build (the violations are always ignored). Recommend either removing `ignoreFailures` (if you want the thresholds to enforce) or removing the `maxPriority*Violations` settings (if you want reporting only). ```suggestion ``` ########## grails-doc/src/en/guide/testing/codeQuality.adoc: ########## @@ -0,0 +1,177 @@ +//// +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + +https://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +//// + +https://codenarc.org/[CodeNarc] is a static analysis tool for Groovy that finds defects, poor coding practices, inconsistencies, style issues, and more. Grails projects can integrate CodeNarc via the Gradle https://docs.gradle.org/current/userguide/codenarc_plugin.html[CodeNarc plugin]. + +==== Adding CodeNarc to Your Build + +Apply the CodeNarc plugin in your `build.gradle`: + +[source,groovy] +---- +plugins { + id 'codenarc' +} + +dependencies { + codenarc 'org.codenarc:CodeNarc:3.7.0-groovy-4.0' +} + +codenarc { + configFile = file('config/codenarc/codenarc.groovy') + ignoreFailures = true + maxPriority1Violations = 0 +} +---- + +NOTE: Use the `-groovy-4.0` variant of CodeNarc for Grails 7 projects (which use Groovy 4.x). The plain `3.7.0` artifact is built for Groovy 3.x. + +You can then run CodeNarc with: + +[source,bash] +---- +$ ./gradlew codenarcMain +---- + +The HTML report is written to `build/reports/codenarc/main.html`. + +==== GORM AST Compatibility + +CodeNarc provides pre-built rulesets that can be imported as a group using the `ruleset()` syntax: + +[source,groovy] +---- +// config/codenarc/codenarc.groovy - DO NOT use this approach in Grails projects +ruleset { + ruleset('rulesets/basic.xml') + ruleset('rulesets/formatting.xml') + ruleset('rulesets/unused.xml') +} +---- + +WARNING: Importing entire rulesets with `ruleset('rulesets/xxx.xml')` in a Grails project causes compilation failures. This is because some CodeNarc rules (known as "enhanced" rules) perform semantic analysis at Groovy compiler phase 4. These enhanced rules attempt to resolve AST-transformed classes such as `OrderedGormTransformation` and `ServiceTransformation`, but CodeNarc compiles each source file independently without GORM's AST transformation processors on its 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. + +==== Recommended Configuration + +The solution is to list individual rules explicitly rather than importing entire rulesets. This avoids pulling in enhanced rules that require GORM's AST infrastructure. The Grails framework's own build uses this approach: + +[source,groovy] +---- +// config/codenarc/codenarc.groovy +ruleset { + + description 'CodeNarc ruleset for a Grails application' Review Comment: This section says the snippet is “based on” / reflects the Grails framework’s own CodeNarc ruleset, but the included rule list doesn’t match the referenced canonical file in this repo (e.g., Grails’ ruleset includes `MissingBlankLineBeforeAnnotatedField` and `UnnecessaryGString`, while this snippet adds many rules not present there). To avoid misleading readers and future drift, consider either (1) making the snippet match the canonical `build-logic/.../codenarc.groovy` exactly, or (2) shortening the snippet and pointing readers directly at the canonical file for the full up-to-date rule list. ```suggestion // Example config/codenarc/codenarc.groovy // For the canonical, up-to-date Grails ruleset, see build-logic/.../codenarc.groovy in the Grails source. ruleset { description 'Example CodeNarc ruleset for a Grails application' ``` ########## grails-doc/src/en/guide/testing/codeQuality.adoc: ########## @@ -0,0 +1,177 @@ +//// +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + +https://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +//// + +https://codenarc.org/[CodeNarc] is a static analysis tool for Groovy that finds defects, poor coding practices, inconsistencies, style issues, and more. Grails projects can integrate CodeNarc via the Gradle https://docs.gradle.org/current/userguide/codenarc_plugin.html[CodeNarc plugin]. + +==== Adding CodeNarc to Your Build + +Apply the CodeNarc plugin in your `build.gradle`: + +[source,groovy] +---- +plugins { + id 'codenarc' +} + +dependencies { + codenarc 'org.codenarc:CodeNarc:3.7.0-groovy-4.0' +} Review Comment: The example pins CodeNarc to `3.7.0-groovy-4.0`, but this repository currently uses `codenarcVersion=3.6.0-groovy-4.0` (see root `gradle.properties`). Consider aligning the docs with the version Grails itself uses (or wording it as “use the current Grails build’s CodeNarc version” / “use a Groovy 4 variant” to avoid the docs going stale). -- 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]
