Last active
October 9, 2016 17:26
-
-
Save ento/a4e2a251f54fe531ede9a8cd1960c7d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ "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"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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'.elm"> | |
<error line="1" column="1" severity="error" message="<file would change>" 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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