diff --git a/pkg/golinters/whitespace.go b/pkg/golinters/whitespace.go index 02a032c381c0..46d6eef1a2c2 100644 --- a/pkg/golinters/whitespace.go +++ b/pkg/golinters/whitespace.go @@ -58,14 +58,13 @@ func NewWhitespace(settings *config.WhitespaceSettings) *goanalysis.Linter { } case whitespace.MessageTypeAdd: - position := pass.Fset.PositionFor(issue.Diagnostic, false) - bracketLine, err := lintCtx.LineCache.GetLine(position.Filename, position.Line) - if err != nil { - return nil, fmt.Errorf("failed to get line %s:%d: %w", position.Filename, position.Line, err) - } - + report.Pos = pass.Fset.PositionFor(issue.FixStart, false) report.Replacement = &result.Replacement{ - NewLines: []string{bracketLine + "\n"}, + Inline: &result.InlineFix{ + StartCol: 0, + Length: 1, + NewString: "\n\t", + }, } default: diff --git a/test/testdata/fix/in/whitespace.go b/test/testdata/fix/in/whitespace.go index 703c1b8a6d01..14eff29081c4 100644 --- a/test/testdata/fix/in/whitespace.go +++ b/test/testdata/fix/in/whitespace.go @@ -59,4 +59,15 @@ func multiIfFunc() { 2 == 2 { fmt.Println("Hello multi-line world") } + + if true { + if true { + if true { + if 1 == 1 && + 2 == 2 { + fmt.Println("Hello nested multi-line world") + } + } + } + } } diff --git a/test/testdata/fix/out/whitespace.go b/test/testdata/fix/out/whitespace.go index a9dcb901b111..0592878bf721 100644 --- a/test/testdata/fix/out/whitespace.go +++ b/test/testdata/fix/out/whitespace.go @@ -57,4 +57,16 @@ func multiIfFunc() { fmt.Println("Hello multi-line world") } + + if true { + if true { + if true { + if 1 == 1 && + 2 == 2 { + + fmt.Println("Hello nested multi-line world") + } + } + } + } }