Skip to content

Commit d8630ef

Browse files
committed
chore(Tactic/Linter): unicode linter documentation improvements (#38019)
As planned in #36773, we add a link to the style guide, which was updated at leanprover-community/leanprover-community.github.io#820. Further changes: - some more documentation updates (some obsolete comments were talking about a "blocklist" which no longer exists) - change order of checks in `isAllowedCharacter`. The new order is more logical and may slightly improve performance (which probably doesn't matter) since Mathlib has more characters in `otherInMathlib` than `emojis`.
1 parent 5c6d8c4 commit d8630ef

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

Mathlib/Tactic/Linter/TextBased.lean

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ Currently, this file contains linters checking
3232
- for module names to be in upper camel case,
3333
- for module names to be valid Windows filenames, and containing no forbidden characters such as
3434
`!`, `.` or spaces.
35-
- for any code containing blocklisted unicode characters
36-
- bad unicode characters
35+
- for any code containing unicode characters not on the allowlist
36+
- for incorrect usage of unicode variant selectors
3737
3838
For historic reasons, some further such checks are written in a Python script `lint-style.py`:
3939
these are gradually being rewritten in Lean.
@@ -394,7 +394,10 @@ def findBadUnicode (s : String) : Array StyleError :=
394394

395395
end UnicodeLinter
396396

397-
/-- Lint a collection of input strings for disallowed unicode characters. -/
397+
/-- Lint a collection of input strings for disallowed unicode characters.
398+
399+
This is implemented using an allowlist, see
400+
`Mathlib.Linter.TextBased.UnicodeLinter.isAllowedCharacter`. -/
398401
public register_option linter.unicodeLinter : Bool := { defValue := true }
399402

400403
@[inherit_doc linter.unicodeLinter]

Mathlib/Tactic/Linter/TextBased/UnicodeLinter.lean

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import Mathlib.Init
1414
1515
The actual linter is defined in `TextBased.lean`.
1616
17-
This file defines the blocklist and other tools used by the linter.
17+
This file defines the allowlist and other tools used by the linter.
18+
19+
**When changing, make sure to stay in sync with [style guide](https://github.com/leanprover-community/leanprover-community.github.io/blob/lean4/templates/contribute/style.md#unicode-usage)**
1820
1921
-/
2022

@@ -184,20 +186,26 @@ public def emojis : Array Char := #[
184186
/-- Unicode symbols in mathlib that should always be followed by the text variant selector. -/
185187
public def nonEmojis : Array Char := #[]
186188

187-
/-- Blocklist: If `false`, the character is not allowed in Mathlib.
189+
/-- If `false`, the character is not allowed in Mathlib.
190+
191+
Implemented using an allowlist consisting of:
192+
- certain ASCII characters
193+
- characters with abbreviations in the VSCode extension (`withVSCodeAbbrev`)
194+
- "the rest" (`othersInMathlib`)
195+
188196
Note: if `true`, a character might still not be allowed depending on context
189197
(e.g. misplaced variant selectors).
190198
-/
191199
public def isAllowedCharacter (c : Char) : Bool :=
192200
ASCII.allowed c
193201
|| withVSCodeAbbrev.contains c
202+
|| othersInMathlib.contains c
194203
|| emojis.contains c
195204
|| nonEmojis.contains c
196205
|| c == UnicodeVariant.emoji
197206
|| c == UnicodeVariant.text
198-
|| othersInMathlib.contains c
199207

200-
/-- Provide default replacement (`String`) for a blocklisted character, or `none` if none defined -/
208+
/-- Provide default replacement (`String`) for a disallowed character, or `none` if none defined -/
201209
public def replaceDisallowed : Char → Option String
202210
| '\u0009' => " " -- "TAB" => "2 spaces"
203211
| '\u000B' => "\n" -- "LINE TABULATION" => "Line Feed"

0 commit comments

Comments
 (0)