-
-
Notifications
You must be signed in to change notification settings - Fork 962
WIP: Enforce Code Style #14925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
matrei
wants to merge
20
commits into
apache:7.0.x
Choose a base branch
from
matrei:code-style
base: 7.0.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
WIP: Enforce Code Style #14925
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add Checkstyle and Codenarc configuration for the `grails.core.ROOT` and `grails-gradle` projects to enforce consistent coding standards. Rules will be introduced gradually, and source files reformatted incrementally to maintain a manageable review process and avoid overwhelming diffs. Formatting commits will be squashed before merging to minimize noise in the project history.
Add the `NewlineAtEndOfFile` Checkstyle rule and `FileEndsWithoutNewline` Codenarc rule to ensure all source files end with a single newline character. This is a long-standing POSIX convention and is assumed by many Unix tools. It also helps avoid unnecessary noise in version control diffs and ensures consistent formatting across editors and operating systems. Most modern IDEs can be configured to add the final newline automatically. https://checkstyle.sourceforge.io/checks/misc/newlineatendoffile.html https://codenarc.org/codenarc-rules-formatting.html#fileendswithoutnewline-rule
Add the `FileTabCharacter` Checkstyle rule and `NoTabCharacter` Codenarc rule to ensure that source files use spaces instead of tabs. This helps maintain consistent indentation and avoids formatting issues across different editors and environments. https://checkstyle.sourceforge.io/checks/whitespace/filetabcharacter.html https://codenarc.org/codenarc-rules-convention.html#notabcharacter-rule
Allows selective suppression of specific Checkstyle rules where necessary, improving flexibility for edge cases or legacy code.
Add the Checkstyle `UnusedImports` rule and the Codenarc `UnusedImport` and `UnnecessaryGroovyImport` rules. These checks help clean up forgotten or unnecessary import statements, keeping the codebase tidy and easier to maintain. https://checkstyle.sourceforge.io/checks/imports/unusedimports.html#UnusedImports https://codenarc.org/codenarc-rules-imports.html#unusedimport-rule https://codenarc.org/codenarc-rules-imports.html#unnecessarygroovyimport-rule
@@ -62,6 +62,10 @@ micronautVersion=4.6.5 | |||
micronautSerdeJacksonVersion=2.11.0 | |||
grailsSpringSecurityVersion=7.0.0-SNAPSHOT | |||
|
|||
# build dependencies for code quality checks | |||
checkstyleVersion=10.26.1 | |||
codenarcVersion=3.6.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a Groovy 4 version 3.6.0-groovy-4.0
, which I think we should consider using. https://github.com/CodeNarc/CodeNarc/blob/master/CHANGELOG.md
Add the Checkstyle `AvoidStarImport` and Codenarc `NoWildcardImports` rules. https://checkstyle.sourceforge.io/checks/imports/avoidstarimport.html https://codenarc.org/codenarc-rules-imports.html#nowildcardimports-rule
Add the Checkstyle `RedunantImport` and Codenarc `DuplicateImport` and `ImportFromSamePackage` rules. https://checkstyle.sourceforge.io/checks/imports/redundantimport.html https://codenarc.org/codenarc-rules-imports.html#duplicateimport-rule https://codenarc.org/codenarc-rules-imports.html#importfromsamepackage-rule
Order imports alphabetically within these groups: 1) java 2) javax 3) groovy (groovy, org.apache.groovy, org.codehaus.groovy) 4) jakarta 5) all others 6) org.springframework 7) grails (grails, org.apache.grails, org.grails) 8) all static imports This mirrors Spring Framework’s convention and keeps imports tidy, predictable, and easy to scan. Checkstyle can enforce this for Java. I couldn’t find a way to make CodeNarc or Spotless apply the same grouping for Groovy. Most IDEs, including IntelliJ, can apply this import ordering and grouping automatically, either on save or via a shortcut, when properly configured. The code style settings can be shared in the repository to ensure consistency.
# Conflicts: # grails-common/src/main/groovy/org/apache/grails/common/annotation/RecursiveAnnotationAttributesVisitor.java # grails-common/src/main/groovy/org/apache/grails/common/compiler/asm/AnnotationMetadataReader.java # grails-common/src/main/groovy/org/apache/grails/common/compiler/asm/ClassReader.java # grails-common/src/main/groovy/org/apache/grails/common/compiler/asm/Context.java # grails-core/src/main/groovy/grails/boot/config/tools/ClassPathScanner.groovy # grails-datamapping-core/src/main/groovy/org/grails/datastore/gorm/utils/AnnotationMetadataReaderFactory.java
Description from Codenarc rule `UnnecessaryGString`: String objects should be created with single quotes, and GString objects created with double quotes. Creating normal String objects with double quotes is confusing to readers.
# Conflicts: # grails-gradle/docs-core/src/main/groovy/grails/doc/PdfBuilder.groovy # grails-gradle/docs-core/src/main/groovy/grails/doc/gradle/PublishPdf.groovy # grails-gsp/core/src/main/groovy/org/grails/gsp/compiler/GroovyPageCompiler.groovy # grails-test-examples/app1/grails-app/controllers/functionaltests/commandobjects/CommandObjectController.groovy
These were star-imported and we do not do that anymore.
Add the Checkstyle and Codenarc Indentation rules. Use the default setting of four spaces.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Rules can be introduced gradually, and source files reformatted incrementally to maintain a manageable review process and avoid overwhelming diffs.
Formatting commits will be squashed before merging to minimize noise in the project history.
Related: #14903