scripts/check-clippy-limits.sh (check-local.sh --clippy-limits) counts the three lints per crate with thresholds 30 / 10 / 5 and fails when a total over all crates rises above clippy-limits-baseline.json. The root clippy.toml carries only the two thresholds of allow-by-default lints: too_many_arguments is on by default, and a root threshold of 5 fails the hard Clippy gates of strata-control and strata-desktop-core. No source enables the lints and no rustfmt.toml is added. check-local.sh --product runs the limits self-tests and the limits gate next to the architecture gate.
33 lines
2.2 KiB
Bash
Executable File
33 lines
2.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Opt-in Clippy ratchet for the lawbook 301 lints (STRA-367): counts clippy::too_many_lines, cognitive_complexity and
|
|
# too_many_arguments per crate and fails when a total over all crates rises above clippy-limits-baseline.json.
|
|
# Slow (a full Clippy build of the workspace): not part of the default gate; check-local.sh --clippy-limits runs it.
|
|
#
|
|
# scripts/check-clippy-limits.sh compare with the baseline
|
|
# scripts/check-clippy-limits.sh --update-baseline [--allow-increase]
|
|
# CLIPPY_LIMITS_ARGS="-p leleka-memory" restrict the packages (default: --workspace)
|
|
#
|
|
# Thresholds: scripts/limits/clippy/clippy.toml, passed as CLIPPY_CONF_DIR (the root clippy.toml must not lower the
|
|
# default-on too_many_arguments threshold, it would fail the hard Clippy gates). Runs on Linux, WSL and Git Bash on
|
|
# Windows. No source enables these lints; they are requested on the command line only.
|
|
set -euo pipefail
|
|
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
py="$(command -v python3 || command -v python)"
|
|
conf="${repo_root}/scripts/limits/clippy"
|
|
if command -v cygpath >/dev/null 2>&1; then conf="$(cygpath -w "${conf}")"; fi
|
|
export CLIPPY_CONF_DIR="${conf}"
|
|
# Clippy's extra `-W` flags are not part of cargo's fingerprint: units cached by a run with other flags would replay their
|
|
# old diagnostics and undercount. A target directory of its own keeps every run of this script on the same flags.
|
|
export CARGO_TARGET_DIR="${CARGO_TARGET_DIR:-${repo_root}/target}/clippy-limits"
|
|
cd "${repo_root}"
|
|
out="$(mktemp)"
|
|
trap 'rm -f "${out}"' EXIT
|
|
# --cap-lints warn: a crate that denies warnings (#![deny(warnings)]) must still compile with the extra lints on.
|
|
# The counts are only used when cargo succeeded; a partial run must never become the baseline.
|
|
# shellcheck disable=SC2086
|
|
if ! cargo clippy --locked ${CLIPPY_LIMITS_ARGS:---workspace} --all-targets --no-deps --keep-going --message-format=json -- \
|
|
-W clippy::too_many_lines -W clippy::cognitive_complexity -W clippy::too_many_arguments --cap-lints warn > "${out}"; then
|
|
echo "cargo clippy failed: the counts would be incomplete, nothing was compared or written" >&2
|
|
exit 1
|
|
fi
|
|
"${py}" -I "${repo_root}/scripts/limits/clippy_ratchet.py" "$@" < "${out}" |