Skip to content

Commit

Permalink
Set offset of max-line-length violation to the last position at whi…
Browse files Browse the repository at this point in the history
…ch a newline can be inserted to fix the violation (#2419)
  • Loading branch information
paul-dingemans committed Dec 11, 2023
1 parent d8955a6 commit 8b51fb9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ public class MaxLineLengthRule :
?.takeUnless { it.isPartOfRawMultiLineString() }
?.takeUnless { it.isLineOnlyContainingComment() }
?.let { lastNodeOnLine ->
// Calculate the offset at the last possible position at which the newline should be inserted on the line
val offset = node.leavesOnLine().first().startOffset + maxLineLength + 1
emit(
lastNodeOnLine.startOffset + lastNodeOnLine.textLength - 1,
offset,
"Exceeded max line length ($maxLineLength)",
false,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MaxLineLengthRuleTest {
.setMaxLineLength()
.hasLintViolationsWithoutAutoCorrect(
LintViolation(2, 47, "Exceeded max line length (46)"),
LintViolation(3, 61, "Exceeded max line length (46)"),
LintViolation(3, 47, "Exceeded max line length (46)"),
LintViolation(5, 47, "Exceeded max line length (46)"),
)
}
Expand Down Expand Up @@ -159,7 +159,7 @@ class MaxLineLengthRuleTest {
.withEditorConfigOverride(IGNORE_BACKTICKED_IDENTIFIER_PROPERTY to true)
.hasLintViolationsWithoutAutoCorrect(
// Note that no error was generated on line 2 with the long fun name but on another line
LintViolation(3, 91, "Exceeded max line length (37)"),
LintViolation(3, 38, "Exceeded max line length (37)"),
LintViolation(4, 38, "Exceeded max line length (37)"),
)
}
Expand Down

0 comments on commit 8b51fb9

Please sign in to comment.