@@ -3,24 +3,24 @@ package golinters
3
3
import (
4
4
"bytes"
5
5
"fmt"
6
- "go/token"
7
6
"io/ioutil"
8
- "strings"
9
7
"sync"
10
8
9
+ "github.com/pkg/errors"
10
+ "github.com/shazow/go-diff/difflib"
11
11
"golang.org/x/tools/go/analysis"
12
12
"mvdan.cc/gofumpt/format"
13
13
14
14
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
15
15
"github.com/golangci/golangci-lint/pkg/lint/linter"
16
- "github.com/golangci/golangci-lint/pkg/result"
17
16
)
18
17
19
18
const gofumptName = "gofumpt"
20
19
21
20
func NewGofumpt () * goanalysis.Linter {
22
21
var mu sync.Mutex
23
22
var resIssues []goanalysis.Issue
23
+ differ := difflib .New ()
24
24
25
25
analyzer := & analysis.Analyzer {
26
26
Name : gofumptName ,
@@ -53,14 +53,20 @@ func NewGofumpt() *goanalysis.Linter {
53
53
return nil , fmt .Errorf ("error while running gofumpt: %w" , err )
54
54
}
55
55
if ! bytes .Equal (input , output ) {
56
- issues = append (issues , goanalysis .NewIssue (& result.Issue {
57
- FromLinter : gofumptName ,
58
- Text : "File is not `gofumpt`-ed" ,
59
- Pos : token.Position {
60
- Filename : f ,
61
- Line : strings .Count (string (input ), "\n " ),
62
- },
63
- }, pass ))
56
+ out := bytes.Buffer {}
57
+ out .WriteString (fmt .Sprintf ("--- %[1]s\n +++ %[1]s\n " , f ))
58
+
59
+ differ .Diff (& out , bytes .NewReader (input ), bytes .NewReader (output ))
60
+ diff := out .String ()
61
+
62
+ is , err := extractIssuesFromPatch (diff , lintCtx .Log , lintCtx , gofumptName )
63
+ if err != nil {
64
+ return nil , errors .Wrapf (err , "can't extract issues from gofumpt diff output %q" , string (diff ))
65
+ }
66
+
67
+ for i := range is {
68
+ issues = append (issues , goanalysis .NewIssue (& is [i ], pass ))
69
+ }
64
70
}
65
71
}
66
72
0 commit comments