Style linters #
This file contain linters about stylistic aspects: these are only about coding style,
but do not affect correctness nor global coherence of mathlib.
Historically, some of these were ported from the lint-style.py Python script.
This file defines the following linters:
- the
set_optionlinter checks for the presence ofset_optioncommands activating options disallowed in mathlib: these are meant to be temporary, and not for polished code - the
missingEndlinter checks for sections or namespaces which are not closed by the end of the file: enforcing this invariant makes minimising files or moving code between files easier - the
cdotLinterlinter checks for focusing dots·which are typed using a.instead: this is allowed Lean syntax, but it is nicer to be uniform - the
dollarSyntaxlinter checks for use of the dollar sign$instead of the<|pipe operator: similarly, both symbols have the same meaning, but mathlib prefers<|for the symmetry with the|>symbol - the
lambdaSyntaxlinter checks for uses of theλsymbol for ananomous functions, instead of thefunkeyword: mathlib prefers the latter for reasons of readability (This linter is still under review in PR #15896.) - the
longLinelinter checks for lines which have more than 100 characters - the
longFilelinter checks for files which have more than 1500 lines: this linter is still under development in PR #15610.
All of these linters are enabled in mathlib by default, but disabled globally since they enforce conventions which are inherently subjective.
The setOption linter emits a warning on a set_option command, term or tactic
which sets a pp, profiler or trace option.
Whether a syntax element is a set_option command, tactic or term:
Return the name of the option being set, if any.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Deprecated alias for Mathlib.Linter.Style.setOption.parseSetOption.
Equations
Instances For
Whether a given piece of syntax is a set_option command, tactic or term.
Equations
- Mathlib.Linter.Style.setOption.isSetOption stx = match Mathlib.Linter.Style.setOption.parseSetOption stx with | some _name => true | x => false
Instances For
Deprecated alias for Mathlib.Linter.Style.setOption.isSetOption.
Instances For
The setOption linter: this lints any set_option command, term or tactic
which sets a pp, profiler or trace option.
Why is this bad? These options are good for debugging, but should not be used in production code. How to fix this? Remove these options: usually, they are not necessary for production code. (Some tests will intentionally use one of these options; in this case, simply allow the linter.)
Equations
- One or more equations did not get rendered due to their size.
Instances For
The "missing end" linter #
The "missing end" linter emits a warning on non-closed sections and namespaces.
It allows the "outermost" noncomputable section to be left open (whether or not it is named).
The "missing end" linter emits a warning on non-closed sections and namespaces.
It allows the "outermost" noncomputable section to be left open (whether or not it is named).
The "missing end" linter emits a warning on non-closed sections and namespaces.
It allows the "outermost" noncomputable section to be left open (whether or not it is named).
Equations
- One or more equations did not get rendered due to their size.
Instances For
The cdot linter #
The cdot linter is a syntax-linter that flags uses of the "cdot" · that are achieved
by typing a character different from ·.
For instance, a "plain" dot . is allowed syntax, but is flagged by the linter.
It also flags "isolated cdots", i.e. when the · is on its own line.
The cdot linter flags uses of the "cdot" · that are achieved by typing a character
different from ·.
For instance, a "plain" dot . is allowed syntax, but is flagged by the linter.
It also flags "isolated cdots", i.e. when the · is on its own line.
findCDot stx extracts from stx the syntax nodes of kind Lean.Parser.Term.cdot or cdotTk.
unwanted_cdot stx returns an array of syntax atoms within stx
corresponding to cdots that are not written with the character ·.
This is precisely what the cdot linter flags.
Equations
- Mathlib.Linter.unwanted_cdot stx = Array.filter (fun (x : Lean.Syntax) => !Mathlib.Linter.isCDot? x) (Mathlib.Linter.findCDot stx)
Instances For
The cdot linter flags uses of the "cdot" · that are achieved by typing a character
different from ·.
For instance, a "plain" dot . is allowed syntax, but is flagged by the linter.
It also flags "isolated cdots", i.e. when the · is on its own line.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The dollarSyntax linter #
The dollarSyntax linter flags uses of <| that are achieved by typing $.
These are disallowed by the mathlib style guide, as using <| pairs better with |>.
The dollarSyntax linter flags uses of <| that are achieved by typing $.
These are disallowed by the mathlib style guide, as using <| pairs better with |>.
findDollarSyntax stx extracts from stx the syntax nodes of kind $.
The dollarSyntax linter flags uses of <| that are achieved by typing $.
These are disallowed by the mathlib style guide, as using <| pairs better with |>.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The lambdaSyntax linter #
The lambdaSyntax linter is a syntax linter that flags uses of the symbol λ to define anonymous
functions, as opposed to the fun keyword. These are syntactically equivalent; mathlib style
prefers the latter as it is considered more readable.
The lambdaSyntax linter flags uses of the symbol λ to define anonymous functions.
This is syntactically equivalent to the fun keyword; mathlib style prefers using the latter.
findLambdaSyntax stx extracts from stx all syntax nodes of kind Term.fun.
The lambdaSyntax linter flags uses of the symbol λ to define anonymous functions.
This is syntactically equivalent to the fun keyword; mathlib style prefers using the latter.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The "longFile" linter #
The "longFile" linter emits a warning on files which are longer than a certain number of lines (1500 by default).
The "longFile" linter emits a warning on files which are longer than a certain number of lines
(linter.style.longFileDefValue by default on mathlib, no limit for downstream projects).
If this option is set to N lines, the linter warns once a file has more than N lines.
A value of 0 silences the linter entirely.
The number of lines that the longFile linter considers the default.
The "longFile" linter emits a warning on files which are longer than a certain number of lines
(linter.style.longFileDefValue by default on mathlib, no limit for downstream projects).
If this option is set to N lines, the linter warns once a file has more than N lines.
A value of 0 silences the linter entirely.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The "longLine linter" #
The "longLine" linter emits a warning on lines longer than 100 characters. We allow lines containing URLs to be longer, though.
The "longLine" linter emits a warning on lines longer than 100 characters. We allow lines containing URLs to be longer, though.
Equations
- One or more equations did not get rendered due to their size.