Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore disabled checks passed to -XepPatchChecks #4310

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,12 @@ static ErrorProneAnalyzer createAnalyzer(
.customRefactorer()
.or(
() -> {
ScannerSupplier toUse =
ErrorPronePlugins.loadPlugins(scannerSupplier, context)
.applyOverrides(epOptions);
ScannerSupplier toUse = ErrorPronePlugins.loadPlugins(scannerSupplier, context);
ImmutableSet<String> namedCheckers = epOptions.patchingOptions().namedCheckers();
if (!namedCheckers.isEmpty()) {
toUse = toUse.filter(bci -> namedCheckers.contains(bci.canonicalName()));
} else {
toUse = toUse.applyOverrides(epOptions);
}
return ErrorProneScannerTransformer.create(toUse.get());
})
Expand Down
29 changes: 29 additions & 0 deletions core/src/test/java/com/google/errorprone/scanner/ScannerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,35 @@ public void suppressionAnnotationIgnoredWithOptions() {
.doTest();
}

@Test
public void dontRunPatchForDisabledChecks() {
compilationHelper
.addSourceLines(
"Test.java",
"import com.google.errorprone.scanner.ScannerTest.Foo;",
"class Test {",
" Foo foo;",
"}")
.setArgs("-XepPatchLocation:IN_PLACE", "-XepPatchChecks:", "-Xep:ShouldNotUseFoo:OFF")
.doTest();
}

@Test
public void dontRunPatchUnlessRequested() {
compilationHelper
.addSourceLines(
"Test.java",
"import com.google.errorprone.scanner.ScannerTest.Foo;",
"class Test {",
" Foo foo;",
"}")
.setArgs(
"-XepPatchLocation:IN_PLACE",
"-Xep:ShouldNotUseFoo:WARN",
"-XepPatchChecks:DeadException")
.doTest();
}

@OkToUseFoo // Foo can use itself. But this shouldn't suppress errors on *usages* of Foo.
public static final class Foo<T> {}

Expand Down
Loading