Skip to content

Commit

Permalink
v0.4.6: fix #33
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Nov 25, 2022
1 parent 7854233 commit f9e71ba
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ git
.lein-failures
.cache
.lsp
.nrepl-port
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
[rewrite-clj](https://github.com/clj-commons/rewrite-clj) with common operations
to update EDN while preserving whitespace and comments.

## 0.4.6

- [#33](https://github.com/borkdude/rewrite-edn/issues/33): fix `assoc` on map starting with comment

## 0.4.5

- Add `conj`: `(str (r/update (r/parse-string "{:a [1 2 3]}") :a r/conj 1)) ;;=> "{:a [1 2 3 1]}"` ([@zerg000000](https://github.com/zerg000000))
Expand Down
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject borkdude/rewrite-edn "0.4.5"
(defproject borkdude/rewrite-edn "0.4.6"
:description "Rewrite EDN"
:url "https://github.com/borkdude/rewrite-edn"
:scm {:name "git"
Expand Down
17 changes: 17 additions & 0 deletions script/changelog.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bb

(ns changelog
(:require [clojure.string :as str]))

(let [changelog (slurp "CHANGELOG.md")
replaced (str/replace changelog
#" #(\d+)"
(fn [[_ issue after]]
(format " [#%s](https://github.com/borkdude/rewrite-edn/issues/%s)%s"
issue issue (str after))))
replaced (str/replace replaced
#"@([a-zA-Z0-9-_]+)([, \.)])"
(fn [[_ name after]]
(format "[@%s](https://github.com/%s)%s"
name name after)))]
(spit "CHANGELOG.md" replaced))
3 changes: 1 addition & 2 deletions src/borkdude/rewrite_edn/impl.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@
zloc (if nil?
(z/replace zloc (node/coerce {}))
zloc)
children (:children (z/node zloc))
length (count-uncommented-children zloc)
out-of-bounds? (and (= :vector tag) (>= k length))
empty? (or nil? (zero? (count children)))]
empty? (or nil? (zero? length))]
(cond
empty?
(-> zloc
Expand Down
7 changes: 7 additions & 0 deletions test/borkdude/rewrite_edn_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@
(is (= (str "{:a 2\n"
" :b 3}")
(-> "{}"
r/parse-string
(r/assoc :a 2)
(r/assoc :b 3)
str))))
(testing "Assoc on map with comment"
(is (= "{;;a comment\n :a 2\n :b 3}"
(-> "{;;a comment\n}"
r/parse-string
(r/assoc :a 2)
(r/assoc :b 3)
Expand Down

0 comments on commit f9e71ba

Please sign in to comment.