Skip to content

Instantly share code, notes, and snippets.

@Profpatsch
Last active March 21, 2023 13:56
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Profpatsch/9af96a9773fe18825221eb55b4f4fbd5 to your computer and use it in GitHub Desktop.
Save Profpatsch/9af96a9773fe18825221eb55b4f4fbd5 to your computer and use it in GitHub Desktop.
Convert hlint warnings to github Action “smart” log messages
# the github message format requires newlines to be escaped with the URL-style %0A
# see https://github.com/actions/toolkit/issues/193#issuecomment-605394935
def escapeNewline: gsub("[\\n]"; "%0A");
# depending on the hlint message, we want to display the
# headings and the bodies differently
def prepareTitle:
if .hint == "Unused LANGUAGE pragma"
then { heading: "Unused LANGUAGE pragma: \(.from)"
, suggestion: ""
}
else if .hint == "Avoid restricted function"
then { heading: "Don’t use function: \(.from)"
, suggestion: "" }
else if .hint == "Avoid restricted qualification"
then { heading: "Change import to: \(.to)"
, suggestion: .to }
# if there is a `to` field, we can add it as suggestion
else if (.to != "") and (.to != null)
then { heading: .hint
, suggestion: .to }
else { heading: .hint
, suggestion: ""
}
end end end end;
def formatTitle:
. as $dot
| prepareTitle
| "\(.heading)::"
+ if .suggestion != "" then .suggestion else "" end
# if there is any notes, display them after the body message.
+ if ($dot.note | length) == 0
then ""
else if ($dot.note | length) == 1
then "
Note: \($dot.note | join(" "))"
else "
Notes:
\($dot.note | map("* \(.)") | join("\n"))"
end end
| escapeNewline;
# hlint generates a json array of messages
map(
"::warning file=\(.file),line=\(.startLine),col=\(.startColumn),endLine=\(.endLine),endColumn=\(.endColumn),title=\(.|formatTitle)"
)
# split into lines of text
| .[]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment