Skip to content

Commit 9ab7274

Browse files
committed
Use Inline instead of NewLine fix
1 parent dd67e40 commit 9ab7274

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

pkg/golinters/whitespace.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,13 @@ func NewWhitespace(settings *config.WhitespaceSettings) *goanalysis.Linter {
5858
}
5959

6060
case whitespace.MessageTypeAdd:
61-
position := pass.Fset.PositionFor(issue.Diagnostic, false)
62-
bracketLine, err := lintCtx.LineCache.GetLine(position.Filename, position.Line)
63-
if err != nil {
64-
return nil, fmt.Errorf("failed to get line %s:%d: %w", position.Filename, position.Line, err)
65-
}
66-
61+
report.Pos = pass.Fset.PositionFor(issue.FixStart, false)
6762
report.Replacement = &result.Replacement{
68-
NewLines: []string{bracketLine + "\n"},
63+
Inline: &result.InlineFix{
64+
StartCol: 0,
65+
Length: 1,
66+
NewString: "\n\t",
67+
},
6968
}
7069

7170
default:

test/testdata/fix/in/whitespace.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,15 @@ func multiIfFunc() {
5959
2 == 2 {
6060
fmt.Println("Hello multi-line world")
6161
}
62+
63+
if true {
64+
if true {
65+
if true {
66+
if 1 == 1 &&
67+
2 == 2 {
68+
fmt.Println("Hello nested multi-line world")
69+
}
70+
}
71+
}
72+
}
6273
}

test/testdata/fix/out/whitespace.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,16 @@ func multiIfFunc() {
5757

5858
fmt.Println("Hello multi-line world")
5959
}
60+
61+
if true {
62+
if true {
63+
if true {
64+
if 1 == 1 &&
65+
2 == 2 {
66+
67+
fmt.Println("Hello nested multi-line world")
68+
}
69+
}
70+
}
71+
}
6072
}

0 commit comments

Comments
 (0)