Skip to content

Commit e14d166

Browse files
committed
Review and update API docstrings
- Improve consistency of non-whitespace zip API docstrings (eg. next) with their raw (eg. next*) counterparts - Other clarifications and typo fixes Improving node creation docstrings will be addressed at a later date.
1 parent e063919 commit e14d166

File tree

16 files changed

+87
-76
lines changed

16 files changed

+87
-76
lines changed

src/rewrite_clj/custom_zipper/core.cljc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
parent))))
130130

131131
(defn-switchable root
132-
"Zips all the way up `zloc` and returns zipper at the root node, reflecting any changes."
132+
"Zips all the way up `zloc` and returns the root node, reflecting any changes."
133133
[zloc]
134134
(if (:end? zloc)
135135
(node zloc)
@@ -210,7 +210,9 @@
210210
(assoc zloc :changed? true :node node))
211211

212212
(defn edit
213-
"Returns zipper with value of `(f current-node args)` replacing current node in `zloc`"
213+
"Returns zipper with value of `(apply f current-node args)` replacing current node in `zloc`.
214+
215+
The result of `f` should be a rewrite-clj node."
214216
[zloc f & args]
215217
(if (custom-zipper? zloc)
216218
(replace zloc (apply f (node zloc) args))

src/rewrite_clj/node.cljc

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@
8383
"Return `node` converted to form.
8484
8585
Optional `opts` can specify:
86-
- `:auto-resolve` specify a function to customize namespaced element auto-resolve behavior, see [docs on namespaced elements](/doc/01-user-guide.adoc#namespaced-elements)"
86+
- `:auto-resolve` specify a function to customize namespaced element auto-resolve behavior, see [docs on namespaced elements](/doc/01-user-guide.adoc#namespaced-elements)
87+
88+
See docs for [sexpr nuances](/doc/01-user-guide.adoc#sexpr-nuances)."
8789
([node] (rewrite-clj.node.protocols/sexpr node))
8890
([node opts] (rewrite-clj.node.protocols/sexpr node opts)))
8991

@@ -97,7 +99,9 @@
9799
"Return forms for `nodes`. Nodes that do not represent s-expression are skipped.
98100
99101
Optional `opts` can specify:
100-
- `:auto-resolve` specify a function to customize namespaced element auto-resolve behavior, see [docs on namespaced elements](/doc/01-user-guide.adoc#namespaced-elements)"
102+
- `:auto-resolve` specify a function to customize namespaced element auto-resolve behavior, see [docs on namespaced elements](/doc/01-user-guide.adoc#namespaced-elements)
103+
104+
See docs for [sexpr nuances](/doc/01-user-guide.adoc#sexpr-nuances)."
101105
([nodes] (rewrite-clj.node.protocols/sexprs nodes))
102106
([nodes opts] (rewrite-clj.node.protocols/sexprs nodes opts)))
103107

@@ -160,7 +164,7 @@
160164
161165
`base` defaults to 10.
162166
163-
Note: the parser does not currently parse to integer-nodes, but the write can handle them just fine."
167+
Note: the parser does not currently parse to integer-nodes, but they fully supported for output."
164168
([value] (rewrite-clj.node.integer/integer-node value))
165169
([value base] (rewrite-clj.node.integer/integer-node value base)))
166170

@@ -204,16 +208,16 @@
204208
- `(map-qualifier-node true \"my-ns-alias\")` -> `#::my-ns-alias` - auto-resolved namespace alias
205209
- `(map-qualifier-node true nil)` -> `#::` - auto-resolved current namespace
206210
207-
The above are the only supported variations, use [[rewrite-clj.node/map-node]] for unqualified maps."
211+
The above are the only supported variations, use [[map-node]] for unqualified maps."
208212
[auto-resolved? prefix] (rewrite-clj.node.namespaced-map/map-qualifier-node auto-resolved? prefix))
209213

210214
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.namespaced-map
211215
(defn namespaced-map-node
212216
"Create a namespaced map node with `children`.
213217
214-
- first child must be a map-qualifier node, see [[rewrite-clj.node/map-qualifier-node]]
218+
- first child must be a map-qualifier node, see [[map-qualifier-node]]
215219
- optionally followed by whitespace node(s),
216-
- followed by a map node, see [[rewrite-clj.node/map-node]]"
220+
- followed by a map node, see [[map-node]]"
217221
[children] (rewrite-clj.node.namespaced-map/namespaced-map-node children))
218222

219223
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.regex
@@ -253,7 +257,7 @@
253257

254258
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.seq
255259
(defn map-node
256-
"Create a node representing an map with `children`."
260+
"Create a node representing a map with `children`."
257261
[children] (rewrite-clj.node.seq/map-node children))
258262

259263
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.node.seq

src/rewrite_clj/node/integer.cljc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
4040
`base` defaults to 10.
4141
42-
Note: the parser does not currently parse to integer-nodes, but the write can handle them just fine."
42+
Note: the parser does not currently parse to integer-nodes, but they fully supported for output."
4343
([value]
4444
(integer-node value 10))
4545
([value base]

src/rewrite_clj/node/namespaced_map.cljc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,15 @@
130130
- `(map-qualifier-node true \"my-ns-alias\")` -> `#::my-ns-alias` - auto-resolved namespace alias
131131
- `(map-qualifier-node true nil)` -> `#::` - auto-resolved current namespace
132132
133-
The above are the only supported variations, use [[rewrite-clj.node/map-node]] for unqualified maps."
133+
The above are the only supported variations, use [[map-node]] for unqualified maps."
134134
[auto-resolved? prefix]
135135
(->MapQualifierNode auto-resolved? prefix))
136136

137137
(defn namespaced-map-node
138138
"Create a namespaced map node with `children`.
139139
140-
- first child must be a map-qualifier node, see [[rewrite-clj.node/map-qualifier-node]]
140+
- first child must be a map-qualifier node, see [[map-qualifier-node]]
141141
- optionally followed by whitespace node(s),
142-
- followed by a map node, see [[rewrite-clj.node/map-node]]"
142+
- followed by a map node, see [[map-node]]"
143143
[children]
144144
(->NamespacedMapNode (apply-context children)))

src/rewrite_clj/node/protocols.cljc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,19 @@
4040
"Return `node` converted to form.
4141
4242
Optional `opts` can specify:
43-
- `:auto-resolve` specify a function to customize namespaced element auto-resolve behavior, see [docs on namespaced elements](/doc/01-user-guide.adoc#namespaced-elements)"
43+
- `:auto-resolve` specify a function to customize namespaced element auto-resolve behavior, see [docs on namespaced elements](/doc/01-user-guide.adoc#namespaced-elements)
44+
45+
See docs for [sexpr nuances](/doc/01-user-guide.adoc#sexpr-nuances)."
4446
([node] (sexpr node {}))
4547
([node opts] (sexpr* node opts)))
4648

4749
(defn sexprs
4850
"Return forms for `nodes`. Nodes that do not represent s-expression are skipped.
4951
5052
Optional `opts` can specify:
51-
- `:auto-resolve` specify a function to customize namespaced element auto-resolve behavior, see [docs on namespaced elements](/doc/01-user-guide.adoc#namespaced-elements)"
53+
- `:auto-resolve` specify a function to customize namespaced element auto-resolve behavior, see [docs on namespaced elements](/doc/01-user-guide.adoc#namespaced-elements)
54+
55+
See docs for [sexpr nuances](/doc/01-user-guide.adoc#sexpr-nuances)."
5256
([nodes]
5357
(sexprs nodes {}))
5458
([nodes opts]

src/rewrite_clj/node/seq.cljc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@
5555
(->SeqNode :set "#{%s}" 3 set children))
5656

5757
(defn map-node
58-
"Create a node representing an map with `children`."
58+
"Create a node representing a map with `children`."
5959
[children]
60-
(->SeqNode :map "{%s}" 2 #(apply hash-map %) children))
60+
(->SeqNode :map "{%s}" 2 #(apply hash-map %) children))

src/rewrite_clj/zip.cljc

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@
190190

191191
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.custom-zipper.core
192192
(defn root
193-
"Zips all the way up `zloc` and returns zipper at the root node, reflecting any changes."
193+
"Zips all the way up `zloc` and returns the root node, reflecting any changes."
194194
[zloc] (rewrite-clj.custom-zipper.core/root zloc))
195195

196196
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.zip.base
@@ -241,7 +241,7 @@
241241

242242
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.zip.base
243243
(defn length
244-
"Return length of printable string of current node in `zloc`."
244+
"Return length of printable [[string]] of current node in `zloc`."
245245
[zloc] (rewrite-clj.zip.base/length zloc))
246246

247247
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.zip.base
@@ -306,10 +306,9 @@
306306
(defn edit
307307
"Return `zloc` with the current node replaced with the result of:
308308
309-
(`f` (s-expression node) `args`)
309+
`(apply f (s-expr current-node) args)`
310310
311-
`f` should return a node.
312-
The result of `f` will be coerced to a node if possible.
311+
The result of `f`, if not already a node, will be coerced to a node if possible.
313312
314313
See docs for [sexpr nuances](/doc/01-user-guide.adoc#sexpr-nuances)."
315314
[zloc f & args] (apply rewrite-clj.zip.editz/edit zloc f args))
@@ -366,7 +365,7 @@
366365
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.zip.findz
367366
(defn find-next
368367
"Return `zloc` located to the next node satisfying predicate `p?` else `nil`.
369-
Search starts one movement `f` from the current node continues via `f`.
368+
Search starts one movement `f` from the current node and continues via `f`.
370369
371370
`f` defaults to [[rewrite-clj.zip/right]]"
372371
([zloc p?] (rewrite-clj.zip.findz/find-next zloc p?))
@@ -439,7 +438,7 @@
439438

440439
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.zip.findz
441440
(defn find-next-token
442-
"Return `zloc` location to the next token node satisfying predicate `p?` else `nil`.
441+
"Return `zloc` located to the next token node satisfying predicate `p?` else `nil`.
443442
Search starts one movement `f` after the current node and continues via `f`.
444443
445444
`f` defaults to [[rewrite-clj.zip/right]]"
@@ -463,75 +462,76 @@
463462

464463
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.zip.insert
465464
(defn insert-right
466-
"Return zipper with `item` inserted to the right of the current node in `zloc`.
465+
"Return zipper with `item` inserted to the right of the current node in `zloc`, without moving location.
467466
Will insert a space if necessary."
468467
[zloc item] (rewrite-clj.zip.insert/insert-right zloc item))
469468

470469
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.zip.insert
471470
(defn insert-left
472-
"Return zipper with `item` inserted to the left of the current node in `zloc`.
471+
"Return zipper with `item` inserted to the left of the current node in `zloc`, without moving location.
473472
Will insert a space if necessary."
474473
[zloc item] (rewrite-clj.zip.insert/insert-left zloc item))
475474

476475
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.zip.insert
477476
(defn insert-child
478-
"Return zipper with `item` inserted as the first child of the current node in `zloc`."
477+
"Return zipper with `item` inserted as the first child of the current node in `zloc`, without moving location."
479478
[zloc item] (rewrite-clj.zip.insert/insert-child zloc item))
480479

481480
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.zip.insert
482481
(defn append-child
483-
"Return zipper with `item` appended as last child of the current node in `zloc`.
482+
"Return zipper with `item` inserted as the last child of the current node in `zloc`, without moving.
484483
Will insert a space if necessary."
485484
[zloc item] (rewrite-clj.zip.insert/append-child zloc item))
486485

487486
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.zip.move
488487
(defn left
489-
"Return zipper with location moved left to next non-whitespace/non-comment node in `zloc`."
488+
"Return zipper with location moved left to next non-whitespace/non-comment sibling of current node in `zloc`."
490489
[zloc] (rewrite-clj.zip.move/left zloc))
491490

492491
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.zip.move
493492
(defn right
494-
"Return zipper with location moved right to next non-whitespace/non-comment node in `zloc`."
493+
"Return zipper with location moved right to next non-whitespace/non-comment sibling of current node in `zloc`."
495494
[zloc] (rewrite-clj.zip.move/right zloc))
496495

497496
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.zip.move
498497
(defn up
499-
"Return zipper with location moved up to next non-whitespace/non-comment node in `zloc`."
498+
"Return zipper with location moved up to next non-whitespace/non-comment parent of current node in `zloc`, or `nil` if at the top."
500499
[zloc] (rewrite-clj.zip.move/up zloc))
501500

502501
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.zip.move
503502
(defn down
504-
"Return zipper with location moved down to next non-whitespace/non-comment node in `zloc`."
503+
"Return zipper with location moved down to the first non-whitespace/non-comment child node of the current node in `zloc`, or nil if no applicable children."
505504
[zloc] (rewrite-clj.zip.move/down zloc))
506505

507506
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.zip.move
508507
(defn prev
509-
"Return zipper with location moved to the previous depth-first non-whitespace/non-comment node in `zloc`."
508+
"Return zipper with location moved to the previous depth-first non-whitespace/non-comment node in `zloc`. If already at root, returns nil."
510509
[zloc] (rewrite-clj.zip.move/prev zloc))
511510

512511
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.zip.move
513512
(defn next
514-
"Return zipper with location moved to the next depth-first non-whitespace/non-comment node in `zloc`."
513+
"Return zipper with location moved to the next depth-first non-whitespace/non-comment node in `zloc`.
514+
End can be detected with [[end?]], if already at end, stays there."
515515
[zloc] (rewrite-clj.zip.move/next zloc))
516516

517517
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.zip.move
518518
(defn leftmost
519-
"Return zipper with location moved to the leftmost non-whitespace/non-comment node in `zloc`."
519+
"Return zipper with location moved to the leftmost non-whitespace/non-comment sibling of current node in `zloc`."
520520
[zloc] (rewrite-clj.zip.move/leftmost zloc))
521521

522522
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.zip.move
523523
(defn rightmost
524-
"Return zipper with location moved to the rightmost non-whitespace/non-comment node in `zloc`."
524+
"Return zipper with location moved to the rightmost non-whitespace/non-comment sibling of current node in `zloc`."
525525
[zloc] (rewrite-clj.zip.move/rightmost zloc))
526526

527527
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.zip.move
528528
(defn leftmost?
529-
"Return true if at leftmost non-whitespace/non-comment node in `zloc`."
529+
"Return true if at leftmost non-whitespace/non-comment sibling node in `zloc`."
530530
[zloc] (rewrite-clj.zip.move/leftmost? zloc))
531531

532532
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.zip.move
533533
(defn rightmost?
534-
"Return true if at rightmost non-whitespace/non-comment node in `zloc`."
534+
"Return true if at rightmost non-whitespace/non-comment sibling node in `zloc`."
535535
[zloc] (rewrite-clj.zip.move/rightmost? zloc))
536536

537537
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.zip.move
@@ -743,7 +743,7 @@
743743
- or a valid zipper
744744
WARNING: when function `f` changes the location in the zipper, normal traversal will be affected.
745745
746-
When `p?` is not specified `f` is called all locations.
746+
When `p?` is not specified `f` is called on all locations.
747747
748748
Note that by default a newly created zipper automatically navigates to the first non-whitespace
749749
node. If you want to be sure to walk all forms in a zipper, you'll want to navigate one up prior to your walk:
@@ -785,7 +785,7 @@
785785
- or a valid zipper
786786
WARNING: when function `f` changes the location in the zipper, normal traversal will be affected.
787787
788-
When `p?` is not specified `f` is called all locations.
788+
When `p?` is not specified `f` is called on all locations.
789789
790790
Note that by default a newly created zipper automatically navigates to the first non-whitespace
791791
node. If you want to be sure to walk all forms in a zipper, you'll want to navigate one up prior to your walk:
@@ -836,28 +836,28 @@
836836

837837
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.zip.whitespace
838838
(defn ^{:added "0.5.0"} insert-space-left
839-
"Return zipper with `n` space whitespace node inserted to the left of the current node in `zloc`.
839+
"Return zipper with `n` space whitespace node inserted to the left of the current node in `zloc`, without moving location.
840840
`n` defaults to 1."
841841
([zloc] (rewrite-clj.zip.whitespace/insert-space-left zloc))
842842
([zloc n] (rewrite-clj.zip.whitespace/insert-space-left zloc n)))
843843

844844
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.zip.whitespace
845845
(defn ^{:added "0.5.0"} insert-space-right
846-
"Return zipper with `n` space whitespace node inserted to the right of the current node in `zloc`.
846+
"Return zipper with `n` space whitespace node inserted to the right of the current node in `zloc`, without moving location.
847847
`n` defaults to 1."
848848
([zloc] (rewrite-clj.zip.whitespace/insert-space-right zloc))
849849
([zloc n] (rewrite-clj.zip.whitespace/insert-space-right zloc n)))
850850

851851
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.zip.whitespace
852852
(defn ^{:added "0.5.0"} insert-newline-left
853-
"Return zipper with `n` newlines node inserted to the left of the current node in `zloc`.
853+
"Return zipper with `n` newlines node inserted to the left of the current node in `zloc`, without moving location.
854854
`n` defaults to 1."
855855
([zloc] (rewrite-clj.zip.whitespace/insert-newline-left zloc))
856856
([zloc n] (rewrite-clj.zip.whitespace/insert-newline-left zloc n)))
857857

858858
;; DO NOT EDIT FILE, automatically imported from: rewrite-clj.zip.whitespace
859859
(defn ^{:added "0.5.0"} insert-newline-right
860-
"Return zipper with `n` newlines node inserted to the right of the current node in `zloc`.
860+
"Return zipper with `n` newlines node inserted to the right of the current node in `zloc`, without moving location.
861861
`n` defaults to 1."
862862
([zloc] (rewrite-clj.zip.whitespace/insert-newline-right zloc))
863863
([zloc n] (rewrite-clj.zip.whitespace/insert-newline-right zloc n)))
@@ -989,7 +989,9 @@ NOTE: This function does not skip, nor provide any special handling for whitespa
989989
(defn edit*
990990
"Raw version of [[edit]].
991991
992-
Returns zipper with value of `(f current-node args)` replacing current node in `zloc`
992+
Returns zipper with value of `(apply f current-node args)` replacing current node in `zloc`.
993+
994+
The result of `f` should be a rewrite-clj node.
993995
994996
NOTE: This function does not skip, nor provide any special handling for whitespace/comment nodes."
995997
[zloc f & args] (apply rewrite-clj.custom-zipper.core/edit zloc f args))

src/rewrite_clj/zip/base.cljc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
(some-> zloc zraw/node (node/child-sexprs (get-opts zloc)))))
7878

7979
(defn length
80-
"Return length of printable string of current node in `zloc`."
80+
"Return length of printable [[string]] of current node in `zloc`."
8181
[zloc]
8282
(or (some-> zloc zraw/node node/length) 0))
8383

src/rewrite_clj/zip/edit.clj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818
(defn edit
1919
"Return `zloc` with the current node replaced with the result of:
2020
21-
(`f` (s-expression node) `args`)
21+
`(apply f (s-expr current-node) args)`
2222
23-
`f` should return a node.
24-
The result of `f` will be coerced to a node if possible.
23+
The result of `f`, if not already a node, will be coerced to a node if possible.
2524
2625
See docs for [sexpr nuances](/doc/01-user-guide.adoc#sexpr-nuances)."
2726
[zloc f & args] (apply rewrite-clj.zip.editz/edit zloc f args))

src/rewrite_clj/zip/editz.cljc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@
3131
(defn edit
3232
"Return `zloc` with the current node replaced with the result of:
3333
34-
(`f` (s-expression node) `args`)
34+
`(apply f (s-expr current-node) args)`
3535
36-
`f` should return a node.
37-
The result of `f` will be coerced to a node if possible.
36+
The result of `f`, if not already a node, will be coerced to a node if possible.
3837
3938
See docs for [sexpr nuances](/doc/01-user-guide.adoc#sexpr-nuances)."
4039
[zloc f & args]

0 commit comments

Comments
 (0)