Skip to content

Commit bc22338

Browse files
committed
Update README/CHANGELOG, use find instead of first+filter
1 parent d56ff99 commit bc22338

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
* [#251](https://github.com/clojure-emacs/refactor-nrepl/pull/251) `clean-ns` support extra message key `relative-path`, which will be used if `path` does not exist.
6+
57
## 2.4.0
68

79
* [#231](https://github.com/clojure-emacs/refactor-nrepl/issues/231) hotload-dependencies temporarily disabled due to java 10 issues.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ The `clean-ns` op will perform the following cleanups on an ns form:
161161
* Use the shorthand version of metadata found if possible, and sort it
162162
alphabetically
163163

164-
The `clean-ns` requires a `path` which is the path to the file containing the `ns` to be operated upon.
164+
The `clean-ns` requires a `path` which must be the absolute path to the file containing the `ns` to be operated upon. A client should also pass in a `relative-path`, which is the path relative to the project root, and which is used as a fallback when the `path` does not exist. (see [clj-refactor.el #380](https://github.com/clojure-emacs/clj-refactor.el/issues/380)).
165165

166166
The return value, `ns` is the entire `(ns ..)` form in prestine condition, or `nil` if nothing was done (so the client doesn't update the timestamp on files when nothing actually needs doing).
167167

src/refactor_nrepl/ns/clean_ns.clj

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,14 @@
3636
(assert-no-exclude-clause (core/get-ns-component ns-form :use))
3737
ns-form)
3838

39+
(defn- find
40+
"Find the first element in coll that satisfies pred?"
41+
[pred? coll]
42+
(reduce (fn [_ x] (when (pred? x) (reduced x))) nil coll))
43+
3944
(defn clean-ns [{:keys [path relative-path]}]
40-
{:pre [(seq path) (string? path)]}
41-
;; Try first the absolute, then the relative path
42-
(let [path (first (filter #(some-> % io/file .exists) [path relative-path]))]
45+
(let [path (find #(and % (.exists (io/file %)))
46+
[path relative-path])]
4347
(assert (core/source-file? path))
4448
;; Prefix notation not supported in cljs.
4549
;; We also turn it off for cljc for reasons of symmetry

0 commit comments

Comments
 (0)