mas/script/format

48 lines
1.2 KiB
Text
Raw Normal View History

#!/bin/bash -eu
2021-03-29 00:16:37 +00:00
#
# script/format
# mas
#
# Linting checks for development and CI.
#
# Automatically formats and fixes style violations using various tools.
#
# Please keep in sync with script/lint.
#
mas_dir="$(readlink -fn "$(dirname "${BASH_SOURCE:-"${0}"}")/..")"
2021-03-29 00:16:37 +00:00
if ! cd -- "${mas_dir}"; then
printf $'Error: Could not cd into mas directory: %s\n' "${mas_dir}" >&2
exit 1
fi
printf $'==> 🚨 Formatting mas\n'
for LINTER in markdownlint shfmt swift-format swiftformat swiftlint; do
2021-03-29 00:16:37 +00:00
if [[ ! -x "$(command -v ${LINTER})" ]]; then
printf $'error: %s is not installed. Run \'script/bootstrap\' or \'brew install %s\'.\n' "${LINTER}" "${LINTER}"
2021-03-29 00:16:37 +00:00
exit 1
fi
done
2021-04-28 21:50:29 +00:00
for SOURCE in Package.swift Sources Tests; do
printf -- $'--> 🕊 %s swift-format\n' "${SOURCE}"
swift-format format --in-place --recursive "${SOURCE}"
printf -- $'--> 🕊 %s swiftformat\n' "${SOURCE}"
swiftformat "${SOURCE}"
printf -- $'--> 🕊 %s swiftlint\n' "${SOURCE}"
swiftlint --fix --strict "${SOURCE}"
2021-03-29 00:16:37 +00:00
done
printf -- $'--> 📜 Bash shfmt\n'
shfmt \
--write \
--list \
--indent 2 \
--case-indent \
contrib/ script/
2021-03-29 00:16:37 +00:00
printf -- $'--> 〽️ Markdown\n'
markdownlint --config .markdownlint.json --fix .github .