Skip to content

Commit

Permalink
Merge pull request #429 from amperser/off-by-one-json
Browse files Browse the repository at this point in the history
Fix off-by-one error in JSON output
  • Loading branch information
suchow committed Mar 31, 2016
2 parents c2a39e0 + 4d3fe2c commit 334749d
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions proselint/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,27 +113,29 @@ def clear_cache():
shell=True)


def errors_to_json(errors):
"""Convert the errors to JSON."""
out = []
for e in errors:
out.append({
"check": e[0],
"message": e[1],
"line": 1 + e[2],
"column": 1 + e[3],
"start": 1 + e[4],
"end": 1 + e[5],
"extent": e[6],
"severity": e[7],
"replacements": e[8],
})

return json.dumps(dict(status="success", data={"errors": out}))


def show_errors(filename, errors, output_json=False, compact=False):
"""Print the errors, resulting from lint, for filename."""
if output_json:
out = []
for e in errors:
out.append({
"check": e[0],
"message": e[1],
"line": e[2],
"column": e[3],
"start": e[4],
"end": e[5],
"extent": e[6],
"severity": e[7],
"replacements": e[8],
})
result = dict(
status="success",
data={"errors": out})

click.echo(json.dumps(result))
click.echo(errors_to_json(errors))

else:
for error in errors:
Expand Down

0 comments on commit 334749d

Please sign in to comment.