The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V34. The tactics of Mathlib

Mathlib.Tactic.Linter.Header

4 declarations. Mathlib docs · Source

The "header" linter

The "header" style linter checks that a file starts with

/-
Copyright ...
Apache ...
Authors ...
-/

import statements*

module doc-string*

remaining file

It emits a warning if

  • the copyright statement is malformed;
  • Mathlib.Tactic is imported;
  • any import in Lake is present;
  • the first non-import command is not a module doc-string.

The linter allows import-only files and does not require a copyright statement in Mathlib.Init.

Implementation

The linter is a stateful linter whose state is atStart : Bool. It starts out true, and is set to false as soon as a command which is not a header-related set_option is encountered. The header linter ensures that that first command is a module doc-string (unless the linter has been turned off, or the command is exempted for some reason).

def Mathlib.Linter.copyrightHeaderChecks E1 #

String → String → Array (Lean.Syntax × String)

The main function to validate the copyright string. The input is the copyright string, the output is an array of Syntax × String encoding:

  • the Syntax factors are atoms whose ranges are "best guesses" for where the changes should take place; the embedded string is the current text that the linter flagged;
  • the String factor is the linter message.

The linter checks that

  • the first and last line of the copyright are a ("/-", "-/") pair, each on its own line;
  • the first line is begins with Copyright (c) 20 and ends with . All rights reserved.;
  • the second line equals expectedLicense (determined by the linter.style.header.license option, defaults to the Mathlib default);
  • the remainder of the string begins with Authors: , does not end with . and contains no and nor a double space, except possibly after a line break.

opaque Mathlib.Linter.linter.style.header E1 #

Lean.Option Bool

The "header" style linter checks that a file starts with

/-
Copyright ...
Apache ...
Authors ...
-/

import statements*
module doc-string*
remaining file

It emits a warning if

  • the copyright statement is malformed;
  • Mathlib.Tactic is imported;
  • any import in Lake is present;
  • the first non-import command is not a module doc-string.

The linter allows import-only files and does not require a copyright statement in Mathlib.Init.

opaque Mathlib.Linter.linter.style.header.license E1 #

Lean.Option String

The text required by linter.style.header as the second line of the header.

opaque Mathlib.Linter.linter.style.header.imports E1 #

Lean.Option Bool

Whether to reformat import blocks in the module system according to the style convention. Note that this only has an effect if linter.style.header is true and the header is participating in the module system. This does not remove redundant imports.