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.59 kB
39
def containsLatex (s : String) : Bool :=
body · 2 lines
  (s.splitOn "\\[").length > 1 || (s.splitOn "\\]").length > 1 ||
  (s.splitOn "\\(").length > 1 || (s.splitOn "\\)").length > 1
43
def containsLegacyUrlLink (s : String) : Bool :=
body · 1 line
  (s.splitOn "][http://").length > 1 || (s.splitOn "][https://").length > 1
46
def getDocstringText (stx : TSyntax ``Command.declModifiers) : String :=
body · 2 lines
  let docstring := stx.raw[0]!
  Syntax.getAtomVal (docstring[0]![1]!)
50
def lintDocstring (location : Syntax) (text : String) : CommandElabM Unit := do
body · 6 lines
  if containsLatex text then
    logLintIf linter.style.latex_docstring location
      "Docstrings should use `$ $` or `$$ $$` for math formulas instead of `\\[ \\]` or `\\( \\)`."
  if containsLegacyUrlLink text then
    logLintIf linter.style.latex_docstring location
      "Docstring URLs should use `[label](https://...)`, not `[label][https://...]`."

The linter checking markup in docstrings.

59
def latexDocstringLinter : Linter where
body · 11 lines
  run := withSetOptionIn fun stx => do
    if stx.getKind == ``Lean.Parser.Command.moduleDoc then
      let text := Syntax.getAtomVal stx[1]!
      lintDocstring stx text
      return
    match stx with
    | `(command| $mods:declModifiers theorem $name:declId $sig:declSig $val:declVal) =>
      let text := getDocstringText mods
      if text != "" then
        lintDocstring name text
    | _ => return