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

Json output #68

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

alexkiousis
Copy link

This introduces a JSON format output.

Each message is a JSON dictionary. Example output:

yamllint -f json yamllint/conf/*
{"code": "YAMLLINT", "char": 1, "severity": "error", "line": 1, "path": "yamllint/conf/default.yaml", "name": "YAMLLINT", "description": "too many blank lines (1 > 0) (empty-lines)"}
{"code": "YAMLLINT", "char": 1, "severity": "warning", "line": 2, "path": "yamllint/conf/default.yaml", "name": "YAMLLINT", "description": "missing document start \"---\" (document-start)"}
{"code": "YAMLLINT", "char": 1, "severity": "warning", "line": 1, "path": "yamllint/conf/relaxed.yaml", "name": "YAMLLINT", "description": "missing document start \"---\" (document-start)"}

The output is based on Phabricator's API for linting input. I use it with this Jenkins plugin.

@coveralls
Copy link

coveralls commented Sep 1, 2017

Coverage Status

Coverage decreased (-0.2%) to 97.805% when pulling b0412b5 on alexkiousis:json_output into db57127 on adrienverge:master.

@alexkiousis
Copy link
Author

This is basically my first PR, so any feedback is welcome.
I'm trying to figure out what test is needed to "cover" the new function introduced.

Copy link
Owner

@adrienverge adrienverge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

Looks good!

Indeed you need to add tests to make sure future development won't break your feature. Can you add a function at the end of tests/test_cli.py, for instance test_run_json_output()? Something that checks that when passing -f json, the output is parsable using json.loads() and matches a pre-defined dictionnary.

@@ -49,6 +50,18 @@ def parsable(problem, filename):
'message': problem.message})

@staticmethod
def json_output(problem, filename):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other formats don't have _output, you can simply name this function json(problem, filename) ;-)

"char": problem.column,
"description": problem.message,
"code": "YAMLLINT",
"name": "YAMLLINT",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of the tool is yamllint (lowercase), can you keep it?

@xelatirdan
Copy link

@alexkiousis Hello, are you going to bring your pull request to finish?

@strowi strowi mentioned this pull request Mar 31, 2020
@MrBones757
Copy link

is there any progress on this issue? I've come across a situation where this would be very useful to have if its possible to move this forward..

@adrienverge
Copy link
Owner

adrienverge commented Jan 15, 2021

@MrBones757 as you can see, this PR seems abandoned. Yes it's "possible to move this forward": do you want to contribute and write a new, clean pull request?

It needs to come with tests (see previous comments), and the output format would be better like that:

{
  "path": ...,
  "line": ...,
  "column": ...,
  "message": ...,
  "rule": ...,
  "level": "warning|error"
}

@bluikko
Copy link

bluikko commented Jun 11, 2021

Please consider using the Codeclimate JSON syntax. Why come up with a proprietary JSON schema when a de facto standard exists? It would also be supported in GitLab.

Edit: I saw there was an issue closed with regards to my suggested specific JSON schema. Why when there is an output format "github"? If the JSON output would be codeclimate style then it could be used out of the box with the GitLab cloud which is no different from GitHub. Call it "gitlab" if it makes you feel better...

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.

None yet

6 participants