Skip to content

Commit ca33caf

Browse files
Do not trigger warning if there is whitespace after ;;
OCaml toplevel ignores trailing whitespace so it would make sense to just ignore it in MDX as well. Unfortunately Astring does not have `rtrim` so both prefix and suffix are removed, but except for additional useless computation load it doesn't make a difference since we only check for the suffix.
1 parent 0826e37 commit ca33caf

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

lib/deprecated.ml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@ let warn ?replacement s ~since =
2727
module Missing_double_semicolon = struct
2828
let missing_semicolon = ref false
2929

30-
let check_toplevel : Toplevel.t -> unit = function
31-
| toplevel -> (
32-
match List.rev toplevel.command with
33-
| cmd :: _ when not @@ Astring.String.is_suffix ~affix:";;" cmd ->
34-
missing_semicolon := true
35-
| _ -> ())
30+
let check_toplevel : Toplevel.t -> unit =
31+
fun toplevel ->
32+
match List.rev toplevel.command with
33+
| cmd :: _ ->
34+
let ends_with_semi =
35+
cmd |> Astring.String.trim |> Astring.String.is_suffix ~affix:";;"
36+
in
37+
if not ends_with_semi then missing_semicolon := true
38+
| [] -> ()
3639

3740
let check_block block = List.iter check_toplevel block
3841

test/bin/mdx-test/expect/trailing-whitespaces/test-case.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,13 @@ val x : int = 13
99
$ echo "bob "
1010
bob
1111
```
12+
13+
Also, it should be valid to terminate phrases that end with `;;` but have
14+
trailing whitespace:
15+
16+
```ocaml
17+
# let terminated_with_space = 42;;
18+
val terminated_with_space : int = 42
19+
# let terminated_with_tab = 42;;
20+
val terminated_with_tab : int = 42
21+
```

test/bin/mdx-test/expect/trailing-whitespaces/test-case.md.expected

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,13 @@ val x : int = 13
99
$ echo "bob "
1010
bob
1111
```
12+
13+
Also, it should be valid to terminate phrases that end with `;;` but have
14+
trailing whitespace:
15+
16+
```ocaml
17+
# let terminated_with_space = 42;;
18+
val terminated_with_space : int = 42
19+
# let terminated_with_tab = 42;;
20+
val terminated_with_tab : int = 42
21+
```

0 commit comments

Comments
 (0)