nielsr's picture
nielsr HF Staff
Add Formal Conjectures (snapshot 86a2f58): statements + files parquet, Lean project (part 7)
8ca48d7 verified
Raw History Blame Contribute Delete
2.91 kB

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.

53
def moduleDocstringLinter : Linter where run := withSetOptionIn fun stx ↦ do
body · 22 lines
  let fileName ← getFileName
  let env ← getEnv
  if stx.getKind == ``Lean.Parser.Command.moduleDoc then
    -- Duplicate check
    let numDocs := (getMainModuleDoc env).size + (getMainVersoModuleDocs env).snippets.size
    if numDocs > 1 then
      Lean.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 do
        Lean.Linter.logLintIf linter.style.moduleDocstring stx
          "This file has no module docstring (`/-! ... -/`). \
           Add one after the imports to document the file."