Skip to content

Commit

Permalink
lintcmd: print TOML error on invalid config
Browse files Browse the repository at this point in the history
Previously the error message would get lost:

    % staticcheck
    staticcheck.conf:5:0:  (last key parsed: "dot_import_whitelist") (compile)

This is actually my bug; the ParseError.Message wasn't always set; fixed
with: BurntSushi/toml#411

Now it prints the expected:

    % staticcheck
    staticcheck.conf:2:32: expected a comma (',') or array terminator (']'), but got end of file (last key parsed: "checks") (config)

Closes: gh-1547 [via git-merge-pr]
  • Loading branch information
arp242 authored and dominikh committed Jun 16, 2024
1 parent dbad790 commit a8e4505
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module honnef.co/go/tools
go 1.22

require (
github.com/BurntSushi/toml v1.3.2
github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa
golang.org/x/exp/typeparams v0.0.0-20231108232855-2478ac86f678
golang.org/x/sys v0.20.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c h1:pxW6RcqyfI9/kWtOwnv/G+AzdKuy2ZrqINhenH4HyNs=
github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa h1:FRnLl4eNAQl8hwxVVC17teOw8kdjVDVAiFMtgUdTSRQ=
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa/go.mod h1:zk2irFbV9DP96SEBUUAy67IdHUaZuSnrz1n472HUCLE=
golang.org/x/exp/typeparams v0.0.0-20231108232855-2478ac86f678 h1:1P7xPZEwZMoBoz0Yze5Nx2/4pxj6nw9ZqHWXqP0iRgQ=
Expand Down
2 changes: 1 addition & 1 deletion go/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func convertError(err error) []packages.Error {

case config.ParseError:
errs = append(errs, packages.Error{
Pos: fmt.Sprintf("%s:%d", err.Filename, err.Position.Line),
Pos: fmt.Sprintf("%s:%d:%d", err.Filename, err.Position.Line, err.Position.Col),
Msg: fmt.Sprintf("%s (last key parsed: %q)", err.Message, err.LastKey),
Kind: packages.ParseError,
})
Expand Down
7 changes: 6 additions & 1 deletion lintcmd/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,11 @@ func failed(res runner.Result) []diagnostic {
msg = msg[1:]
}

cat := "compile"
if e.Kind == packages.ParseError {
cat = "config"
}

var posn token.Position
if e.Pos == "" {
// Under certain conditions (malformed package
Expand Down Expand Up @@ -456,7 +461,7 @@ func failed(res runner.Result) []diagnostic {
Diagnostic: runner.Diagnostic{
Position: posn,
Message: msg,
Category: "compile",
Category: cat,
},
Severity: severityError,
}
Expand Down

0 comments on commit a8e4505

Please sign in to comment.