Skip to content

Commit fea9430

Browse files
kim-emReemMelamed
authored andcommitted
ci: wire up lake lint to run runLinter (leanprover-community#39934)
This PR configures the `mathlib` package so that the standard `lake lint` command is equivalent to `lake exe runLinter Mathlib`, by setting ``` lintDriver := "batteries/runLinter" lintDriverArgs := #["Mathlib"] ``` on the `package mathlib` declaration. `runLinter` is already a `lean_exe` in batteries, so the `<pkg>/<name>` syntax lets mathlib reuse it directly. The CI workflows in `build_template.yml` and `nolints.yml` are also switched from invoking `lake exe runLinter [args] Mathlib` to `lake lint -- [args]` so there's a single source of truth for "lint mathlib", and so that local users get the same behaviour as CI. ### Behavior change for local users Before this PR, `lake lint` in a Mathlib checkout errored out with "no lint driver configured" and was essentially unused. After this PR, `lake lint` runs the full Batteries linter over all of Mathlib, which is a substantial multi-minute job. Anyone who has scripts or muscle memory expecting `lake lint` to be a no-op should be aware. The previous direct invocation, `lake exe runLinter Mathlib`, continues to work for anyone who prefers it. The `scripts/bench/lint/` benchmark intentionally keeps the direct `lake exe runLinter Mathlib` invocation so its measurements are not affected by anything `lake lint` may do above the linter. Motivated by a recent Zulip discussion in which it became clear that very few people know `lake lint` exists, partly because few packages bother to configure a lint driver: https://leanprover.zulipchat.com/#narrow/channel/270676-lean4/topic/Using.20.60lake.20test.60.20effectively Companion to leanprover/reference-manual#855 (which documents the mechanism in the Lean reference manual). 🤖 Prepared with Claude Code
1 parent 8a71bbc commit fea9430

3 files changed

Lines changed: 9 additions & 7 deletions

File tree

.github/workflows/build_template.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -513,19 +513,19 @@ jobs:
513513
run: |
514514
cd pr-branch
515515
set -o pipefail
516-
# Try running with --trace; if it fails due to argument parsing, the PR needs to merge master
516+
# If lint fails because the PR predates lake-lint configuration or the
517+
# old --trace argument-parsing behavior, ask the author to merge master.
517518
# We use .lake/ for the output file because landrun restricts /tmp access
518519
for attempt in 1 2; do
519-
if timeout 10m env LEAN_ABORT_ON_PANIC=1 stdbuf -oL lake exe runLinter --trace Mathlib 2>&1 | tee ".lake/lint_output_attempt_${attempt}.txt"; then
520+
if timeout 10m env LEAN_ABORT_ON_PANIC=1 stdbuf -oL lake lint -- --trace 2>&1 | tee ".lake/lint_output_attempt_${attempt}.txt"; then
520521
break
521522
fi
522523
status=${PIPESTATUS[0]}
523-
if grep -q "cannot parse arguments" ".lake/lint_output_attempt_${attempt}.txt"; then
524+
if grep -qE "cannot parse arguments|no lint driver configured" ".lake/lint_output_attempt_${attempt}.txt"; then
524525
echo ""
525526
echo "=============================================================================="
526-
echo "ERROR: Your branch uses an older version of runLinter that doesn't support"
527-
echo "the --trace flag. Please merge 'master' into your PR branch to get the"
528-
echo "updated linter, then push again."
527+
echo "ERROR: Your branch predates the current 'lake lint' configuration."
528+
echo "Please merge 'master' into your PR branch and push again."
529529
echo ""
530530
echo "You can do this with:"
531531
echo " git fetch upstream"

.github/workflows/nolints.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- name: update nolints.json
2727
shell: bash
2828
run: |
29-
env LEAN_ABORT_ON_PANIC=1 lake exe runLinter --trace --update Mathlib
29+
env LEAN_ABORT_ON_PANIC=1 lake lint -- --trace --update
3030
3131
- name: Generate app token
3232
id: app-token

lakefile.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ abbrev mathlibLeanOptions := #[
4848

4949
package mathlib where
5050
testDriver := "MathlibTest"
51+
lintDriver := "batteries/runLinter"
52+
lintDriverArgs := #["Mathlib"]
5153
-- These are additional settings which do not affect the lake hash,
5254
-- so they can be enabled in CI and disabled locally or vice versa.
5355
-- Warning: Do not put any options here that actually change the olean files,

0 commit comments

Comments
 (0)