Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lintcmd: print TOML error on invalid config #1547

Closed
wants to merge 1 commit into from

Conversation

arp242
Copy link
Contributor

@arp242 arp242 commented May 26, 2024

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

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
Copy link
Owner

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

@arp242
Copy link
Contributor Author

arp242 commented May 26, 2024

No worries, I changed that back.

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants