Skip to content

Commit

Permalink
Introduce MonoFluxThen and MonoVoidThen Refaster rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Paco van Beckhoven committed Dec 9, 2022
1 parent 0153c14 commit d4145a5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,34 @@ Flux<T> after(Mono<T> mono) {
}
}

/** Don't unnecessarily convert {@link Mono} to {@link Flux}. */
@SuppressWarnings("VoidMissingNullable")
static final class MonoFluxThen<T> {
@BeforeTemplate
Mono<Void> before(Mono<T> mono) {
return mono.flux().then();
}

@AfterTemplate
Mono<Void> after(Mono<T> mono) {
return mono.then();
}
}

/** Don't unnecessarily call {@link Mono#then()} on a {@code Mono<Void>} . */
@SuppressWarnings("VoidMissingNullable")
static final class MonoVoidThen {
@BeforeTemplate
Mono<Void> before(Mono<Void> mono) {
return mono.then();
}

@AfterTemplate
Mono<Void> after(Mono<Void> mono) {
return mono;
}
}

/**
* Prefer a collection using {@link MoreCollectors#toOptional()} over more contrived alternatives.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ ImmutableSet<Flux<String>> testMonoFlux() {
Flux.concat(Mono.just("baz")));
}

Mono<Void> testMonoFluxThen() {
return Mono.just("foo").flux().then();
}

Mono<Void> testMonoVoidThen() {
return Mono.just("foo").then().then();
}

Mono<Optional<String>> testMonoCollectToOptional() {
return Mono.just("foo").map(Optional::of).defaultIfEmpty(Optional.empty());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,14 @@ ImmutableSet<Flux<String>> testMonoFlux() {
Mono.just("foo").flux(), Mono.just("bar").flux(), Mono.just("baz").flux());
}

Mono<Void> testMonoFluxThen() {
return Mono.just("foo").then();
}

Mono<Void> testMonoVoidThen() {
return Mono.just("foo").then();
}

Mono<Optional<String>> testMonoCollectToOptional() {
return Mono.just("foo").flux().collect(toOptional());
}
Expand Down

0 comments on commit d4145a5

Please sign in to comment.