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

lint: emit json #21

Closed
dominikh opened this issue Jan 29, 2017 · 7 comments
Closed

lint: emit json #21

dominikh opened this issue Jan 29, 2017 · 7 comments
Assignees

Comments

@dominikh
Copy link
Owner

We should provide a flag to output results in JSON. Such output would allow other tools to more easily consume our output.

@dmitshur
Copy link
Sponsor Contributor

dmitshur commented Jan 29, 2017

When you say "other tools", do you mean tools that do not have a good way of parsing the file:line:col: text type of output?

@dominikh
Copy link
Owner Author

Well, tools like frontends shouldn't have to parse that format (which currently exists of 3 components: the location, the message, and the ID of the check). It'd be much cleaner if they could receive the information in a structured format.

@dominikh
Copy link
Owner Author

Preliminary design of the JSON output is a stream of JSON objects of the following kind:

{
  "checker": "staticcheck",
  "code": "SA1000",
  "severity": "warning",
  "location": {
    "file": "/some/absolute/path.go",
    "line": 123,
    "column": 123,
  },
  "message": "Your code is full of bugs"
}

Where severity is optional, and not fully defined yet, but will be used to differentiate compiler errors, suggestions (gosimple), warnings (most of staticcheck), high impact bugs and so on. We can standardize on a list later.

column is a byte offset, just like it's in the existing text output.

@bradleyfalzon as the author of gopherci, do you have any feedback on the format? any fields that are missing?

@dominikh
Copy link
Owner Author

dominikh commented Sep 21, 2017

Real-world example (without the severity field):

$ megacheck strings
{"checker":"staticcheck","code":"SA4017","location":{"file":"/usr/lib/go/src/strings/strings_test.go","line":954,"column":8},"message":"Repeat is a pure function but its return value is ignored"}
{"checker":"gosimple","code":"S1021","location":{"file":"/usr/lib/go/src/strings/replace_test.go","line":54,"column":2},"message":"should merge variable declaration with assignment on next line"}

@bradleyfalzon
Copy link
Contributor

Looks good to me, not sure if others would prefer to handle a single json document instead of a stream.

What about errors, or is it just assumed that if you weren’t able to decode a plain text error is presented itself?

@dominikh
Copy link
Owner Author

not sure if others would prefer to handle a single json document instead of a stream.

It's much easier to be given a stream and treat it as a single document (read until EOF before processing) than it is to do streaming with a document.

What about errors, or is it just assumed that if you weren’t able to decode a plain text error is presented itself?

For now, if the input is malformed, we'll continue emitting errors on stderr. In the future, these may become part of the JSON.

@dominikh dominikh self-assigned this Oct 25, 2017
@dominikh dominikh added the started Issues we've started working on label Oct 25, 2017
@dominikh
Copy link
Owner Author

Implemented in 479b882

@dominikh dominikh removed the started Issues we've started working on label Oct 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants