The module docstring linter checks two things:
- A file that has no/-! ... -/ block gets a warning on its
first non-moduleDoc command.
- A file that has more than one/-! ... -/ block gets a
warning on each extra block.
defmoduleDocstringLinter : Linterwhere run := withSetOptionIn fun stx ↦do
body · 22
lines
let fileName ← getFileName
let env ← getEnv
if stx.getKind == ``Lean.Parser.Command.moduleDoc then-- Duplicate checklet numDocs := (getMainModuleDoc env).size + (getMainVersoModuleDocs env).snippets.size
if numDocs > 1thenLean.Linter.logLintIf linter.style.moduleDocstring stx
"This file has more than one module docstring \ (`/-! ... -/`). Only the first one is treated as \ module documentation; convert additional ones to \ regular comments (`/- ... -/`)."else-- Missing check: on the first non-moduleDoc command,-- warn if no moduleDoc has been seen for this file.let checked ← checkedForDoc.get
unless checked.contains fileName do
checkedForDoc.modify (·.insert fileName)
let hasDoc := !(getMainModuleDoc env).isEmpty || !(getMainVersoModuleDocs env).snippets.isEmpty
unless hasDoc doLean.Linter.logLintIf linter.style.moduleDocstring stx
"This file has no module docstring (`/-! ... -/`). \ Add one after the imports to document the file."