Skip to content

Commit 20c3278

Browse files
matreijamesfredley
andauthored
Reformat code (#14925)
* build: add Checkstyle and Codenarc support 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. * style: enforce newline at end of file 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 * style: enforce no tab characters 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 * style: add Checkstyle `@SuppressWarnings` support Allows selective suppression of specific Checkstyle rules where necessary, improving flexibility for edge cases or legacy code. * style: enforce no unused imports 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 * style: enforce no wildcard imports 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 * style: enforce no redundant imports 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 * style: enforce import ordering and grouping 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. * style: whitespace missed previously * style(groovy): enforce no unnecessary semicolons * style(groovy): enforce no unnecessary `public` keyword * style(groovy): enforce no unnecessary `GString` 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. * fix: add ast util imports These were star-imported and we do not do that anymore. * style(groovy): update ast sources for `UnnecessaryGString` * style(groovy): update testFixtures sources for `UnnecessaryGString` * style(groovy): update e2eTest sources for `UnnecessaryGString` * style: enforce indentation Add the Checkstyle and Codenarc Indentation rules. Use the default setting of four spaces. * style: disable style check on integrationTest * style(groovy): enforce misc whitespace rules * style: add `io.spring` to spring import group * chore: remove unused imports after merge * fix: restore accidentally renamed parameter * style: update code style in geb testFixtures * style: move spring-related imports * style(java): enforce misc whitespace rules * fix(deps): update Checkstyle and CodeNarc Update to Checkstyle to 11.0.0 and use Groovy 4 version of CodeNarc 3.6.0. * style(groovy): enforce rule `UnnecessaryConstructor` * style(groovy): enforce rule `UnnecessaryDotClass` * style(groovy): enforce rule `UnnecessaryOverridingMethod` * style(groovy): enforce rule `UnnecessarySafeNavigationOperator` * style: cleanup generics to use diamond Manual cleanup to use diamond operator introduced in Java 7. * style: fix indentation issue * style(groovy): use parentheses in method calls Manually updated Groovy code to consistently use parentheses in method calls. Groovy allows omitting parentheses (useful in DSLs or scripts), but explicit parentheses improve readability and maintainability in framework code. * style(groovy): add space after type casts Manually updated Groovy code to consistently include a space after type casts, improving readability and consistency. * refactor(logging): use lazy-evaluated log messages - Switch to lazily evaluated log messages where possible - Standardize on the `@Slf4j` annotation - Remove redundant logging guards - Remove unused logging annotations * back to single quotes on documentation links * chore: remove code style enforcement The code style enforcement will be added in another commit that is not added to `.git-blame-ignore-revs`. * style: optimize imports --------- Co-authored-by: James Fredley <[email protected]>
1 parent 1b1ef2d commit 20c3278

File tree

2,236 files changed

+35145
-31977
lines changed

Some content is hidden

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

2,236 files changed

+35145
-31977
lines changed

grails-async/core/src/main/groovy/grails/async/DelegateAsync.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ import org.codehaus.groovy.transform.GroovyASTTransformationClass
6363
@Documented
6464
@Retention(RetentionPolicy.SOURCE)
6565
@Target([ElementType.TYPE, ElementType.FIELD])
66-
@GroovyASTTransformationClass("org.grails.async.transform.internal.DelegateAsyncTransformation")
66+
@GroovyASTTransformationClass('org.grails.async.transform.internal.DelegateAsyncTransformation')
6767
@interface DelegateAsync {
68+
6869
Class value() default DelegateAsync
6970
}

grails-async/core/src/main/groovy/grails/async/PromiseFactory.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
*/
1919
package grails.async
2020

21+
import java.util.concurrent.TimeUnit
22+
2123
import grails.async.decorator.PromiseDecorator
2224
import grails.async.decorator.PromiseDecoratorLookupStrategy
2325

24-
import java.util.concurrent.TimeUnit
25-
2626
/**
2727
* An interface capable of creating {@link Promise} instances. The {@link Promises} static methods use this
2828
* interface to create promises. The default Promise creation mechanism can be overridden by setting {@link Promises#setPromiseFactory(PromiseFactory)}

grails-async/core/src/main/groovy/grails/async/PromiseList.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
*/
1919
package grails.async
2020

21+
import java.util.concurrent.TimeUnit
22+
2123
import groovy.transform.AutoFinal
2224
import groovy.transform.CompileStatic
2325

24-
import java.util.concurrent.TimeUnit
25-
2626
/**
2727
* A list of promises
2828
*
@@ -138,7 +138,7 @@ class PromiseList<T> implements Promise<List<T>> {
138138

139139
@Override
140140
boolean isDone() {
141-
return promises.every {promise -> promise.isDone() }
141+
return promises.every { promise -> promise.isDone() }
142142
}
143143

144144
@Override

grails-async/core/src/main/groovy/grails/async/PromiseMap.groovy

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
*/
1919
package grails.async
2020

21+
import java.util.concurrent.TimeUnit
22+
2123
import groovy.transform.AutoFinal
2224
import groovy.transform.CompileStatic
2325

24-
import java.util.concurrent.TimeUnit
25-
2626
/**
2727
* A map-like structure for promises that allows waiting for all values in the map to be populated before
2828
* executing a callback
@@ -55,7 +55,7 @@ class PromiseMap<K,V> implements Promise<Map<K,V>> {
5555

5656
@Override
5757
boolean isDone() {
58-
return promisesKeys.keySet().every {it.isDone() }
58+
return promisesKeys.keySet().every { it.isDone() }
5959
}
6060

6161
@Override
@@ -213,7 +213,7 @@ class PromiseMap<K,V> implements Promise<Map<K,V>> {
213213
Map<K,V> get() throws Throwable {
214214
def promises = promises.values()
215215
Map<K,V> resultMap = [:]
216-
for(Promise<V> promise : promises) {
216+
for (Promise<V> promise : promises) {
217217
V value = promise.get()
218218
resultMap.put(promisesKeys.get(promise), value)
219219
}
@@ -232,7 +232,7 @@ class PromiseMap<K,V> implements Promise<Map<K,V>> {
232232
List<Promise<V>> promises = new ArrayList<Promise<V>>(promises.values())
233233
Promises.waitAll(promises, timeout, units)
234234
Map<K,V> resultMap = [:]
235-
for(Promise<V> promise : promises) {
235+
for (Promise<V> promise : promises) {
236236
V value = promise.get()
237237
resultMap.put(promisesKeys.get(promise), value)
238238
}
@@ -245,7 +245,7 @@ class PromiseMap<K,V> implements Promise<Map<K,V>> {
245245
Promises.onComplete(promises) { List<V> values ->
246246
Map<K,V> resultMap = [:]
247247
int i = 0
248-
for(V value in values) {
248+
for (V value in values) {
249249
Promise<V> promise = promises[i]
250250
K key = promisesKeys.get(promise)
251251
resultMap.put(key, value)

grails-async/core/src/main/groovy/grails/async/Promises.groovy

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
*/
1919
package grails.async
2020

21-
import grails.async.decorator.PromiseDecorator
21+
import java.util.concurrent.TimeUnit
22+
2223
import groovy.transform.AutoFinal
2324
import groovy.transform.CompileStatic
24-
import org.grails.async.factory.PromiseFactoryBuilder
2525

26-
import java.util.concurrent.TimeUnit
26+
import grails.async.decorator.PromiseDecorator
27+
import org.grails.async.factory.PromiseFactoryBuilder
2728

2829
/**
2930
* Factory class for working with {@link Promise} instances
@@ -164,6 +165,6 @@ class Promises {
164165
* @see PromiseFactory#createBoundPromise(java.lang.Object)
165166
*/
166167
static<T> Promise<T> createBoundPromise(T value) {
167-
return getPromiseFactory().createBoundPromise(value)
168+
return getPromiseFactory().createBoundPromise(value)
168169
}
169170
}

grails-async/core/src/main/groovy/grails/async/factory/AbstractPromiseFactory.groovy

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,19 @@
1818
*/
1919
package grails.async.factory
2020

21+
import java.util.concurrent.ConcurrentLinkedQueue
22+
23+
import groovy.transform.AutoFinal
24+
import groovy.transform.CompileStatic
25+
2126
import grails.async.Promise
2227
import grails.async.PromiseFactory
2328
import grails.async.PromiseList
2429
import grails.async.PromiseMap
2530
import grails.async.decorator.PromiseDecorator
2631
import grails.async.decorator.PromiseDecoratorLookupStrategy
27-
import groovy.transform.AutoFinal
28-
import groovy.transform.CompileStatic
2932
import org.grails.async.factory.BoundPromise
3033

31-
import java.util.concurrent.ConcurrentLinkedQueue
32-
3334
/**
3435
* Abstract implementation of the {@link grails.async.PromiseFactory} interface, subclasses should extend
3536
* this class to obtain common generic functionality
@@ -59,13 +60,13 @@ abstract class AbstractPromiseFactory implements PromiseFactory {
5960
}
6061

6162
<T> Closure<T> applyDecorators(Closure<T> closure, List<PromiseDecorator> decorators) {
62-
List<PromiseDecorator> allDecorators = decorators != null ? new ArrayList<PromiseDecorator>(decorators): new ArrayList<PromiseDecorator>()
63+
List<PromiseDecorator> allDecorators = decorators != null ? new ArrayList<PromiseDecorator>(decorators) : new ArrayList<PromiseDecorator>()
6364
for (PromiseDecoratorLookupStrategy lookupStrategy : lookupStrategies) {
6465
allDecorators.addAll(lookupStrategy.findDecorators())
6566
}
6667
def decoratedClosure = closure
6768
if (!allDecorators.empty) {
68-
for(PromiseDecorator decorator : allDecorators) {
69+
for (PromiseDecorator decorator : allDecorators) {
6970
decoratedClosure = decorator.decorate(decoratedClosure)
7071
}
7172
}
@@ -76,7 +77,7 @@ abstract class AbstractPromiseFactory implements PromiseFactory {
7677
* @see PromiseFactory#createPromise(java.util.List)
7778
*/
7879
<T> Promise<List<T>> createPromise(List<Closure<T>> closures) {
79-
return createPromise(closures,null)
80+
return createPromise(closures, null)
8081
}
8182

8283
/**
@@ -99,7 +100,7 @@ abstract class AbstractPromiseFactory implements PromiseFactory {
99100
*/
100101
<T> Promise<List<T>> createPromise(Promise<T>... promises) {
101102
PromiseList<T> promiseList = new PromiseList<>()
102-
for(Promise<T> promise : promises) {
103+
for (Promise<T> promise : promises) {
103104
promiseList.add(promise)
104105
}
105106
return promiseList
@@ -133,7 +134,7 @@ abstract class AbstractPromiseFactory implements PromiseFactory {
133134
}
134135

135136
protected <T> Promise<T> createPromiseInternal(Closure<T> closure) {
136-
return createPromise(closure)
137+
return createPromise(closure)
137138
}
138139

139140
/**

grails-async/core/src/main/groovy/org/grails/async/factory/BoundPromise.groovy

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
*/
1919
package org.grails.async.factory
2020

21-
import grails.async.Promise
21+
import java.util.concurrent.TimeUnit
22+
2223
import groovy.transform.CompileStatic
2324

24-
import java.util.concurrent.TimeUnit
25+
import grails.async.Promise
2526

2627
/**
2728
* A bound promise is a promise which is already resolved and doesn't require any asynchronous processing to calculate the value

grails-async/core/src/main/groovy/org/grails/async/factory/PromiseFactoryBuilder.groovy

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
package org.grails.async.factory
2121

2222
import grails.async.PromiseFactory
23-
import grails.async.Promises
2423
import groovy.transform.CompileStatic
2524
import groovy.util.logging.Slf4j
2625
import org.grails.async.factory.future.CachedThreadPoolPromiseFactory
@@ -43,13 +42,13 @@ class PromiseFactoryBuilder {
4342
List<PromiseFactory> promiseFactories = ServiceLoader.load(PromiseFactory).toList()
4443

4544
PromiseFactory promiseFactory
46-
if(promiseFactories.isEmpty()) {
47-
log.debug 'No PromiseFactory implementation found. Using default ExecutorService promise factory.'
45+
if (promiseFactories.isEmpty()) {
46+
log.debug('No PromiseFactory implementation found. Using default ExecutorService promise factory.')
4847
promiseFactory = new CachedThreadPoolPromiseFactory()
4948
}
5049
else {
5150
promiseFactory = promiseFactories.first()
52-
log.debug 'Found PromiseFactory implementation to use [{}]', promiseFactory
51+
log.debug('Found PromiseFactory implementation to use [{}]', promiseFactory)
5352
}
5453

5554
return promiseFactory

grails-async/core/src/main/groovy/org/grails/async/factory/SynchronousPromise.groovy

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
*/
1919
package org.grails.async.factory
2020

21-
import grails.async.Promise
21+
import java.util.concurrent.TimeUnit
22+
2223
import groovy.transform.CompileStatic
2324

24-
import java.util.concurrent.TimeUnit
25+
import grails.async.Promise
2526

2627
/**
2728
* A promise that executes synchronously, in the same thread as the creator

grails-async/core/src/main/groovy/org/grails/async/factory/SynchronousPromiseFactory.groovy

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818
*/
1919
package org.grails.async.factory
2020

21-
import grails.async.Promise
22-
import grails.async.PromiseList
23-
import grails.async.factory.AbstractPromiseFactory
21+
import java.util.concurrent.TimeUnit
22+
2423
import groovy.transform.AutoFinal
2524
import groovy.transform.CompileStatic
2625

27-
import java.util.concurrent.TimeUnit
26+
import grails.async.Promise
27+
import grails.async.PromiseList
28+
import grails.async.factory.AbstractPromiseFactory
2829

2930
/**
3031
* A {@link grails.async.PromiseFactory} implementation that constructors promises that execute synchronously.
@@ -54,7 +55,7 @@ class SynchronousPromiseFactory extends AbstractPromiseFactory {
5455
promise = new SynchronousPromise<T>(closures[0])
5556
} else {
5657
def promiseList = new PromiseList()
57-
for(p in closures) {
58+
for (p in closures) {
5859
promiseList << p
5960
}
6061
promise = promiseList

0 commit comments

Comments
 (0)