@@ -2,10 +2,12 @@ package golinters
2
2
3
3
import (
4
4
"context"
5
+ "errors"
5
6
"fmt"
6
7
"strings"
7
8
8
9
megacheckAPI "github.com/golangci/go-tools/cmd/megacheck"
10
+ "github.com/golangci/golangci-lint/pkg/fsutils"
9
11
"github.com/golangci/golangci-lint/pkg/lint/linter"
10
12
"github.com/golangci/golangci-lint/pkg/result"
11
13
)
@@ -50,14 +52,45 @@ func (m Megacheck) Desc() string {
50
52
return descs [m .Name ()]
51
53
}
52
54
55
+ func prettifyCompilationError (err error ) error {
56
+ i := TypeCheck {}.parseError (err )
57
+ if i == nil {
58
+ return err
59
+ }
60
+
61
+ shortFilename , pathErr := fsutils .ShortestRelPath (i .Pos .Filename , "" )
62
+ if pathErr != nil {
63
+ return err
64
+ }
65
+
66
+ errText := shortFilename
67
+ if i .Line () != 0 {
68
+ errText += fmt .Sprintf (":%d" , i .Line ())
69
+ }
70
+ errText += fmt .Sprintf (": %s" , i .Text )
71
+ return errors .New (errText )
72
+ }
73
+
53
74
func (m Megacheck ) Run (ctx context.Context , lintCtx * linter.Context ) ([]result.Issue , error ) {
54
75
if len (lintCtx .NotCompilingPackages ) != 0 {
55
76
var packages []string
77
+ var errors []error
56
78
for _ , p := range lintCtx .NotCompilingPackages {
57
79
packages = append (packages , p .String ())
80
+ errors = append (errors , p .Errors ... )
58
81
}
59
- lintCtx .Log .Warnf ("Can't run megacheck because of compilation errors in packages " +
60
- "%s: run `typecheck` linter to see errors" , packages )
82
+
83
+ warnText := fmt .Sprintf ("Can't run megacheck because of compilation errors in packages %s" ,
84
+ packages )
85
+ if len (errors ) != 0 {
86
+ warnText += fmt .Sprintf (": %s" , prettifyCompilationError (errors [0 ]))
87
+ if len (errors ) > 1 {
88
+ const runCmd = "golangci-lint run --no-config --disable-all -E typecheck"
89
+ warnText += fmt .Sprintf (" and %d more errors: run `%s` to see all errors" , len (errors )- 1 , runCmd )
90
+ }
91
+ }
92
+ lintCtx .Log .Warnf ("%s" , warnText )
93
+
61
94
// megacheck crashes if there are not compiling packages
62
95
return nil , nil
63
96
}
0 commit comments