2024-09-30 11:28:25 -04:00
#!/bin/bash -u
2019-01-15 18:31:51 -07:00
#
# script/lint
2019-01-18 21:37:51 -07:00
# mas
2019-01-15 18:31:51 -07:00
#
2021-03-21 19:17:28 -07:00
# Linting checks for development and CI.
2019-01-15 18:31:51 -07:00
#
2021-03-28 17:16:37 -07:00
# Reports style violations without making any modifications to the code.
#
# Please keep in sync with script/format.
#
2019-01-12 13:30:08 -07:00
2024-09-30 11:28:25 -04:00
set -o pipefail
2019-01-12 13:30:08 -07:00
2024-09-30 11:28:25 -04:00
mas_dir="$(readlink -fn "$(dirname "${BASH_SOURCE:-"${0}"}")/..")"
if ! cd -- "${mas_dir}"; then
printf $'Error: Could not cd into mas directory: %s\n' "${mas_dir}" >&2
exit 1
fi
2024-10-26 23:48:05 -04:00
printf $'==> 🚨 Linting mas (%s)\n' "$(script/version --write)"
2024-09-30 11:28:25 -04:00
2024-10-26 23:48:05 -04:00
for linter in git markdownlint periphery shellcheck shfmt swift-format swiftformat swiftlint yamllint; do
2024-09-30 11:28:25 -04: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-22 00:01:52 -07:00
exit 1
fi
done
2024-09-30 11:28:25 -04:00
exit_code=0
for source in Package.swift Sources Tests; do
2024-10-24 07:46:50 -04:00
printf -- $'--> 🦅 %s swift-format\n' "${source}"
2024-09-30 11:28:25 -04:00
swift-format lint --strict --recursive "${source}"
((exit_code |= "${?}"))
2024-10-24 07:46:50 -04:00
printf -- $'--> 🦅 %s swiftformat\n' "${source}"
2024-09-30 11:28:25 -04:00
script -q /dev/null swiftformat --lint --strict "${source}" |
2024-10-24 07:46:50 -04:00
(grep -vxE '(?:\^D\x08{2})?Running SwiftFormat\.{3}\r|\(lint mode - no files will be changed\.\)\r|Reading (?:config|swift-version) file at .*|\x1b\[32mSwiftFormat completed in \d+\.\d+s\.\x1b\[0m\r|0/\d+ files require formatting\.\r' || true)
2024-09-30 11:28:25 -04:00
((exit_code |= "${?}"))
2024-10-24 07:46:50 -04:00
printf -- $'--> 🦅 %s swiftlint\n' "${source}"
2024-09-30 11:28:25 -04:00
swiftlint --strict --quiet "${source}" 2> \
>((grep -vxF $'warning: Configuration option \'allow_multiline_func\' in \'opening_brace\' rule is deprecated. Use the option \'ignore_multiline_function_signatures\' instead.' || true) >&2)
((exit_code |= "${?}"))
2021-03-21 22:25:18 -07:00
done
2024-02-18 13:16:50 -07:00
2024-09-30 11:28:25 -04:00
printf -- $'--> 🐚 Bash shellcheck\n'
2021-06-08 18:56:27 -07:00
shellcheck --shell=bash script/*
2024-09-30 11:28:25 -04:00
((exit_code |= "${?}"))
printf -- $'--> 📜 Bash shfmt\n'
2024-03-31 11:05:04 -06:00
shfmt \
--diff \
--list \
--indent 2 \
--case-indent \
contrib/ script/
2024-09-30 11:28:25 -04:00
((exit_code |= "${?}"))
2021-03-21 19:17:28 -07:00
2024-09-30 11:28:25 -04:00
printf -- $'--> 〽️ Markdown\n'
2021-05-03 13:42:10 -07:00
markdownlint --config .markdownlint.json .github .
2024-09-30 11:28:25 -04:00
((exit_code |= "${?}"))
2021-05-03 13:42:10 -07:00
2024-09-30 11:28:25 -04:00
printf -- $'--> 🌳 Git\n'
PAGER='cat' git diff --check
((exit_code |= "${?}"))
2019-01-15 18:15:55 -07:00
2024-10-26 23:48:05 -04:00
printf -- $'--> 🖊 YAML\n'
yamllint .
((exit_code |= "${?}"))
2024-09-30 11:28:25 -04:00
printf -- $'--> 🌀 Periphery\n'
script -q /dev/null periphery scan --strict --quiet --disable-update-check |
2024-10-24 07:46:50 -04:00
(grep -vxE '(?:\x1b\[0;1;32m|\^D\x08{2})\* (?:\x1b\[0;0m\x1b\[0;1m)?No unused code detected\.(?:\x1b\[0;0m)?\r' || true)
2024-09-30 11:28:25 -04:00
((exit_code |= "${?}"))
exit "${exit_code}"