Skip to content

Instantly share code, notes, and snippets.

@ento
Last active October 9, 2016 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ento/a4e2a251f54fe531ede9a8cd1960c7d6 to your computer and use it in GitHub Desktop.
Save ento/a4e2a251f54fe531ede9a8cd1960c7d6 to your computer and use it in GitHub Desktop.
{ "path": "path/to/Main'.elm", "line": 1, "column": 1, "message": "<file would change>"}
{ "path": "path/to/Main'.elm", "line": 2, "column": 1, "message": "file would change"}
{ "path": "path/to/View.elm", "line": 1, "column": 1, "message": "file would change"}
# sample json contains XML special chars to check if they get correctly encoded
$ cat 00-sample.json | jq -n -r -f checkstyle.jq
<?xml version="1.0" encoding="utf-8"?>
<checkstyle version="5.7">
<file name="path/to/Main&apos;.elm">
<error line="1" column="1" severity="error" message="&lt;file would change&gt;" source="elm-format">
<error line="2" column="1" severity="error" message="file would change" source="elm-format">
</file>
<file name="path/to/View.elm">
<error line="1" column="1" severity="error" message="file would change" source="elm-format">
</file>
</checkstyle>
$ cat 00-sample.json | jq -r -f pep8.jq
path/to/Main'.elm:1:1: <file would change>
path/to/Main'.elm:2:1: file would change
path/to/View.elm:1:1: file would change
def preamble:
# This format is based on:
# https://github.com/checkstyle/checkstyle/blob/release5_7/src/checkstyle/com/puppycrawl/tools/checkstyle/XMLLogger.java
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<checkstyle version=\"5.7\">\n";
def postamble:
"\n</checkstyle>";
def map_join(f):
map(f) | join("\n");
def format_error:
@html "<error line=\"\(.line)\" column=\"\(.column)\" severity=\"error\" message=\"\(.message)\" source=\"elm-format\">";
def format_file:
@html "<file name=\"\(.key)\">\n" + (.value | map_join(format_error)) + "\n</file>";
reduce inputs as $error
({};
$error.path as $path
| has($path) as $newFile
| (if $newFile then .[$path] else [] end) as $prevErrors
| . + { ($path): ($prevErrors + [$error]) })
| preamble + (to_entries | map_join(format_file)) + postamble
# We might need an error code before the message:
# haven't tried against a real pep8 output parser
"\(.path):\(.line):\(.column): \(.message)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment