mirror of
https://github.com/jlengrand/error-prone-support.git
synced 2026-03-10 08:11:25 +00:00
WIP Try baseline-error-prone
This commit is contained in:
@@ -158,8 +158,10 @@ final class CollectionTemplates {
|
||||
}
|
||||
|
||||
/** Prefer {@link ArrayList#ArrayList(Collection)} over the Guava alternative. */
|
||||
// XXX: Drop this template if we adopt `baseline-error-prone`.
|
||||
static final class NewArrayListFromCollection<T> {
|
||||
@BeforeTemplate
|
||||
@SuppressWarnings("PreferCollectionConstructors")
|
||||
ArrayList<T> before(Collection<T> collection) {
|
||||
return Lists.newArrayList(collection);
|
||||
}
|
||||
|
||||
@@ -167,6 +167,7 @@ final class OptionalTemplates {
|
||||
*/
|
||||
abstract static class MapOptionalToBoolean<T> {
|
||||
@BeforeTemplate
|
||||
@SuppressWarnings("OptionalOrElseMethodInvocation")
|
||||
boolean before(Optional<T> optional, Function<? super T, Boolean> predicate) {
|
||||
return optional.map(predicate).orElse(Refaster.anyOf(false, Boolean.FALSE));
|
||||
}
|
||||
@@ -317,6 +318,7 @@ final class OptionalTemplates {
|
||||
/** Prefer {@link Optional#or(Supplier)} over more verbose alternatives. */
|
||||
abstract static class OptionalOrOtherOptional<T> {
|
||||
@BeforeTemplate
|
||||
@SuppressWarnings("OptionalOrElseGetValue")
|
||||
Optional<T> before(Optional<T> optional1, Optional<T> optional2) {
|
||||
// XXX: Note that rewriting the first and third variant will change the code's behavior if
|
||||
// `optional2` has side-effects.
|
||||
|
||||
@@ -24,19 +24,6 @@ import java.util.stream.Stream;
|
||||
final class StreamTemplates {
|
||||
private StreamTemplates() {}
|
||||
|
||||
/** Prefer {@link Stream#empty()} over less clear alternatives. */
|
||||
static final class EmptyStream<T> {
|
||||
@BeforeTemplate
|
||||
Stream<T> before() {
|
||||
return Stream.of();
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
Stream<T> after() {
|
||||
return Stream.empty();
|
||||
}
|
||||
}
|
||||
|
||||
/** Prefer {@link Stream#ofNullable(Object)} over more contrived alternatives. */
|
||||
static final class StreamOfNullable<T> {
|
||||
@BeforeTemplate
|
||||
|
||||
@@ -17,10 +17,6 @@ final class StreamTemplatesTest implements RefasterTemplateTestCase {
|
||||
return ImmutableSet.of(Objects.class, Streams.class, not(null), reverseOrder());
|
||||
}
|
||||
|
||||
Stream<String> testEmptyStream() {
|
||||
return Stream.of();
|
||||
}
|
||||
|
||||
ImmutableSet<Stream<String>> testStreamOfNullable() {
|
||||
return ImmutableSet.of(
|
||||
Stream.of("a").filter(Objects::nonNull), Optional.ofNullable("b").stream());
|
||||
|
||||
@@ -19,10 +19,6 @@ final class StreamTemplatesTest implements RefasterTemplateTestCase {
|
||||
return ImmutableSet.of(Objects.class, Streams.class, not(null), reverseOrder());
|
||||
}
|
||||
|
||||
Stream<String> testEmptyStream() {
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
ImmutableSet<Stream<String>> testStreamOfNullable() {
|
||||
return ImmutableSet.of(Stream.ofNullable("a"), Stream.ofNullable("b"));
|
||||
}
|
||||
|
||||
35
pom.xml
35
pom.xml
@@ -1392,12 +1392,12 @@
|
||||
<artifactId>assertj-error-prone</artifactId>
|
||||
<version>${version.palantir-assertj-automation}</version>
|
||||
</path>
|
||||
-->
|
||||
<path>
|
||||
<groupId>com.palantir.baseline</groupId>
|
||||
<artifactId>baseline-error-prone</artifactId>
|
||||
<version>${version.palantir-baseline}</version>
|
||||
</path>
|
||||
-->
|
||||
<path>
|
||||
<groupId>com.uber.nullaway</groupId>
|
||||
<artifactId>nullaway</artifactId>
|
||||
@@ -1437,6 +1437,39 @@
|
||||
-Xep:Java7ApiChecker:OFF
|
||||
<!-- We don't target Android. -->
|
||||
-Xep:StaticOrDefaultInterfaceMethod:OFF
|
||||
<!--
|
||||
Flags for `baseline-error-prone`.
|
||||
-->
|
||||
<!-- We prefer to name loggers name `LOG`,
|
||||
rather than `log`. -->
|
||||
-Xep:ConsistentLoggerName:OFF
|
||||
<!-- XXX: This check discourages use of
|
||||
parallel streams, which is good, but also
|
||||
suggests a Palantir alternative. Consider
|
||||
introducing a similar but less opinionated
|
||||
check. -->
|
||||
-Xep:DangerousParallelStreamUsage:OFF
|
||||
<!-- Nice idea, but too expensive due to
|
||||
(recursive) invocation of
|
||||
`SuggestedFixes.compilesWithFix`. -->
|
||||
-Xep:LambdaMethodReference:OFF
|
||||
<!-- We don't use Palantir's `safe-logging`
|
||||
library. -->
|
||||
-Xep:PreferSafeLoggingPreconditions:OFF
|
||||
<!-- We don't use Palantir's `safe-logging`
|
||||
library. -->
|
||||
-Xep:Slf4jLogsafeArgs:OFF
|
||||
<!-- XXX: This check suggests prefixing
|
||||
unused parameters with an underscore.
|
||||
Discuss this idea within the team. -->
|
||||
-Xep:StrictUnusedVariable:OFF
|
||||
<!-- Ideally `@VisibleForTesting` members
|
||||
are package-private, but there are
|
||||
reasonable exceptions. -->
|
||||
-Xep:VisibleForTestingPackagePrivate:OFF
|
||||
<!--
|
||||
Flags for `nullaway`.
|
||||
-->
|
||||
-XepOpt:NullAway:AnnotatedPackages=tech.picnic
|
||||
-XepOpt:NullAway:AssertsEnabled=true
|
||||
-XepOpt:NullAway:CheckOptionalEmptiness=true
|
||||
|
||||
Reference in New Issue
Block a user