STRA-367: opt-in Clippy ratchet for too_many_lines, cognitive_complexity and too_many_arguments; limits gate in check-local --product
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.
This commit is contained in:
@@ -22,6 +22,7 @@ crates/deploy/data/expert-profile.bin -text binary
|
||||
# CI entry points run on Linux runners: LF whatever the checkout host's autocrlf says (docs/ci-audit.md).
|
||||
scripts/ci/** text eol=lf
|
||||
scripts/check-local.sh text eol=lf
|
||||
scripts/check-clippy-limits.sh text eol=lf
|
||||
scripts/check-ci-coverage.py text eol=lf
|
||||
scripts/install-pinned-rustup.sh text eol=lf
|
||||
scripts/test-cuda-fixed-ptx.sh text eol=lf
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
{
|
||||
"_comment": "Count of Clippy warnings per crate for the lawbook 301 lints, thresholds in scripts/limits/clippy/clippy.toml (scripts/check-clippy-limits.sh). A total per lint may only fall; regenerate with --update-baseline. Measured on Linux (WSL Ubuntu, Clippy 0.1.99). Not part of the default gate.",
|
||||
"clippy": {
|
||||
"leleka-backend-api": {
|
||||
"clippy::too_many_lines": 8
|
||||
},
|
||||
"leleka-context": {
|
||||
"clippy::too_many_lines": 12,
|
||||
"clippy::too_many_arguments": 1,
|
||||
"clippy::cognitive_complexity": 10
|
||||
},
|
||||
"leleka-cpu-kernels": {
|
||||
"clippy::too_many_lines": 8,
|
||||
"clippy::too_many_arguments": 3,
|
||||
"clippy::cognitive_complexity": 1
|
||||
},
|
||||
"leleka-cpu-sys": {
|
||||
"clippy::too_many_lines": 24,
|
||||
"clippy::too_many_arguments": 19,
|
||||
"clippy::cognitive_complexity": 4
|
||||
},
|
||||
"leleka-cpu-worker": {
|
||||
"clippy::too_many_lines": 13,
|
||||
"clippy::cognitive_complexity": 2,
|
||||
"clippy::too_many_arguments": 1
|
||||
},
|
||||
"leleka-cuda-driver": {
|
||||
"clippy::too_many_lines": 674,
|
||||
"clippy::too_many_arguments": 162,
|
||||
"clippy::cognitive_complexity": 240
|
||||
},
|
||||
"leleka-deploy": {
|
||||
"clippy::too_many_lines": 143,
|
||||
"clippy::cognitive_complexity": 34,
|
||||
"clippy::too_many_arguments": 2
|
||||
},
|
||||
"leleka-experimental-ref": {
|
||||
"clippy::too_many_arguments": 8,
|
||||
"clippy::too_many_lines": 23,
|
||||
"clippy::cognitive_complexity": 14
|
||||
},
|
||||
"leleka-gateway-domain": {
|
||||
"clippy::too_many_lines": 17,
|
||||
"clippy::cognitive_complexity": 6,
|
||||
"clippy::too_many_arguments": 3
|
||||
},
|
||||
"leleka-gateway-text": {
|
||||
"clippy::too_many_lines": 25,
|
||||
"clippy::cognitive_complexity": 4,
|
||||
"clippy::too_many_arguments": 1
|
||||
},
|
||||
"leleka-gguf": {
|
||||
"clippy::too_many_lines": 10,
|
||||
"clippy::cognitive_complexity": 2
|
||||
},
|
||||
"leleka-gptoss": {
|
||||
"clippy::too_many_arguments": 6,
|
||||
"clippy::too_many_lines": 24,
|
||||
"clippy::cognitive_complexity": 5
|
||||
},
|
||||
"leleka-gptoss-igpu": {
|
||||
"clippy::too_many_arguments": 1,
|
||||
"clippy::too_many_lines": 6
|
||||
},
|
||||
"leleka-gptoss-npu": {
|
||||
"clippy::too_many_lines": 9,
|
||||
"clippy::too_many_arguments": 3,
|
||||
"clippy::cognitive_complexity": 1
|
||||
},
|
||||
"leleka-gpu-npu-worker": {
|
||||
"clippy::too_many_arguments": 1,
|
||||
"clippy::too_many_lines": 5
|
||||
},
|
||||
"leleka-harmony": {
|
||||
"clippy::too_many_lines": 7,
|
||||
"clippy::cognitive_complexity": 3
|
||||
},
|
||||
"leleka-igpu": {
|
||||
"clippy::too_many_lines": 19,
|
||||
"clippy::too_many_arguments": 10,
|
||||
"clippy::cognitive_complexity": 1
|
||||
},
|
||||
"leleka-igpu-worker": {
|
||||
"clippy::too_many_lines": 2
|
||||
},
|
||||
"leleka-kar-codec": {
|
||||
"clippy::too_many_lines": 3,
|
||||
"clippy::too_many_arguments": 1
|
||||
},
|
||||
"leleka-memory": {
|
||||
"clippy::cognitive_complexity": 9,
|
||||
"clippy::too_many_lines": 19
|
||||
},
|
||||
"leleka-model-format": {
|
||||
"clippy::too_many_lines": 144,
|
||||
"clippy::cognitive_complexity": 45,
|
||||
"clippy::too_many_arguments": 15
|
||||
},
|
||||
"leleka-native-cpu-expert": {
|
||||
"clippy::cognitive_complexity": 41,
|
||||
"clippy::too_many_lines": 21,
|
||||
"clippy::too_many_arguments": 25
|
||||
},
|
||||
"leleka-npu-service": {
|
||||
"clippy::too_many_lines": 9,
|
||||
"clippy::too_many_arguments": 1,
|
||||
"clippy::cognitive_complexity": 1
|
||||
},
|
||||
"leleka-npu-worker": {
|
||||
"clippy::too_many_lines": 3
|
||||
},
|
||||
"leleka-obs": {
|
||||
"clippy::cognitive_complexity": 1,
|
||||
"clippy::too_many_lines": 4,
|
||||
"clippy::too_many_arguments": 1
|
||||
},
|
||||
"leleka-offline-tools": {
|
||||
"clippy::too_many_lines": 9
|
||||
},
|
||||
"leleka-openvino": {
|
||||
"clippy::too_many_lines": 2
|
||||
},
|
||||
"leleka-quant-core": {
|
||||
"clippy::too_many_lines": 10,
|
||||
"clippy::cognitive_complexity": 7
|
||||
},
|
||||
"leleka-runtime": {
|
||||
"clippy::too_many_lines": 611,
|
||||
"clippy::too_many_arguments": 215,
|
||||
"clippy::cognitive_complexity": 172
|
||||
},
|
||||
"leleka-runtime-client": {
|
||||
"clippy::too_many_lines": 15,
|
||||
"clippy::cognitive_complexity": 1
|
||||
},
|
||||
"leleka-sampler-ref": {
|
||||
"clippy::cognitive_complexity": 4,
|
||||
"clippy::too_many_lines": 18,
|
||||
"clippy::too_many_arguments": 1
|
||||
},
|
||||
"leleka-serving-policy": {
|
||||
"clippy::too_many_lines": 20,
|
||||
"clippy::cognitive_complexity": 8
|
||||
},
|
||||
"leleka-tokenizer": {
|
||||
"clippy::too_many_lines": 22,
|
||||
"clippy::too_many_arguments": 1,
|
||||
"clippy::cognitive_complexity": 2
|
||||
},
|
||||
"leleka-worker-protocol": {
|
||||
"clippy::too_many_lines": 3,
|
||||
"clippy::too_many_arguments": 1,
|
||||
"clippy::cognitive_complexity": 1
|
||||
},
|
||||
"strata-control": {
|
||||
"clippy::too_many_arguments": 20,
|
||||
"clippy::too_many_lines": 362,
|
||||
"clippy::cognitive_complexity": 91
|
||||
},
|
||||
"strata-desktop-core": {
|
||||
"clippy::too_many_lines": 137,
|
||||
"clippy::cognitive_complexity": 20,
|
||||
"clippy::too_many_arguments": 2
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
# Thresholds of the Clippy limits ratchet (STRA-367, lawbook 301, docs/architecture/limits-gate.md).
|
||||
# too_many_lines and cognitive_complexity are allow-by-default lints: these two numbers change nothing for the default
|
||||
# `cargo clippy ... -D warnings` gates, and no source enables the lints. scripts/check-clippy-limits.sh turns them on as
|
||||
# warnings and ratchets the count per crate.
|
||||
#
|
||||
# too-many-arguments-threshold = 5 is NOT set here: too_many_arguments is on by default, so 5 would fail the hard Clippy
|
||||
# gates of check-local.sh --product today (strata-control, strata-desktop-core: functions with 6 and 7 arguments). The
|
||||
# opt-in script reads scripts/limits/clippy/clippy.toml (CLIPPY_CONF_DIR), which repeats these two keys and adds that one.
|
||||
too-many-lines-threshold = 30
|
||||
cognitive-complexity-threshold = 10
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
#!/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}"
|
||||
+27
-9
@@ -8,6 +8,8 @@
|
||||
# the release build of the six product binaries (leleka, strata-next, leleka-inference,
|
||||
# leleka-daemon, leleka-cli, leleka-seal-exec), the tests of the product crates, the
|
||||
# type-check of the CUDA-feature crates, Clippy and rustfmt (known debt is reported)
|
||||
# scripts/check-local.sh --clippy-limits opt-in, slow: ratchet of the Clippy length/complexity/argument lints (STRA-367,
|
||||
# scripts/check-clippy-limits.sh); alone it runs only that, next to a mode it runs last
|
||||
#
|
||||
# Environment:
|
||||
# STRICT_DEBT=1 fail on the known format/Clippy debt listed below instead of warning
|
||||
@@ -21,15 +23,22 @@ set -euo pipefail
|
||||
|
||||
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
|
||||
mode=full
|
||||
case "${1:-}" in
|
||||
""|--full) ;;
|
||||
--fast) mode=fast ;;
|
||||
--port) mode=port ;;
|
||||
--product) mode=product ;;
|
||||
-h|--help) sed -n '2,20p' "${BASH_SOURCE[0]}"; exit 0 ;;
|
||||
*) echo "usage: $0 [--fast|--port|--product|--full]" >&2; exit 2 ;;
|
||||
esac
|
||||
mode=""
|
||||
clippy_limits=0
|
||||
for arg in "$@"; do
|
||||
case "${arg}" in
|
||||
""|--full) mode=full ;;
|
||||
--fast) mode=fast ;;
|
||||
--port) mode=port ;;
|
||||
--product) mode=product ;;
|
||||
--clippy-limits) clippy_limits=1 ;;
|
||||
-h|--help) sed -n '2,22p' "${BASH_SOURCE[0]}"; exit 0 ;;
|
||||
*) echo "usage: $0 [--fast|--port|--product|--full] [--clippy-limits]" >&2; exit 2 ;;
|
||||
esac
|
||||
done
|
||||
if [[ -z "${mode}" ]]; then
|
||||
if ((clippy_limits)); then mode=clippy-limits; else mode=full; fi
|
||||
fi
|
||||
|
||||
# Known debt on the port branch: these crates are not rustfmt/Clippy clean (other agents own the sources, so the gate
|
||||
# reports them instead of reformatting). New debt-free crates must be added to strict_crates below, not here.
|
||||
@@ -124,6 +133,9 @@ product_path() {
|
||||
echo "== product: architecture gate (layers, adapter edges, size and source ratchets; STRA-338)"
|
||||
gate python3 "${repo_root}/scripts/check_architecture_test.py"
|
||||
gate python3 "${repo_root}/scripts/check-architecture.py"
|
||||
echo "== product: limits gate (function 30 lines, complexity 10, nesting 4, width 120 on new and changed code; legacy census only falls; STRA-367)"
|
||||
gate python3 "${repo_root}/scripts/check_limits_test.py"
|
||||
gate python3 "${repo_root}/scripts/check-limits.py"
|
||||
echo "== product: sealed PTX are byte-exact LF (a CRLF checkout makes the engine refuse to start)"
|
||||
if grep -rl --include='*.ptx' $'\r' "${repo_root}/crates/cuda-driver" >&2; then
|
||||
echo "CR found in the sealed PTX listed above: check out with core.autocrlf=false (.gitattributes marks them -text)" >&2
|
||||
@@ -175,6 +187,10 @@ product_path() {
|
||||
gate debt cargo fmt -p leleka-deploy -p leleka-memory -p leleka-cuda-driver -p leleka-runtime -p leleka-native-cpu-expert --check
|
||||
gate debt cargo clippy "${manifest[@]}" -p leleka-cuda-driver --all-targets --all-features --no-deps -- -D warnings
|
||||
gate debt cargo clippy "${manifest[@]}" -p leleka-runtime --all-targets --no-deps -- -D warnings
|
||||
if ((clippy_limits)); then
|
||||
echo "== product: Clippy limits ratchet (opt-in, slow; STRA-367)"
|
||||
gate "${repo_root}/scripts/check-clippy-limits.sh"
|
||||
fi
|
||||
if ((${#failed[@]})); then
|
||||
echo "== product: ${#failed[@]} step(s) failed:" >&2
|
||||
printf ' %s\n' "${failed[@]}" >&2
|
||||
@@ -183,7 +199,9 @@ product_path() {
|
||||
echo "== product: all steps passed"
|
||||
}
|
||||
|
||||
if [[ "${mode}" == clippy-limits ]]; then exec "${repo_root}/scripts/check-clippy-limits.sh"; fi
|
||||
if [[ "${mode}" == product ]]; then product_path; exit 0; fi
|
||||
if ((clippy_limits)); then echo "--clippy-limits runs alone or together with --product" >&2; exit 2; fi
|
||||
fast_path
|
||||
[[ "${mode}" == fast ]] && exit 0
|
||||
linux_typecheck
|
||||
|
||||
Reference in New Issue
Block a user