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

Set offset of max-line-length violation to the last position at which a newline can be inserted to fix the violation #2419

Merged
merged 1 commit into from
Dec 11, 2023
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 @@ -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