Skip to content

Instantly share code, notes, and snippets.

@beer-psi
Last active August 1, 2022 07:37
Show Gist options
  • Save beer-psi/75591e695dab9cae863eb768b59f5513 to your computer and use it in GitHub Desktop.
Save beer-psi/75591e695dab9cae863eb768b59f5513 to your computer and use it in GitHub Desktop.
jq filter for generating github actions annotations from cargo check/cargo clippy
# SPDX-License-Identifier: 0BSD
# Usage: cargo clippy --message-format=json | jq --arg WORKING_DIRECTORY "$WORKDIR" -rsf annotations.jq
def annotation_level(x):
if x == "help" or x == "note" then
"notice"
elif x == "warning" then
"warning"
else
"error"
end;
def sanitize(x):
x
| gsub("%"; "%25")
| gsub("\n"; "%0A")
| gsub("\r"; "%0D");
.[]
| select(.reason == "compiler-message" and .message.code and .message.spans[].is_primary)
| .message
| (.spans[] | select(.is_primary)) as $span
| "::\(annotation_level(.level)) file=\($WORKING_DIRECTORY)/\($span.file_name),line=\($span.line_start),endLine=\($span.line_end),col=\($span.column_start),endColumn=\($span.column_end),title=\(.message)::"
+ sanitize(.rendered)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment