Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions dev/scalastyle
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ if test ! -z "$ERRORS"; then
# break every regex below. Cheap to harden.
ERRORS_PLAIN=$(printf '%s' "$ERRORS" | sed -E $'s/\x1b\\[[0-9;]*[A-Za-z]//g')
# Helper: emit one `::error` annotation. Centralised so the two regex
# branches below stay short.
# branches below stay short. `col` is optional -- GitHub's annotation
# command accepts a `col=<n>` parameter, but not every scalastyle
# checker reports a column.
emit_annotation() {
local file="$1" lineno="$2" msg="$3"
local file="$1" lineno="$2" msg="$3" col="${4:-}"
# Strip the GitHub Actions workspace prefix so the annotation
# references the path as it appears in the repo.
local file_rel="${file#${GITHUB_WORKSPACE:-}/}"
Expand All @@ -57,8 +59,12 @@ if test ! -z "$ERRORS"; then
local msg_escaped="${msg//%/%25}"
msg_escaped="${msg_escaped//$'\r'/%0D}"
msg_escaped="${msg_escaped//$'\n'/%0A}"
printf '::error file=%s,line=%s,title=Scalastyle::%s\n' \
"$file_rel" "$lineno" "$msg_escaped"
local col_param=""
if [[ -n "$col" ]]; then
col_param=",col=$col"
fi
printf '::error file=%s,line=%s%s,title=Scalastyle::%s\n' \
"$file_rel" "$lineno" "$col_param" "$msg_escaped"
}
printf '%s\n' "$ERRORS_PLAIN" | while IFS= read -r raw; do
# Two scalastyle output formats reach us:
Expand All @@ -75,14 +81,23 @@ if test ! -z "$ERRORS"; then
# through `streams.value.log.error(...)` -- which is what the
# explicit `scalastyle` / `test:scalastyle` tasks invoked by
# this script do, and so this is the format we see in CI:
# [error] <path>:<line>: <message>
# The leading `[error] ` plus a single `:<line>:` (with no
# `:<col>:` follow-up) is what tells it apart from a regular
# Scala compile error of shape `[error] <path>:<line>:<col>: <msg>`.
if [[ "$raw" =~ ^error[[:space:]]+file=([^[:space:]]+)[[:space:]]+message=(.*)[[:space:]]+line=([0-9]+)([[:space:]]+column=[0-9]+)?$ ]]; then
emit_annotation "${BASH_REMATCH[1]}" "${BASH_REMATCH[3]}" "${BASH_REMATCH[2]}"
elif [[ "$raw" =~ ^\[error\][[:space:]]+(/[^:[:space:]]+):([0-9]+):[[:space:]]+(.+)$ ]]; then
emit_annotation "${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}" "${BASH_REMATCH[3]}"
# [error] <path>:<line>[:<col>]: <message>
# The column is present for some checkers (e.g. `nonascii`)
# and absent for others, so it's optional here too. This
# shape is unambiguously a style violation rather than a
# genuine Scala compile error of the same
# `[error] <path>:<line>:<col>: <msg>` shape: SparkBuild.scala
# deliberately does not attach style checking to
# `(Compile / compile)` (see `enableScalaStyle`), precisely so
# a broken compile elsewhere can't cascade into the style job
# and vice versa -- a real compiler error structurally cannot
# reach this script's input.
if [[ "$raw" =~ ^error[[:space:]]+file=([^[:space:]]+)[[:space:]]+message=(.*)[[:space:]]+line=([0-9]+)([[:space:]]+column=([0-9]+))?$ ]]; then
emit_annotation "${BASH_REMATCH[1]}" "${BASH_REMATCH[3]}" "${BASH_REMATCH[2]}" \
"${BASH_REMATCH[5]}"
elif [[ "$raw" =~ ^\[error\][[:space:]]+(/[^:[:space:]]+):([0-9]+):(([0-9]+):)?[[:space:]]+(.+)$ ]]; then
emit_annotation "${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}" "${BASH_REMATCH[5]}" \
"${BASH_REMATCH[4]}"
fi
done
fi
Expand Down