dialyxir icon indicating copy to clipboard operation
dialyxir copied to clipboard

Output diagnostics in JSON format

Open azizk opened this issue 3 years ago • 3 comments

Hi!

I was wondering whether a --format jsonoption is something that would make sense. I think it wouldn't be just a nice-to-have feature. I'm thinking about being able to process that output further and extracting info from it or converting it to another format. For example, converting dialyxir's output to the JUnit XML test-suites report format would enable us to view the diagnostics on the dashboard of our automation systems. Otherwise you only get some flat text output which can be hard to digest.

In addition to this it would be even more awesome if dialyxir added additional info like the list of modules that have been checked and the time each one took. It would also be great to mention the module name besides its file name in the warning, because there can be several modules in the same file. All of this info can be translated to the JUnit format in a meaningful way.

azizk avatar May 18 '21 22:05 azizk

I think it might be better to work with the native terms returned by the Erlang library. Those can't be naively encoded to JSON (e.g. Jason.encode will fail since there is no JSON encoding for basic tuple type) but are reasonably well structured and are what we use to format warnings to text. You might be able to just pipe the results of dialyxir --format raw into Code.eval_string to recover those, but we could also look to add a feature to make it easier to call Dialyxir as a library; that way it still uses your config, PLT etc but can be invoked from your own script or mix task to transform the terms the way you'd like.

jeremyjh avatar May 19 '21 12:05 jeremyjh

Ah, I wasn't thinking about going as far as converting the Erlang data structures to JSON. I agree there wouldn't be a clear and easy way to do that. I was thinking more along the lines of having a rather basic JSON object structure. Let's say we have this error:

lib/my_app/html.ex:123:no_return
Function unescape_entities/1 has no local return.

The corresponding JSON would look something like this:

{
  "warnings": [
    {
      "code": "no_return",
      "file": "lib/my_app/html.ex",
      "line": 123,
      "module": "MyApp.HTML",
      "message": "Function unescape_entities/1 has no local return."
    }
  ],
  "successful": [
    {
      "file": "lib/my_app/my_app.ex",
      "line": 1,
      "module": "MyApp",
      "time": 1.23
    }
  ]
}

This is the format I had in mind.

Thanks for the tip about --format raw and Code.eval_string. Maybe I can do something with that in the meantime.

azizk avatar May 19 '21 18:05 azizk

Hey @jeremyjh, I checked the raw format but it isn't really the solution. Do you have any pointers for how one would go about implementing this? Maybe I can try my hand or someone else who's interested. Would you even like to see a feature like this?

PS.: As an alternative to calling it --format json we could have --format json_report or even --report json.

azizk avatar Jun 13 '21 16:06 azizk

Closing due to staleness.

azizk avatar Aug 27 '22 19:08 azizk