Skip to content

Commit d106e13

Browse files
author
Vincent Potucek
committed
Add error-prone.picnic.tech featuring Lexicographical & StaticImport
1 parent 343017b commit d106e13

File tree

228 files changed

+639
-608
lines changed

Some content is hidden

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

228 files changed

+639
-608
lines changed

gradle/libs.versions.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ bndlib = { module = "biz.aQute.bnd:biz.aQute.bndlib", version.ref = "bnd" }
3232
checkstyle = { module = "com.puppycrawl.tools:checkstyle", version.ref = "checkstyle" }
3333
classgraph = { module = "io.github.classgraph:classgraph", version = "4.8.181" }
3434
commons-io = { module = "commons-io:commons-io", version = "2.20.0" }
35-
errorProne-core = { module = "com.google.errorprone:error_prone_core", version = "2.42.0" }
35+
error-prone-core = { module = "com.google.errorprone:error_prone_core", version = "2.42.0" }
36+
error-prone-contrib = { module = "tech.picnic.error-prone-support:error-prone-contrib", version = "0.25.0" }
37+
refaster-runner = { module = "tech.picnic.error-prone-support:refaster-runner", version = "0.25.0" }
3638
fastcsv = { module = "de.siegmar:fastcsv", version = "4.0.0" }
3739
groovy = { module = "org.apache.groovy:groovy", version = "5.0.1" }
3840
groovy2-bom = { module = "org.codehaus.groovy:groovy-bom", version = "2.5.23" }

gradle/plugins/common/src/main/kotlin/junitbuild.java-nullability-conventions.gradle.kts

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import junitbuild.extensions.dependencyFromLibs
22
import net.ltgt.gradle.errorprone.errorprone
33
import net.ltgt.gradle.nullaway.nullaway
4+
import org.gradle.jvm.toolchain.JvmImplementation.J9
5+
import java.lang.System.getenv
46

57
plugins {
68
`java-library`
@@ -9,61 +11,71 @@ plugins {
911
}
1012

1113
dependencies {
12-
errorprone(dependencyFromLibs("errorProne-core"))
14+
errorprone(dependencyFromLibs("error-prone-contrib"))
15+
errorprone(dependencyFromLibs("error-prone-core"))
1316
errorprone(dependencyFromLibs("nullaway"))
17+
errorprone(dependencyFromLibs("refaster-runner"))
1418
constraints {
1519
errorprone("com.google.guava:guava") {
1620
version {
1721
require("33.4.8-jre")
1822
}
1923
because("Older versions use deprecated methods in sun.misc.Unsafe")
24+
// https://github.com/junit-team/junit-framework/pull/5039#discussion_r2414490581
2025
}
2126
}
2227
}
2328

24-
nullaway {
25-
onlyNullMarked = true
26-
}
27-
2829
tasks.withType<JavaCompile>().configureEach {
2930
options.errorprone {
30-
val shouldDisableErrorProne = java.toolchain.implementation.orNull == JvmImplementation.J9
31-
if (name == "compileJava" && !shouldDisableErrorProne) {
31+
disableAllChecks = !(J9 != java.toolchain.implementation.orNull && "compileJava" == name)
32+
if (!disableAllChecks.get()) {
33+
errorproneArgs.add("-XepOpt:Refaster:NamePattern=^(?!.*Rules\\$).*") // currently failing Refaster; might consider whitelist.
3234
disable(
33-
34-
// This check is opinionated wrt. which method names it considers unsuitable for import which includes
35-
// a few of our own methods in `ReflectionUtils` etc.
36-
"BadImport",
37-
38-
// The findings of this check are subjective because a named constant can be more readable in many cases
39-
"UnnecessaryLambda",
40-
41-
// Resolving findings for these checks requires ErrorProne's annotations which we don't want to use
42-
"AnnotateFormatMethod",
35+
"AnnotateFormatMethod", // We don`t want to use ErrorProne`s annotations.
36+
"BadImport", // This check is opinionated wrt. which method names it considers unsuitable for import which includes a few of our own methods in `ReflectionUtils` etc.
4337
"DoNotCallSuggester",
44-
"InlineMeSuggester",
4538
"ImmutableEnumChecker",
46-
47-
// Resolving findings for this check requires using Guava which we don't want to use
48-
"StringSplitter",
49-
50-
// Produces a lot of findings that we consider to be false positives, for example for package-private
51-
// classes and methods
52-
"MissingSummary",
39+
"InlineMeSuggester",
40+
"MissingSummary", // Produces a lot of findings that we consider to be false positives, for example for package-private classes and methods.
41+
"StringSplitter", // We don`t want to use Guava.
42+
"UnnecessaryLambda", // The findings of this check are subjective because a named constant can be more readable in many cases.
43+
// picnic (https://error-prone.picnic.tech)
44+
"ConstantNaming",
45+
"DirectReturn", // https://github.com/junit-team/junit-framework/pull/5006#discussion_r2403984446
46+
"FormatStringConcatenation",
47+
"IdentityConversion",
48+
"MissingTestCall",
49+
"NestedOptionals",
50+
"OptionalOrElseGet",
51+
"TimeZoneUsage",
5352
)
54-
error("PackageLocation")
55-
} else {
56-
disableAllChecks = true
53+
error(
54+
"NonStaticImport",
55+
"PackageLocation",
56+
"RedundantStringConversion",
57+
"RedundantStringEscape",
58+
"LexicographicalAnnotationListing",
59+
"LexicographicalAnnotationAttributeListing",
60+
"StaticImport",
61+
)
62+
// introduce new check by compiling once:
63+
// allErrorsAsWarnings = true
64+
// non-fixable - why? in spotless its working.
65+
// errorproneArgs.addAll("-XepPatchLocation:IN_PLACE","-XepPatchChecks:ConstantNaming")
66+
// fixable
67+
// errorproneArgs.addAll("-XepPatchLocation:IN_PLACE","-XepPatchChecks:LexicographicalAnnotationListing,LexicographicalAnnotationListing,StaticImport")
5768
}
5869
nullaway {
59-
if (shouldDisableErrorProne) {
60-
disable()
61-
} else {
70+
if (J9 == java.toolchain.implementation.orNull) {
6271
enable()
72+
} else {
73+
disable()
6374
}
64-
isJSpecifyMode = true
65-
customContractAnnotations.add("org.junit.platform.commons.annotation.Contract")
6675
checkContracts = true
76+
customContractAnnotations.add("org.junit.platform.commons.annotation.Contract")
77+
isJSpecifyMode = true
78+
onlyNullMarked = true
6779
suppressionNameAliases.add("DataFlowIssue")
6880
}
6981
}

junit-jupiter-api/src/main/java/org/junit/jupiter/api/AfterAll.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@
9191
* @see TestFactory
9292
* @see TestInstance
9393
*/
94-
@Target({ ElementType.ANNOTATION_TYPE, ElementType.METHOD })
95-
@Retention(RetentionPolicy.RUNTIME)
96-
@Documented
9794
@API(status = STABLE, since = "5.0")
95+
@Documented
96+
@Retention(RetentionPolicy.RUNTIME)
97+
@Target({ ElementType.ANNOTATION_TYPE, ElementType.METHOD })
9898
public @interface AfterAll {
9999
}

junit-jupiter-api/src/main/java/org/junit/jupiter/api/AfterEach.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@
8484
* @see TestFactory
8585
* @see TestTemplate
8686
*/
87-
@Target({ ElementType.ANNOTATION_TYPE, ElementType.METHOD })
88-
@Retention(RetentionPolicy.RUNTIME)
89-
@Documented
9087
@API(status = STABLE, since = "5.0")
88+
@Documented
89+
@Retention(RetentionPolicy.RUNTIME)
90+
@Target({ ElementType.ANNOTATION_TYPE, ElementType.METHOD })
9191
public @interface AfterEach {
9292
}

junit-jupiter-api/src/main/java/org/junit/jupiter/api/Assertions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3718,8 +3718,8 @@ public static <T> T assertInstanceOf(Class<T> expectedType, @Nullable Object act
37183718
*
37193719
* @since 5.8
37203720
*/
3721-
@Contract("_, null, _ -> fail")
37223721
@API(status = STABLE, since = "5.10")
3722+
@Contract("_, null, _ -> fail")
37233723
public static <T> T assertInstanceOf(Class<T> expectedType, @Nullable Object actualValue,
37243724
Supplier<@Nullable String> messageSupplier) {
37253725
return AssertInstanceOf.assertInstanceOf(expectedType, actualValue, messageSupplier);

junit-jupiter-api/src/main/java/org/junit/jupiter/api/Assumptions.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,8 @@ public static void assumingThat(boolean assumption, Executable executable) {
284284
* @throws TestAbortedException always
285285
* @since 5.9
286286
*/
287-
@Contract(" -> fail")
288287
@API(status = STABLE, since = "5.9")
288+
@Contract(" -> fail")
289289
@SuppressWarnings("TypeParameterUnusedInFormals")
290290
public static <V> V abort() {
291291
throw new TestAbortedException();
@@ -309,8 +309,8 @@ public static <V> V abort() {
309309
* @throws TestAbortedException always
310310
* @since 5.9
311311
*/
312-
@Contract("_ -> fail")
313312
@API(status = STABLE, since = "5.9")
313+
@Contract("_ -> fail")
314314
@SuppressWarnings("TypeParameterUnusedInFormals")
315315
public static <V> V abort(String message) {
316316
throw new TestAbortedException(message);
@@ -327,8 +327,8 @@ public static <V> V abort(String message) {
327327
* @throws TestAbortedException always
328328
* @since 5.9
329329
*/
330-
@Contract("_ -> fail")
331330
@API(status = STABLE, since = "5.9")
331+
@Contract("_ -> fail")
332332
@SuppressWarnings("TypeParameterUnusedInFormals")
333333
public static <V> V abort(Supplier<String> messageSupplier) {
334334
throw new TestAbortedException(messageSupplier.get());

junit-jupiter-api/src/main/java/org/junit/jupiter/api/AutoClose.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@
7575
*
7676
* @since 5.11
7777
*/
78-
@Target({ ElementType.ANNOTATION_TYPE, ElementType.FIELD })
79-
@Retention(RetentionPolicy.RUNTIME)
80-
@Documented
8178
@API(status = MAINTAINED, since = "5.13.3")
79+
@Documented
80+
@Retention(RetentionPolicy.RUNTIME)
81+
@Target({ ElementType.ANNOTATION_TYPE, ElementType.FIELD })
8282
public @interface AutoClose {
8383

8484
/**

junit-jupiter-api/src/main/java/org/junit/jupiter/api/BeforeAll.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@
9191
* @see TestFactory
9292
* @see TestInstance
9393
*/
94-
@Target({ ElementType.ANNOTATION_TYPE, ElementType.METHOD })
95-
@Retention(RetentionPolicy.RUNTIME)
96-
@Documented
9794
@API(status = STABLE, since = "5.0")
95+
@Documented
96+
@Retention(RetentionPolicy.RUNTIME)
97+
@Target({ ElementType.ANNOTATION_TYPE, ElementType.METHOD })
9898
public @interface BeforeAll {
9999
}

junit-jupiter-api/src/main/java/org/junit/jupiter/api/BeforeEach.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@
8484
* @see TestFactory
8585
* @see TestTemplate
8686
*/
87-
@Target({ ElementType.ANNOTATION_TYPE, ElementType.METHOD })
88-
@Retention(RetentionPolicy.RUNTIME)
89-
@Documented
9087
@API(status = STABLE, since = "5.0")
88+
@Documented
89+
@Retention(RetentionPolicy.RUNTIME)
90+
@Target({ ElementType.ANNOTATION_TYPE, ElementType.METHOD })
9191
public @interface BeforeEach {
9292
}

junit-jupiter-api/src/main/java/org/junit/jupiter/api/ClassOrderer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010

1111
package org.junit.jupiter.api;
1212

13+
import static java.util.Collections.shuffle;
14+
import static java.util.Comparator.comparing;
1315
import static java.util.Comparator.comparingInt;
1416
import static org.apiguardian.api.API.Status.EXPERIMENTAL;
1517
import static org.apiguardian.api.API.Status.STABLE;
1618

17-
import java.util.Collections;
1819
import java.util.Comparator;
1920

2021
import org.apiguardian.api.API;
@@ -148,7 +149,7 @@ public void orderClasses(ClassOrdererContext context) {
148149
context.getClassDescriptors().sort(comparator);
149150
}
150151

151-
private static final Comparator<ClassDescriptor> comparator = Comparator.comparing(
152+
private static final Comparator<ClassDescriptor> comparator = comparing(
152153
descriptor -> descriptor.getTestClass().getName());
153154
}
154155

@@ -171,8 +172,7 @@ public void orderClasses(ClassOrdererContext context) {
171172
context.getClassDescriptors().sort(comparator);
172173
}
173174

174-
private static final Comparator<ClassDescriptor> comparator = Comparator.comparing(
175-
ClassDescriptor::getDisplayName);
175+
private static final Comparator<ClassDescriptor> comparator = comparing(ClassDescriptor::getDisplayName);
176176
}
177177

178178
/**
@@ -265,7 +265,7 @@ public Random() {
265265
*/
266266
@Override
267267
public void orderClasses(ClassOrdererContext context) {
268-
Collections.shuffle(context.getClassDescriptors(),
268+
shuffle(context.getClassDescriptors(),
269269
new java.util.Random(RandomOrdererUtils.getSeed(context::getConfigurationParameter, logger)));
270270
}
271271
}

0 commit comments

Comments
 (0)