Skip to content

Commit

Permalink
FormattingRule: Use the offset as calculated by KtLint
Browse files Browse the repository at this point in the history
This is the offset expected by the calculateLineColByOffset() function
copied from KtLint.

Fixes detekt#1843.
  • Loading branch information
sschuberth committed Apr 14, 2020
1 parent c98230f commit e3ff322
Showing 1 changed file with 4 additions and 4 deletions.
Expand Up @@ -58,16 +58,16 @@ abstract class FormattingRule(config: Config) : Rule(config) {
if (ruleShouldOnlyRunOnFileNode(node)) {
return
}
wrapping.visit(node, autoCorrect) { _, message, _ ->
val (line, column) = positionByOffset(node.startOffset)
wrapping.visit(node, autoCorrect) { offset, message, _ ->
val (line, column) = positionByOffset(offset)
val location = Location(
SourceLocation(line, column),
TextLocation(node.startOffset, node.psi.endOffset),
"($line, $column)",
root.originalFilePath() ?: root.containingFile.name
)
// The formatting rules report slightly wrong positions - #1843.
// Also nodes reported by 'NoConsecutiveBlankLines' are dangling whitespace nodes which means they have

// Nodes reported by 'NoConsecutiveBlankLines' are dangling whitespace nodes which means they have
// no direct parent which we can use to get the containing file needed to baseline or suppress findings.
// For these reasons we do not report a KtElement which may lead to crashes when postprocessing it
// e.g. reports (html), baseline etc.
Expand Down

0 comments on commit e3ff322

Please sign in to comment.