Skip to content

Commit

Permalink
Disallow static import of {Mono,Flux} and partially allow empty
Browse files Browse the repository at this point in the history
  • Loading branch information
rickie committed Feb 9, 2024
1 parent 0a35376 commit de3fdcd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.time.ZoneOffset;
import java.util.Collections;
import java.util.Locale;
import java.util.Optional;
import java.util.regex.Pattern;
import org.jspecify.annotations.Nullable;
import tech.picnic.errorprone.bugpatterns.util.SourceCode;
Expand Down Expand Up @@ -71,7 +72,9 @@ public final class NonStaticImport extends BugChecker implements CompilationUnit
Strings.class.getCanonicalName(),
VisitorState.class.getCanonicalName(),
ZoneOffset.class.getCanonicalName(),
"com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode");
"com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode",
"reactor.core.publisher.Flux",
"reactor.core.publisher.Mono");

/**
* Type members that should never be statically imported.
Expand Down Expand Up @@ -103,6 +106,7 @@ public final class NonStaticImport extends BugChecker implements CompilationUnit
"sort",
"swap")
.put(Locale.class.getCanonicalName(), "ROOT")
.put(Optional.class.getCanonicalName(), "empty")
.putAll(Pattern.class.getCanonicalName(), "compile", "matches", "quote")
.put(Predicates.class.getCanonicalName(), "contains")
.put("org.springframework.http.MediaType", "ALL")
Expand All @@ -125,7 +129,6 @@ public final class NonStaticImport extends BugChecker implements CompilationUnit
"builder",
"copyOf",
"create",
"empty",
"from",
"getDefaultInstance",
"INSTANCE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ void identification() {
"// BUG: Diagnostic contains:",
"import static java.util.Optional.empty;",
"import static pkg.A.WithMethodThatIsSelectivelyFlagged.list;",
"// BUG: Diagnostic contains:",
"import static reactor.core.publisher.Flux.just;",
"",
"import com.google.common.collect.ImmutableList;",
"import com.google.common.collect.ImmutableSet;",
Expand All @@ -90,6 +92,7 @@ void identification() {
" Locale english = ENGLISH;",
" Locale root = ROOT;",
" empty();",
" just();",
"",
" list();",
" new INSTANCE();",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void identification() {
"import com.google.common.collect.ImmutableSet;",
"import com.google.errorprone.refaster.ImportPolicy;",
"import com.google.errorprone.refaster.annotation.UseImportPolicy;",
"import com.mongodb.client.model.Filters;",
"import java.nio.charset.StandardCharsets;",
"import java.time.ZoneOffset;",
"import java.util.Optional;",
Expand Down Expand Up @@ -99,6 +100,8 @@ void identification() {
" // BUG: Diagnostic contains:",
" MediaType t2 = MediaType.APPLICATION_JSON;",
"",
" // BUG: Diagnostic contains:",
" Filters.empty();",
" Optional.empty();",
"",
" // BUG: Diagnostic contains:",
Expand Down

0 comments on commit de3fdcd

Please sign in to comment.