#!/usr/bin/env bash # Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. # SPDX-License-Identifier: Apache-2.0 # # Run formatters and linter, anything platform-independent and quick # # Usage: ./fmt.sh [--test] set -euo pipefail cd "$(dirname "$0")" # load the dev-env eval "$(dev-env/bin/dade-assist)" ## Config ## is_test= scalafmt_args=() hlint_diff=false dade_copyright_arg=update buildifier_target=//:buildifier-fix ## Functions ## log() { echo "fmt.sh: $*" >&2 } run() { echo "$ ${*%Q}" "$@" ret=$? if [[ $is_test = 1 && $ret -gt 0 ]]; then log "command failed with return $ret" log log "run ./fmt.sh to fix the issue" exit 1 fi return 0 } ## Main ## while [[ $# -gt 0 ]]; do case "$1" in -h | --help) cat <&2 exit 1 ;; esac done echo "\ ─────────────────────────────▄██▄ ──FORMAT ALL THE THINGS!!!───▀███ ────────────────────────────────█ ───────────────▄▄▄▄▄────────────█ ──────────────▀▄────▀▄──────────█ ──────────▄▀▀▀▄─█▄▄▄▄█▄▄─▄▀▀▀▄──█ ─────────█──▄──█────────█───▄─█─█ ─────────▀▄───▄▀────────▀▄───▄▀─█ ──────────█▀▀▀────────────▀▀▀─█─█ ──────────█───────────────────█─█ ▄▀▄▄▀▄────█──▄█▀█▀█▀█▀█▀█▄────█─█ █▒▒▒▒█────█──█████████████▄───█─█ █▒▒▒▒█────█──██████████████▄──█─█ █▒▒▒▒█────█───██████████████▄─█─█ █▒▒▒▒█────█────██████████████─█─█ █▒▒▒▒█────█───██████████████▀─█─█ █▒▒▒▒█───██───██████████████──█─█ ▀████▀──██▀█──█████████████▀──█▄█ ──██───██──▀█──█▄█▄█▄█▄█▄█▀──▄█▀ ──██──██────▀█─────────────▄▀▓█ ──██─██──────▀█▀▄▄▄▄▄▄▄▄▄▀▀▓▓▓█ ──████────────█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█ ──███─────────█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█ ──██──────────█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█ ──██──────────█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█ ──██─────────▐█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█ ──██────────▐█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█ ──██───────▐█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█▌ ──██──────▐█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█▌ ──██─────▐█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█▌ ──██────▐█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█▌ " # Check for correct copyrights run dade-copyright-headers "$dade_copyright_arg" . # We do test hlint via Bazel rules but we run it separately # to get linting failures early. HLINT=(hlint -j4) echo "\$ ${HLINT[*]}" if [ "$hlint_diff" = "true" ]; then # We do not run on deleted files, or files that have been added since we last rebased onto trunk. changed_haskell_files="$(git diff --name-only --diff-filter=ACMRT "$merge_base" | grep '\.hs$' || [[ $? == 1 ]])" if [[ -n "$changed_haskell_files" ]]; then "${HLINT[@]}" -j4 $changed_haskell_files fi else "${HLINT[@]}" --git fi # check for scala code style run scalafmt "${scalafmt_args[@]:-}" # check for Bazel build files code formatting run bazel run "$buildifier_target"