Skip to content

Commit

Permalink
Ensure multiple errors from the same method do not repeat in `@Suppre…
Browse files Browse the repository at this point in the history
…ssWarnings` (#24)

Ensure multiple errors from the same method do not repeat in `@SuppressWarnings` when suppressing
  • Loading branch information
CRogers authored Nov 14, 2024
1 parent ad12601 commit bae6982
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions changelog/@unreleased/pr-24.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: fix
fix:
description: Ensure multiple errors from the same method do not repeat in `@SuppressWarnings`
when suppressing
links:
- https://github.com/palantir/suppressible-error-prone/pull/24
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ private Description coalesceSuppressWarnings(VisitorState state, Tree tree, Modi
List<String> warningsToSuppress = suppressWarnings.stream()
.sorted(suppressWarningsBeforeRepeatableSuppressedWarnings())
.flatMap(SuppressWarningsCoalesce::annotationStringValues)
.distinct()
.collect(Collectors.toList());

if (warningsToSuppress.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,31 @@ void multiple_suppress_warnings_multiple_repeatable_warnings() {
.doTest();
}

@Test
void same_warnings_multiple_times() {
fix().addInput(
"Test.java",
String.join(
"\n",
"public class Test {",
" @com.palantir.suppressibleerrorprone.RepeatableSuppressWarnings(\"A\")",
" @com.palantir.suppressibleerrorprone.RepeatableSuppressWarnings(\"A\")",
" @com.palantir.suppressibleerrorprone.RepeatableSuppressWarnings(\"B\")",
" @com.palantir.suppressibleerrorprone.RepeatableSuppressWarnings(\"D\")",
" @SuppressWarnings({\"A\", \"B\", \"C\"})",
" void f() {}",
"}"))
.addOutput(
"Test.java",
String.join(
"\n",
"public class Test {",
" @SuppressWarnings({\"A\", \"B\", \"C\", \"D\"})",
" void f() {}",
"}"))
.doTest();
}

@Test
void field() {
fix().addInput(
Expand Down

0 comments on commit bae6982

Please sign in to comment.