Skip to content

Commit ee5b5bd

Browse files
author
Yannick Scherer
committed
add guard to 'prepend-space' and 'append-space'.
1 parent 677e81e commit ee5b5bd

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/rewrite_clj/zip/whitespace.clj

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,19 @@
4444
"Prepend a whitespace node representing the given number of spaces (default: 1)."
4545
([zloc] (prepend-space zloc 1))
4646
([zloc n]
47-
(z/insert-left zloc (node/spaces n))))
47+
{:pre [(>= n 0)]}
48+
(if (pos? n)
49+
(z/insert-left zloc (node/spaces n))
50+
zloc)))
4851

4952
(defn append-space
5053
"Append a whitespace node representing the given number of spaces (default: 1)."
5154
([zloc] (append-space zloc 1))
5255
([zloc n]
53-
(z/insert-right zloc (node/spaces n))))
56+
{:pre [(>= n 0)]}
57+
(if (pos? n)
58+
(z/insert-right zloc (node/spaces n))
59+
zloc)))
5460

5561
(defn prepend-newline
5662
"Prepend a whitespace node representing the given number of spaces (default: 1)."

0 commit comments

Comments
 (0)