dominikh / go-tools

Staticcheck - The advanced Go linter
https://staticcheck.dev
MIT License
6.01k stars 361 forks source link

lintcmd: print TOML error on invalid config #1547

Closed arp242 closed 2 weeks ago

arp242 commented 1 month ago

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: https://github.com/BurntSushi/toml/pull/411

Also print a more verbose errors, which is nicer IMHO:

% staticcheck
staticcheck.conf:5:60: toml: error: expected a comma (',') or array terminator (']'), but got '"'

At line 5, column 60:

      3 |
      4 | checks = ["all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022", "-ST1023"]
      5 | dot_import_whitelist = ["github.com/mmcloughlin/avo/build" "github.com/mmcloughlin/avo/operand", "github.com/mmcloughlin/avo/reg"]
                                                                     ^
 (config)

% staticcheck -f stylish
/home/martin/src/go-tools/staticcheck.conf
  (5, 60)  config  toml: error: expected a comma (',') or array terminator (']'), but got '"'

At line 5, column 60:

      3 |
      4 | checks = ["all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022", "-ST1023"]
      5 | dot_import_whitelist = ["github.com/mmcloughlin/avo/build" "github.com/mmcloughlin/avo/operand", "github.com/mmcloughlin/avo/reg"]
                                                                     ^

 ✖ 1 problems (0 errors, 1 warnings, 0 ignored)

% staticcheck -f json | jfmt
{
    "code":     "config",
    "end":      {"column": 0, "file": "", "line": 0},
    "location": {"column": 60, "file": "/home/martin/src/go-tools/staticcheck.conf", "line": 5},
    "message":  "toml: error: expected a comma (',') or array terminator (']'), but got '\"'\n\nAt line 5, column 60:\n\n      3 | \n      4 | checks = [\"all\", \"-ST1000\", \"-ST1003\", \"-ST1016\", \"-ST1020\", \"-ST1021\", \"-ST1022\", \"-ST1023\"]\n      5 | dot_import_whitelist = [\"github.com/mmcloughlin/avo/build\" \"github.com/mmcloughlin/avo/operand\", \"github.com/mmcloughlin/avo/reg\"]\n
                              ^\n",
    "severity": "warning"
}
dominikh commented 1 month ago

I'll have to veto the more verbose message. It doesn't fit the style of messages that Staticcheck and go usually print.

arp242 commented 1 month ago

No worries, I changed that back.