WUT_Computer_Science/.pre-commit-config.yaml
Krzysztof kuhy Rudnicki f7763bb1cd Add a run.sh to every course, and fix the code that would not build
All 44 directories now probe: 38 runnable, 5 no-code, 1 blocked (ENUME needs
MATLAB or Octave, neither of which is on this machine).

The runners are stubs over one shared scripts/course_lib.sh rather than 44
copies of the logic, for the same reason the gates live in ~/utils. A stub
passes its kind as ARGUMENTS -- course_main --kind python --entry ... -- "$@"
-- rather than setting globals, because globals a linter cannot see being read
mean SC2034 on every one of them, and the only cure would be 44 disables.

Fixed along the way:
  - Generating the stubs overwrote Programming/PSD/run.sh, the original
    coursework runner. Restored, and given a --probe early exit instead so it
    is otherwise untouched: it installs packages with sudo and starts Kafka,
    which is exactly what a probe must not trigger.
  - The probe guard only recognised runners containing the literal --probe, so
    the new stubs (which delegate to the library) all read unprobed. It now
    also accepts delegation to course_lib.sh.
  - Blocked probes reported "unknown" because _require_any prints the tool it
    found, so probes redirected its stdout -- swallowing the failure reason
    too. Split into _probe_any, and ENUME now says exactly what it needs.
  - shellcheck runs with -x so it follows the sourced library; without it every
    stub reports SC1091 and the only alternative is a per-file disable. The
    library itself carries `# shellcheck shell=bash` because it has no shebang
    on purpose -- it is sourced, never executed.

Then EADS was actually run, and three of its six C++ files did not compile:
  - lab3.cpp: copyDictionary was declared taking Dictionary* but its body used
    Node members, and the copy constructor called copyTree(), which does not
    exist. The copy also dropped key and balanceFactor. Now compiles AND runs,
    printing its AVL tests.
  - MidTerm/task2.cpp: a const mismatch between declaration and definition, a
    stray semicolon before a function body, findNode calling a Tree method on
    a treeNode*, and a while loop that never advanced. sumNodeSub also had no
    base case -- unreachable before, because the const mismatch meant its body
    was never compiled.
These compiled years ago because older GCC did not diagnose uninstantiated
template bodies. Fragments with no main() are now type-checked with -c rather
than linked, since two of these files are exam answers, not programs.

Binaries go to a gitignored build/ -- an extensionless executable dropped next
to its source is not something .gitignore catches by name.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0172dj34FDpao6wsix8ZuCzE
2026-08-28 18:37:55 +02:00

76 lines
3.1 KiB
YAML

# Install: ./install.sh (or: pre-commit install && pre-commit install --hook-type pre-push)
# Fast lint: pre-commit run --all-files
#
# Ordering rule for this repo: a hook lands only once the thing it gates is
# already clean, so `pre-commit run --all-files` is green at every commit.
# Hooks still to come, each blocked on its own cleanup:
# - file-length blocked on the .tex/code splits and TODO-file-length-250.md
# - ruff / mypy blocked on the root pyproject.toml (Milestone 4)
# - dependency-freshness blocked on the upgrade itself; the gate and the
# upgrade must land in the SAME commit or the repo is
# instantly and permanently red
# - trailing-whitespace / end-of-file-fixer these REWRITE files, so they get
# their own reviewed cleanup commit first
default_language_version:
python: python3
default_stages: [pre-commit]
fail_fast: false
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
# Structural checks only -- none of these rewrite a file.
- id: check-merge-conflict
- id: check-case-conflict
- id: check-symlinks
- id: destroyed-symlinks
- id: detect-private-key
# tsconfig*.json and .vscode/*.json are JSONC -- both TypeScript and
# VS Code document comments and trailing commas as valid there, and
# check-json uses a strict RFC parser. This is the wrong parser for
# those files, not a defect being suppressed; every other .json is
# still checked. (The one real failure this hook found, a committed
# merge conflict in EARIN/.vscode/extensions.json, is fixed.)
- id: check-json
exclude: |
(?x)^(
.*/tsconfig[^/]*\.json|
.*/\.vscode/[^/]*\.json
)$
- id: check-toml
- id: check-yaml
args: [--unsafe]
# 2 MB. The four 39 MB movies.csv copies are already tracked and stay
# (approved decision 6); this stops the NEXT one.
- id: check-added-large-files
args: [--maxkb=2000]
- repo: local
hooks:
# Coursework deliverables are allowed under the two course trees;
# compiled output is allowed nowhere. See .binary-allowlist.
- id: no-binaries
name: block binary files outside the allowlist
entry: scripts/check_no_binaries.sh
language: script
pass_filenames: true
# Thin shim into ~/utils, which owns the four markdown namespaces.
- id: md-naming
name: markdown naming convention
entry: scripts/check_md_naming.sh
language: system
files: \.(md|markdown)$
# -x so shellcheck FOLLOWS sourced files. The 44 per-course run.sh stubs
# source scripts/course_lib.sh; without -x every one of them reports
# SC1091 "not following", and the only other way to silence that is a
# per-file disable, which is banned here.
- id: shellcheck
name: shellcheck
entry: bash -c 'printf "%s\0" "$@" | xargs -0 -n 40 shellcheck -x' --
language: system
types: [shell]
exclude_types: [zsh]