Skip to content

Commit be6d83b

Browse files
committed
WIP: packages.Load, go list, and typcheck
1 parent cd2aa83 commit be6d83b

File tree

7 files changed

+22
-4
lines changed

7 files changed

+22
-4
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ require (
107107
github.com/yagipy/maintidx v1.0.0
108108
github.com/yeya24/promlinter v0.2.0
109109
gitlab.com/bosi/decorder v0.2.3
110-
golang.org/x/tools v0.4.1-0.20221208213631-3f74d914ae6d
110+
golang.org/x/tools v0.4.1-0.20221209215444-3da7f1e4c248
111111
gopkg.in/yaml.v3 v3.0.1
112112
honnef.co/go/tools v0.4.0-0.dev.0.20221209223220-58c4d7e4b720
113113
mvdan.cc/gofumpt v0.4.0

go.sum

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/golinters/goanalysis/runner_loadingpackage.go

+1
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ func (lp *loadingPackage) convertError(err error) []packages.Error {
434434
// If you see this error message, please file a bug.
435435
lp.log.Warnf("Internal error: error %q (%T) without position", err, err)
436436
}
437+
437438
return errs
438439
}
439440

pkg/golinters/gofmt_common.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ func extractIssuesFromPatch(patch string, lintCtx *linter.Context, linterName st
242242
}
243243

244244
if len(diffs) == 0 {
245-
return nil, fmt.Errorf("got no diffs from patch parser: %v", diffs)
245+
return nil, fmt.Errorf("got no diffs from patch parser: %v", patch)
246246
}
247247

248248
var issues []result.Issue

pkg/lint/load.go

+11
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,16 @@ func (cl *ContextLoader) debugPrintLoadedPackages(pkgs []*packages.Package) {
160160

161161
func (cl *ContextLoader) parseLoadedPackagesErrors(pkgs []*packages.Package) error {
162162
for _, pkg := range pkgs {
163+
var errs []packages.Error
163164
for _, err := range pkg.Errors {
165+
// quick fix: skip error related to `go list` invocation by packages.Load()
166+
// The behavior has been changed between go1.19 and go1.20, the error is now inside the JSON content.
167+
if strings.Contains(err.Msg, "# command-line-arguments") {
168+
continue
169+
}
170+
171+
errs = append(errs, err)
172+
164173
if strings.Contains(err.Msg, "no Go files") {
165174
return errors.Wrapf(exitcodes.ErrNoGoFiles, "package %s", pkg.PkgPath)
166175
}
@@ -169,6 +178,8 @@ func (cl *ContextLoader) parseLoadedPackagesErrors(pkgs []*packages.Package) err
169178
return errors.Wrap(exitcodes.ErrFailure, err.Msg)
170179
}
171180
}
181+
182+
pkg.Errors = errs
172183
}
173184

174185
return nil

pkg/lint/runner.go

+1
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ func (r Runner) Run(ctx context.Context, linters []*linter.Config, lintCtx *lint
208208

209209
return
210210
}
211+
211212
issues = append(issues, linterIssues...)
212213
})
213214
}

test/linters_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package test
22

33
import (
4+
"fmt"
45
"os"
56
"os/exec"
67
"path/filepath"
@@ -21,6 +22,10 @@ func TestSourcesFromTestdata(t *testing.T) {
2122
testSourcesFromDir(t, testdataDir)
2223
}
2324

25+
func TestName(t *testing.T) {
26+
fmt.Println(filepath.Clean("./typecheck.go"))
27+
}
28+
2429
func TestTypecheck(t *testing.T) {
2530
testshared.SkipOnWindows(t)
2631

0 commit comments

Comments
 (0)