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.TextBased

17 declarations. Mathlib docs · Source

Text-based linters

This file defines various mathlib linters which are based on reading the source code only. In practice, all such linters check for code style issues.

Currently, this file contains linters checking

  • if the string "adaptation note" is used instead of the command #adaptation_note,
  • for lines with windows line endings,
  • for lines containing trailing whitespace,
  • for module names to be in upper camel case,
  • for module names to be valid Windows filenames, and containing no forbidden characters such as !, . or spaces.
  • for any code containing unicode characters not on the allowlist
  • for incorrect usage of unicode variant selectors

This linter has a file for style exceptions (to avoid false positives in the implementation), or for downstream projects to allow a gradual adoption of this linter.

An executable running all these linters is defined in scripts/lint-style.lean.

Definitions of the actual text-based linters.

def Mathlib.Linter.TextBased.instInhabitedStyleError.default E1 #

Mathlib.Linter.TextBased.StyleError✝

abbrev Mathlib.Linter.TextBased.ErrorFormat.ctorElimType E1 #

{motive : Mathlib.Linter.TextBased.ErrorFormat → Sort u} → ℕ → Sort (max 1 u)

def Mathlib.Linter.TextBased.ErrorFormat.ctorIdx E1 #

Mathlib.Linter.TextBased.ErrorFormat → ℕ

inductive Mathlib.Linter.TextBased.ErrorFormat E1 #

Type

How to format style errors

ctor Mathlib.Linter.TextBased.ErrorFormat.humanReadable E0 #

Mathlib.Linter.TextBased.ErrorFormat

Produce style error output aimed at humans: no error code, clickable file name

ctor Mathlib.Linter.TextBased.ErrorFormat.exceptionsFile E0 #

Mathlib.Linter.TextBased.ErrorFormat

Produce an entry in the style-exceptions file: mention the error code, slightly uglier than human-readable output

ctor Mathlib.Linter.TextBased.ErrorFormat.github E0 #

Mathlib.Linter.TextBased.ErrorFormat

Produce output suitable for Github error annotations: in particular, duplicate the file path, line number and error code

def Mathlib.Linter.TextBased.instBEqErrorFormat.beq E1 #

Mathlib.Linter.TextBased.ErrorFormat → Mathlib.Linter.TextBased.ErrorFormat → Bool

instance Mathlib.Linter.TextBased.instBEqErrorFormat E0 #

BEq Mathlib.Linter.TextBased.ErrorFormat

opaque Mathlib.Linter.TextBased.linter.adaptationNote E1 #

Lean.Option Bool

Lint on any occurrences of the string "Adaptation note:" or variants thereof.

opaque Mathlib.Linter.TextBased.linter.whitespaceBeforeSemicolon E1 #

Lean.Option Bool

Lint a collection of input strings for a semicolon preceded by a space.

opaque Mathlib.Linter.TextBased.linter.unicodeLinter E1 #

Lean.Option Bool

Lint a collection of input strings for disallowed unicode characters.

This is implemented using an allowlist, see Mathlib.Linter.TextBased.UnicodeLinter.isAllowedCharacter.

def Mathlib.Linter.TextBased.lintModules E1 #

Lean.Linter.LinterOptions → Array String → Array Lean.Name → Mathlib.Linter.TextBased.ErrorFormat → Bool → IO UInt32

Lint a collection of modules for style violations. Print formatted errors for all unexpected style violations to standard output; correct automatically fixable style errors if configured so. Return the number of files which had new style errors. opts contains the options defined in the Lakefile, determining which linters to enable. nolints is a list of style exceptions to take into account. moduleNames are the names of all the modules to lint, mode specifies what kind of output this script should produce, fix configures whether fixable errors should be corrected in-place.

opaque Mathlib.Linter.TextBased.linter.modulesUpperCamelCase E1 #

Lean.Option Bool

Verify that all modules are named in UpperCamelCase

def Mathlib.Linter.TextBased.modulesNotUpperCamelCase E1 #

Lean.Linter.LinterOptions → Array Lean.Name → IO ℕ

Verifies that all modules in modules are named in UpperCamelCase (except for explicitly discussed exceptions, which are hard-coded here). Return the number of modules violating this.

opaque Mathlib.Linter.TextBased.linter.modulesForbiddenWindows E1 #

Lean.Option Bool

Verify that no module name is forbidden according to Windows' filename rules.

def Mathlib.Linter.TextBased.modulesOSForbidden E1 #

Lean.Linter.LinterOptions → Array Lean.Name → IO ℕ

Verifies that no module in modules contains CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, COM¹, COM², COM³, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, LPT9, LPT¹, LPT² or LPT³ in its filename, as these are forbidden on Windows.

Also verify that module names contain no forbidden characters such as *, ? (Windows), ! (forbidden on Nix OS), . (might result from confusion with a module name) or ' (causes shell escaping issues in scripts).

Source: https://learn.microsoft.com/en-gb/windows/win32/fileio/naming-a-file. Return the number of module names violating this rule.