Skip to content

Commit

Permalink
Don't quibble over trailing newlines.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 684860035
  • Loading branch information
graememorgan authored and Error Prone Team committed Oct 11, 2024
1 parent 78729ff commit 2bebaf2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState
} catch (FormatterException exception) {
return NO_MATCH;
}
if (formattedSource.equals(sourceValue)) {
if (formattedSource.trim().equals(((String) sourceValue).trim())) {
return NO_MATCH;
}
// This is a bit crude: but tokenize between the comma and the 2nd argument in order to work out
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,34 @@ void method() {
.doTest();
}

@Test
public void onlyDiffersByFinalNewline_noFinding() {
assume().that(Runtime.version().feature()).isAtLeast(14);

compilationHelper
.addSourceLines(
"Test.java",
"""
import com.google.errorprone.BugCheckerRefactoringTestHelper;
class Test {
void method(BugCheckerRefactoringTestHelper h) {
h.addInputLines(
"Test.java",
\"""
package foo;
class Test {
void method() {
int a = 1;
}
}\""");
}
}
""")
.doTest();
}

@Test
public void misformatted_suggestsFix() {
assume().that(Runtime.version().feature()).isAtLeast(14);
Expand Down

0 comments on commit 2bebaf2

Please sign in to comment.