All skills

Use when editing .lean files, debugging Lean 4 builds (type mismatch, sorry, failed to synthesize instance, axiom warnings, lake build errors), searching mathlib for lemmas, formalizing mathematics in Lean, finding a counterexample to, refuting, or disproving a Lean statement, or learning Lean 4 concepts. Also trigger when the user asks for help with Lean 4, mathlib, or lakefile. Do NOT trigger for Coq/Rocq, Agda, Isabelle, HOL4, Mizar, Idris, Megalodon, or other non-Lean theorem provers.

Use this Skill: https://skilld.dev/gh/cameronfreer/lean4-skills/lean4

This session only. Nothing lands on disk.

referenceslinter-authoring.md

≈879 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Linter Authoring

Scope: Not part of the prove/autoprove default loop. Consulted when writing or maintaining project-specific Lean 4 linters.

Version metadata:

  • Verified on: Lean reference + release notes through v4.27.0
  • Last validated: 2026-02-17
  • Confidence: medium (docs reviewed; snippets not batch-compiled)

When to Use

  • Project-specific style or safety checks
  • Fast feedback before runtime bugs (slow paths, unsafe usage)
  • Consistent policy enforcement across a codebase

Composable Rule Blocks

Build linters from small parts you can reuse:

  • Option: register_option linter.myRule
  • Finder: findBad : Syntax -> Array Syntax
  • Filter: file or namespace exclusions
  • Action: logWarningAt vs throwErrorAt
  • Registration: initialize addLinter ...

Each rule should be a thin layer over these blocks.

Core Pattern

import Lean

open Lean Elab Command

/-- Option to control the linter. -/
register_option linter.myRule : Bool := {
  defValue := true
  descr := "warn about X"
}

def myRuleEnabled : CommandElabM Bool :=
  return linter.myRule.get (← getOptions)

partial def findBad (stx : Syntax) : Array Syntax := Id.run do
  let mut r := #[]
  match stx with
  | .ident _ raw _ _ =>
      if raw.toString == "BadIdent" then r := r.push stx
  | .node _ _ args =>
      for a in args do r := r ++ findBad a
  | _ => pure ()
  return r

/-- Warning message. -/
def myRuleMsg : MessageData :=
  m!"avoid BadIdent; use GoodIdent"

/-- Linter run function. -/
def myRuleRun (stx : Syntax) : CommandElabM Unit := do
  unless ← myRuleEnabled do return
  for ident in findBad stx do
    logWarningAt ident myRuleMsg

/-- Linter registration. -/
def myRuleLinter : Linter := {
  run := myRuleRun
  name := `MyProject.Linter.myRule
}

initialize addLinter myRuleLinter

Warnings vs Errors

  • Use logWarningAt for style or best-practice rules
  • Use throwErrorAt for correctness or safety rules

File-Based Exclusions

If a rule is too noisy for benchmarks or tests, skip by file path:

private def isBenchOrTest (fileName : String) : Bool :=
  fileName.contains "/Test/" ||
  fileName.contains "/Benchmark/" ||
  fileName.endsWith "Bench.lean"

if isBenchOrTest (← getFileName) then return

Project-Wide Enablement

  • Import linters in a common module (e.g., Basic.lean) so they run everywhere
  • Enable them in lakefile.lean using weak options:
leanOptions := #[
  ⟨`weak.linter.myRule, true⟩
]

Use weak. so builds do not fail when the option is absent.

Local Disable Pattern

set_option linter.myRule false in
-- justify why the exception is needed

Good Linter Messages

  • Explain the why, not just the what
  • Provide a concrete fix snippet
  • Keep the message stable so users can search it

Linter Test File

Create a small file that demonstrates the warning and how to disable it:

MyProject/Linter/MyRuleTest.lean

This helps prevent regressions when refactoring syntax traversal.

Checklist

  • Rule has a clear safety or style goal
  • Finder returns the smallest offending node
  • False positives are minimized (or skipped by file path)
  • Option exists and defaults to a sensible value
  • Error span is attached to the exact syntax node

See Also

Source: SKILL.md on GitHub

2 warnings3d5 checks · Risk MEDIUM
  • Gen Agent Trust Hub3d

    The skill provides a specialized environment for Lean 4 theorem proving. It includes functionality for generating and executing dynamic scripts to refute mathematical statements and processes data from external sources such as PDFs and web pages, which introduces an indirect prompt injection surface.

  • Socket3d

    No alerts

  • Snyk3d

    Risk: LOW · No issues

  • Runlayer6mo

    14/36 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 818c19a. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 19 hours ago.

Activeupdated last week

README badge

README badge for cameronfreer/lean4-skills