diff --git a/proselint/command_line.py b/proselint/command_line.py index d417a2ed8..41b5bc615 100644 --- a/proselint/command_line.py +++ b/proselint/command_line.py @@ -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: