name: clean description: Fix warnings line by line and bring code into compliance with Mathlib style standards.
Clean Mode
Fix compiler warnings and linter hints in an existing file, line by line, without changing proof structure.
Target: $ARGUMENTS
Procedure
- Run
lean_diagnostic_messageson the target file with no severity filter to get the full list of warnings, hints, and infos. - Work through them one at a time, from top to bottom.
- After each fix, re-run
lean_diagnostic_messages severity="error"to confirm no new errors were introduced. - After clearing a batch of warnings, show the user a summary of what was fixed.
Lean Linter Workflow
- Treat
lean_diagnostic_messagesandrunLinteras different signals.lean_diagnostic_messagestells you whether the file currently compiles in the editor;lake exe runLinterchecks extra style linters and may report issues from imported files too. - If
runLinteroutput looks stale or disagrees with the source you just edited, rebuild the target module first:lake build <Module>and then rerunlake exe runLinter <Module>. - After changing a declaration that affects linter behavior directly (especially
@[simp]lemmas andsimpNFissues), do not trust an old terminal run. Always rerunlake build <Module> && lake exe runLinter <Module>. - When linting a module, separate errors in the target file from errors coming from imports before deciding what to fix in
/clean.
What belongs here
- Deprecation warnings: replace deprecated names with their canonical Mathlib successors (use
lean_hover_infoorlean_leansearchto find the replacement). - Unused variable warnings (
_prefix or remove): renamex→_xor_as appropriate. Try this:suggestions: applysimp only [...],exact ...,apply ...suggestions fromsimp?/exact?/apply?. Uselean_diagnostic_messages severity="info"to retrieve them.- Linter hints:
@[simp]on non-simp-normal forms,protectedsuggestions,noncomputableplacement, etc. - Style:
lemmavstheoremper convention inassistants.md; doc string format (/-- ... -/with a period); whitespace. - Namespace hygiene: remove redundant
openstatements; use fully qualified names where the open causes ambiguity.
Rules
- The proof must compile (no errors) after every single edit.
- Never change proof structure — don't extract lemmas, rename theorems, or reorder steps. Use
/refactorfor that. - If a warning cannot be fixed without restructuring, note it for the user and skip it.
- If a
Try this:suggestion changes the meaning or makes the proof fragile, don't apply it blindly — flag it.