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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions yamllint/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import sys

import argparse
import json

from yamllint import APP_DESCRIPTION, APP_NAME, APP_VERSION
from yamllint.config import YamlLintConfig, YamlLintConfigError
Expand Down Expand Up @@ -48,6 +49,18 @@ def parsable(problem, filename):
'level': problem.level,
'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) ;-)

return json.dumps({
"path": filename,
"line": problem.line,
"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?

"severity": problem.level,
})

@staticmethod
def standard(problem, filename):
line = ' %d:%d' % (problem.line, problem.column)
Expand Down Expand Up @@ -87,8 +100,8 @@ def run(argv=None):
action='store',
help='custom configuration (as YAML source)')
parser.add_argument('-f', '--format',
choices=('parsable', 'standard'), default='standard',
help='format for parsing output')
choices=('parsable', 'standard', 'json'),
default='standard', help='format for parsing output')
parser.add_argument('-s', '--strict',
action='store_true',
help='return non-zero exit code on warnings '
Expand Down Expand Up @@ -134,6 +147,8 @@ def run(argv=None):
for problem in linter.run(f, conf, filepath):
if args.format == 'parsable':
print(Format.parsable(problem, file))
elif args.format == 'json':
print(Format.json_output(problem, file))
elif sys.stdout.isatty():
if first:
print('\033[4m%s\033[0m' % file)
Expand Down