Skip to content

Commit 70bc711

Browse files
thorimurb-mehta
authored andcommitted
feat: unrestricted character set in unicode linter (leanprover-community#39796)
This PR creates the `unrestricted` array in the unicode linter, which contains characters that have no restrictions on which selector they are followed by, and are not enforced to be followed by any selector at all. We include `'⚠'` in it to allow `⚠️`. We don't want to ban the text version (`⚠`), as this is used in lake output (without the text selector) and so may conceivably be mentioned in a comment. We plan to use `⚠️` in leanprover-community#38126.
1 parent 2cd2b16 commit 70bc711

3 files changed

Lines changed: 23 additions & 4 deletions

File tree

Mathlib/Tactic/Linter/TextBased.lean

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,13 @@ def findBadUnicodeAux (s : String) (pos : s.Pos) (c : Char)
361361
if ! isAllowedCharacter c then
362362
-- bad: character not allowed.
363363
findBadUnicodeAux s posₙ cₙ (err.push (.unwantedUnicode c))
364-
else if cₙ == UnicodeVariant.emoji && !(emojis.contains c) then
364+
else if cₙ == UnicodeVariant.emoji && !(emojis.contains c) && !(unrestricted.contains c) then
365365
-- bad: unwanted emoji variant selector.
366366
let errₙ := err.push (.unicodeVariant (String.ofList [c, cₙ]) none)
367367
findBadUnicodeAux s posₙ cₙ errₙ
368-
else if cₙ == UnicodeVariant.text && !(nonEmojis.contains c) then
368+
else if
369+
cₙ == UnicodeVariant.text && !(nonEmojis.contains c) && !(unrestricted.contains c)
370+
then
369371
-- bad: unwanted text variant selector.
370372
let errₙ := err.push (.unicodeVariant (String.ofList [c, cₙ]) none)
371373
findBadUnicodeAux s posₙ cₙ errₙ

Mathlib/Tactic/Linter/TextBased/UnicodeLinter.lean

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,19 @@ public def emojis : Array Char := #[
186186
/-- Unicode symbols in mathlib that should always be followed by the text variant selector. -/
187187
public def nonEmojis : Array Char := #[]
188188

189+
/-- Unicode symbols in mathlib that have no restrictions on whether they are followed by a selector
190+
or which selector they are followed by. -/
191+
public def unrestricted : Array Char := #[
192+
'⚠' -- ⚠️, ⚠. Lake output uses '⚠' and does not include the text selector.
193+
]
194+
189195
/-- If `false`, the character is not allowed in Mathlib.
190196
191197
Implemented using an allowlist consisting of:
192198
- certain ASCII characters
199+
- certain emojis (`emojis`)
200+
- certain non-emoji variants of emojifiable characters (`nonEmojis`)
201+
- certain characters with no selector restrictions (`unrestricted`)
193202
- characters with abbreviations in the VSCode extension (`withVSCodeAbbrev`)
194203
- "the rest" (`othersInMathlib`)
195204
@@ -202,6 +211,7 @@ public def isAllowedCharacter (c : Char) : Bool :=
202211
|| othersInMathlib.contains c
203212
|| emojis.contains c
204213
|| nonEmojis.contains c
214+
|| unrestricted.contains c
205215
|| c == UnicodeVariant.emoji
206216
|| c == UnicodeVariant.text
207217

MathlibTest/Linter/TextBased.lean

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,14 +665,21 @@ open Mathlib.Linter.TextBased.UnicodeLinter
665665
/- A character either does or doesn't have an abbreviation in the VSCode extension. -/
666666
#guard withVSCodeAbbrev.toList ∩ othersInMathlib.toList = ∅
667667

668-
/- A character either is or isn't an emoji. -/
668+
/- No character is both an emoji and not an emoji. -/
669669
#guard emojis.toList ∩ nonEmojis.toList = ∅
670670

671+
/- No character is both an emoji and unrestricted. -/
672+
#guard emojis.toList ∩ unrestricted.toList = ∅
673+
674+
/- No character is both a non-emoji and unrestricted. -/
675+
#guard nonEmojis.toList ∩ unrestricted.toList = ∅
676+
671677
def allLinterDefinedCharacterLists : List (List Char) := [
672678
withVSCodeAbbrev,
673679
othersInMathlib,
674680
emojis,
675-
nonEmojis
681+
nonEmojis,
682+
unrestricted
676683
].map Array.toList
677684

678685
/- Ensure none of the lists contain duplicates -/

0 commit comments

Comments
 (0)