Skip to content

Commit

Permalink
Fix offset for violation when final newline is missing (pinterest#2407)
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-dingemans authored Dec 3, 2023
1 parent 85ed6bf commit 814a126
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class FinalNewlineRule :
val lastNode = lastChildNodeOf(node)
if (insertFinalNewline) {
if (lastNode !is PsiWhiteSpace || !lastNode.textContains('\n')) {
emit(0, "File must end with a newline (\\n)", true)
emit(node.textLength - 1, "File must end with a newline (\\n)", true)
if (autoCorrect) {
node.addChild(PsiWhiteSpaceImpl("\n"), null)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class FinalNewlineRuleTest {
""".trimIndent()
finalNewlineRuleAssertThat(code)
.withEditorConfigOverride(FINAL_NEW_LINE_REQUIRED)
.hasLintViolation(1, 1, "File must end with a newline (\\n)")
.hasLintViolation(2, 1, "File must end with a newline (\\n)")
.isFormattedAs(formattedCode)
}

Expand Down

0 comments on commit 814a126

Please sign in to comment.