vala-lang / vala-lint

Check code-style of Vala code files
GNU General Public License v2.0
96 stars 15 forks source link

Adds JSON output mode #170

Closed leggettc18 closed 1 year ago

leggettc18 commented 1 year ago

Resolves issue #169

Feedback on the exact format this outputs is welcome. As far as code style goes, this has a bit of duplication but outside of a fairly large overhaul to the string generation this feels like the cleanest way to accomplish this.

Sample with -p (added by this PR) and -e flags specified image

Keep in mind this is meant to be easier for regex/pattern matching to parse, and is not meant to be human readable.

leggettc18 commented 1 year ago

Might be changing this to a JSON output mode based on discussions happening in the linked issue.

leggettc18 commented 1 year ago

Changed it to be JSON instead. Sample Output of io.elementary.vala-lint -j -e src/Application.vala:

{"mistakes": [{"filename":"src/Application.vala","line":378,"column":38,"endLine":378,"endColumn":39,"level":"error","message":"Expected space before paren","ruleId":"space-before-paren"}]}

I based the keys off of the default strings null-ls' from_json method looks for, since that's the tool I'm currently using. Not sure if there's a more standard format this should be following, but I'd be happy to change any of those keys if desired. I also defaulted to minified JSON since this is meant for parsers and integrations rather than humans to read.

benwaffle commented 1 year ago

When running it on the vala-language-server codebase, I'm getting some invalid JSON. I think it's failing to escape quotes inside strings. I would recommend using json-glib-1.0: https://valadoc.org/json-glib-1.0/Json.html

leggettc18 commented 1 year ago

Ah, good catch, tried to not add any new dependencies but now it seems like the best option.

leggettc18 commented 1 year ago

OK, I used json-glib-1.0, ran it on the vala-language-server codebase, and ran the resulting output through https://jsonlint.com. It seems to have worked fine this time. For now I used Json.Builder to manually set key names and values, plus the structure is pretty flat. I could get fancy with implementing the Serializable interface and/or structuring the JSON differently if that would be desired, just let me know!

tintou commented 1 year ago

Thank you for this!