Skip to content

Commit 3bb575b

Browse files
committed
fix: add style enforcement
1 parent 55af4eb commit 3bb575b

File tree

99 files changed

+427
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+427
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<!DOCTYPE suppressions PUBLIC "-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN" "https://checkstyle.org/dtds/suppressions_1_2.dtd">
21+
<suppressions>
22+
</suppressions>
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<!DOCTYPE module PUBLIC "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN" "https://checkstyle.org/dtds/configuration_1_3.dtd">
21+
<module name="Checker">
22+
23+
<!-- Suppressions -->
24+
<module name="SuppressionFilter">
25+
<property name="file" value="${config_loc}/checkstyle-suppressions.xml"/>
26+
</module>
27+
28+
<!-- Root Checks -->
29+
<module name="NewlineAtEndOfFile"/>
30+
<module name="FileTabCharacter"/>
31+
<module name="SuppressWarningsFilter"/>
32+
33+
<!-- TreeWalker Checks -->
34+
<module name="TreeWalker">
35+
36+
<module name="SuppressWarningsHolder"/>
37+
38+
<!-- Imports -->
39+
<module name="AvoidStarImport"/>
40+
<module name="RedundantImport"/>
41+
<module name="UnusedImports">
42+
<property name="processJavadoc" value="false"/>
43+
</module>
44+
<module name="ImportOrderCheck">
45+
<!-- Import groups: JAVA, JAVAX, GROOVY, JAKARTA, OTHER, SPRING, GRAILS, STATIC -->
46+
<property name="groups" value="java,javax,/^(groovy|org\.apache\.groovy|org\.codehaus\.groovy)\..+/,jakarta,*,/(^io\.spring|org\.springframework)\..+/,/^(grails|org\.apache\.grails|org\.grails)\..+/"/>
47+
<property name="ordered" value="true"/>
48+
<property name="option" value="bottom"/>
49+
<property name="separated" value="true"/>
50+
<property name="sortStaticImportsAlphabetically" value="true"/>
51+
</module>
52+
53+
<!-- Whitespace -->
54+
<module name="CommentsIndentation"/>
55+
<module name="EmptyLineSeparator">
56+
<property name="allowMultipleEmptyLines" value="false"/>
57+
<property name="allowMultipleEmptyLinesInsideClassMembers" value="false"/>
58+
<property name="allowNoEmptyLineBetweenFields" value="true"/>
59+
<property name="tokens" value="IMPORT, STATIC_IMPORT, CLASS_DEF, INTERFACE_DEF, ENUM_DEF, STATIC_INIT, INSTANCE_INIT, METHOD_DEF, CTOR_DEF, VARIABLE_DEF, RECORD_DEF, COMPACT_CTOR_DEF"/><!-- PACKAGE_DEF removed from defaults -->
60+
</module>
61+
<module name="GenericWhitespace"/>
62+
<module name="Indentation"/>
63+
<module name="NoLineWrap"/>
64+
<module name="MethodParamPad"/>
65+
<module name="NoWhitespaceAfter">
66+
<property name="tokens" value="AT, INC, DEC, UNARY_MINUS, UNARY_PLUS, BNOT, LNOT, DOT, ARRAY_DECLARATOR, INDEX_OP"/><!-- ARRAY_INIT removed from defaults -->
67+
</module>
68+
<module name="NoWhitespaceBefore"/>
69+
<module name="NoWhitespaceBeforeCaseDefaultColon"/>
70+
<module name="OperatorWrap">
71+
<property name="option" value="eol"/>
72+
</module>
73+
<module name="ParenPad"/>
74+
<module name="SeparatorWrap">
75+
<property name="option" value="nl"/>
76+
<property name="tokens" value="DOT"/>
77+
</module>
78+
<module name="SingleSpaceSeparator"/>
79+
<module name="TypecastParenPad"/>
80+
<module name="WhitespaceAfter"/>
81+
<module name="WhitespaceAround">
82+
<property name="allowEmptyCatches" value="true"/>
83+
<property name="allowEmptyConstructors" value="true"/>
84+
<property name="allowEmptyMethods" value="true"/>
85+
<property name="allowEmptyTypes" value="true"/>
86+
</module>
87+
</module>
88+
89+
</module>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
ruleset {
20+
21+
description 'A Codenarc ruleset for the Grails codebase'
22+
23+
BracesForClass
24+
ClassStartsWithBlankLine {
25+
ignoreInnerClasses = true
26+
}
27+
ClosureStatementOnOpeningLineOfMultipleLineClosure
28+
ConsecutiveBlankLines
29+
FileEndsWithoutNewline
30+
NoTabCharacter
31+
DuplicateImport
32+
ImportFromSamePackage
33+
Indentation
34+
MisorderedStaticImports {
35+
comesBefore = false // static imports should come last
36+
}
37+
MissingBlankLineAfterImports
38+
MissingBlankLineAfterPackage
39+
MissingBlankLineBeforeAnnotatedField
40+
NoWildcardImports
41+
SpaceAfterCatch
42+
SpaceAfterClosingBrace
43+
SpaceAfterComma
44+
SpaceAfterFor
45+
SpaceAfterIf
46+
SpaceAfterMethodCallName
47+
SpaceAfterMethodDeclarationName
48+
SpaceAfterNotOperator
49+
SpaceAfterOpeningBrace {
50+
ignoreEmptyBlock = true
51+
}
52+
SpaceAfterSemicolon
53+
SpaceAfterSwitch
54+
SpaceAfterWhile
55+
SpaceAroundClosureArrow
56+
SpaceAroundMapEntryColon {
57+
characterAfterColonRegex = ' '
58+
}
59+
SpaceAroundOperator {
60+
ignoreParameterDefaultValueAssignments = false
61+
}
62+
SpaceBeforeClosingBrace {
63+
ignoreEmptyBlock = true
64+
}
65+
SpaceBeforeOpeningBrace
66+
SpaceInsideParentheses
67+
UnnecessaryConstructor
68+
UnnecessaryDotClass
69+
UnnecessaryGroovyImport
70+
UnnecessaryGString
71+
UnnecessaryOverridingMethod
72+
UnnecessaryPublicModifier
73+
UnnecessarySafeNavigationOperator
74+
UnnecessarySemicolon
75+
UnusedImport
76+
}

gradle.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ micronautVersion=4.6.5
6262
micronautSerdeJacksonVersion=2.11.0
6363
grailsSpringSecurityVersion=7.0.0-SNAPSHOT
6464

65+
# build dependencies for code quality checks
66+
checkstyleVersion=11.0.0
67+
codenarcVersion=3.6.0-groovy-4.0
68+
6569
# This prevents the Grails Gradle Plugin from unnecessarily excluding slf4j-simple in the generated POMs
6670
# https://github.com/apache/grails-gradle-plugin/issues/222
6771
slf4jPreventExclusion=true

gradle/code-style-config.gradle

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
apply plugin: 'checkstyle'
21+
apply plugin: 'codenarc'
22+
23+
extensions.configure(CheckstyleExtension) {
24+
// Explicit `it` is required in extension configuration
25+
it.configDirectory = rootProject.layout.projectDirectory.dir('etc/config/checkstyle').asFile
26+
it.maxWarnings = 0
27+
it.showViolations = true
28+
it.ignoreFailures = false
29+
it.toolVersion = checkstyleVersion
30+
}
31+
32+
extensions.configure(CodeNarcExtension) {
33+
// Explicit `it` is required in extension configuration
34+
it.configFile = rootProject.layout.projectDirectory.file('etc/config/codenarc/codenarc.groovy').asFile
35+
it.toolVersion = codenarcVersion
36+
}
37+
38+
// Do not run Code Style checks if the property 'skipCodeStyle' is defined
39+
if (findProperty('skipCodeStyle')) {
40+
tasks.withType(Checkstyle).configureEach { enabled = false }
41+
tasks.withType(CodeNarc).configureEach { enabled = false }
42+
}
43+
44+
tasks.register('codeStyle') {
45+
group = 'verification'
46+
description = 'Runs code style checks'
47+
dependsOn(tasks.withType(Checkstyle))
48+
dependsOn(tasks.withType(CodeNarc))
49+
}
50+
51+
tasks.named('checkstyleMain') {
52+
group = 'verification'
53+
}
54+
55+
tasks.named('checkstyleTest') {
56+
group = 'verification'
57+
enabled = false // Do not check test sources at this time
58+
}
59+
60+
tasks.named('codenarcMain') {
61+
group = 'verification'
62+
}
63+
64+
tasks.named('codenarcTest') {
65+
group = 'verification'
66+
enabled = false // Do not check test sources at this time
67+
}
68+
69+
gradle.taskGraph.whenReady {
70+
if (tasks.findByName('codenarcIntegrationTest')) {
71+
tasks.named('codenarcIntegrationTest') {
72+
group = 'verification'
73+
enabled = false // Do not check test sources at this time
74+
}
75+
}
76+
}

grails-async/core/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ dependencies {
4747
apply {
4848
// java-configuration must be applied first since tasks are now lazy registered
4949
from rootProject.layout.projectDirectory.file('gradle/java-config.gradle')
50+
from rootProject.layout.projectDirectory.file('gradle/code-style-config.gradle')
5051
from rootProject.layout.projectDirectory.file('gradle/docs-config.gradle')
5152
from rootProject.layout.projectDirectory.file('gradle/publish-config.gradle')
5253
from rootProject.layout.projectDirectory.file('gradle/test-config.gradle')

grails-async/gpars/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ dependencies {
4747
apply {
4848
// java-configuration must be applied first since tasks are now lazy registered
4949
from rootProject.layout.projectDirectory.file('gradle/java-config.gradle')
50+
from rootProject.layout.projectDirectory.file('gradle/code-style-config.gradle')
5051
from rootProject.layout.projectDirectory.file('gradle/docs-config.gradle')
5152
from rootProject.layout.projectDirectory.file('gradle/publish-config.gradle')
5253
from rootProject.layout.projectDirectory.file('gradle/test-config.gradle')

grails-async/plugin/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ dependencies {
5757
apply {
5858
// java-configuration must be applied first since tasks are now lazy registered
5959
from rootProject.layout.projectDirectory.file('gradle/java-config.gradle')
60+
from rootProject.layout.projectDirectory.file('gradle/code-style-config.gradle')
6061
from rootProject.layout.projectDirectory.file('gradle/docs-config.gradle')
6162
from rootProject.layout.projectDirectory.file('gradle/publish-config.gradle')
6263
from rootProject.layout.projectDirectory.file('gradle/test-config.gradle')

grails-async/rxjava/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ dependencies {
4343
apply {
4444
// java-configuration must be applied first since tasks are now lazy registered
4545
from rootProject.layout.projectDirectory.file('gradle/java-config.gradle')
46+
from rootProject.layout.projectDirectory.file('gradle/code-style-config.gradle')
4647
from rootProject.layout.projectDirectory.file('gradle/docs-config.gradle')
4748
from rootProject.layout.projectDirectory.file('gradle/publish-config.gradle')
4849
from rootProject.layout.projectDirectory.file('gradle/test-config.gradle')

grails-async/rxjava2/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ dependencies {
4343
apply {
4444
// java-configuration must be applied first since tasks are now lazy registered
4545
from rootProject.layout.projectDirectory.file('gradle/java-config.gradle')
46+
from rootProject.layout.projectDirectory.file('gradle/code-style-config.gradle')
4647
from rootProject.layout.projectDirectory.file('gradle/docs-config.gradle')
4748
from rootProject.layout.projectDirectory.file('gradle/publish-config.gradle')
4849
from rootProject.layout.projectDirectory.file('gradle/test-config.gradle')

0 commit comments

Comments
 (0)