File tree Expand file tree Collapse file tree 3 files changed +39
-4
lines changed Expand file tree Collapse file tree 3 files changed +39
-4
lines changed Original file line number Diff line number Diff line change 22
33## Unreleased
44
5+ * [ #385 ] ( https://github.com/clojure-emacs/refactor-nrepl/pull/385 ) : Fix cljr-refactor.el's ` cljr-slash ` when namespace fragments start with a number.
6+
57## 3.5.4
68
79* [ #383 ] ( https://github.com/clojure-emacs/refactor-nrepl/issues/383 ) : ` prune-dependencies ` : increase accuracy for ` :cljs ` .
Original file line number Diff line number Diff line change 11(ns refactor-nrepl.ns.suggest-aliases
22 " Suggestion of aliases based on these guidelines: https://stuartsierra.com/2015/05/10/clojure-namespace-aliases"
33 (:require
4+ [clojure.edn :as edn]
45 [clojure.string :as string]))
56
67(defn test-like-ns-name? [ns-sym]
1213 (string/starts-with? last-fragment " test-" )
1314 (some #{" test" " unit" " integration" " acceptance" " functional" " generative" } fragments)))))))
1415
16+ (def readable-as-symbol?
17+ (memoize
18+ (fn [s]
19+ (try
20+ (symbol? (edn/read-string s))
21+ (catch Exception _
22+ false )))))
23+
1524(defn suggested-aliases [namespace-name]
1625 (let [fragments (-> namespace-name str (string/split #"\. " ))
1726 fragments (into []
2938 (range 1 (inc (count fragments)))
3039 (repeat (distinct fragments)))
3140 v (into {}
32- (map (fn [segments]
33- [(->> segments (string/join " ." ) (symbol )),
34- [namespace-name]]))
41+ (keep (fn [segments]
42+ (let [candidate (->> segments (string/join " ." ))]
43+ (when (readable-as-symbol? candidate)
44+ [(symbol candidate),
45+ [namespace-name]]))))
3546 fragments)]
3647 (dissoc v namespace-name)))
Original file line number Diff line number Diff line change 2121 'unit.foo true
2222 'foo.unit true ))
2323
24+ (deftest readable-as-symbol?
25+ (testing " is readable as symbol"
26+ (are [input] (sut/readable-as-symbol? input)
27+ " test"
28+ " a.test"
29+ " a-test"
30+ " b.a-test"
31+ " ok.5<-here"
32+ " this:too!#$%&*" ))
33+
34+ (testing " not readable as symbol"
35+ (are [input] (not (sut/readable-as-symbol? input))
36+ " :kw"
37+ " 15"
38+ " 5-bad"
39+ " 6:nope"
40+ " ;what"
41+ " #yeah" )))
42+
2443(deftest suggested-aliases
2544 (are [desc input expected] (testing input
2645 (is (= expected
4665 " Removes redundant bits such as `clj-` and `.core`"
4766 'clj-a.b.c.core '{c [clj-a.b.c.core]
4867 b.c [clj-a.b.c.core]
49- a.b.c [clj-a.b.c.core]}))
68+ a.b.c [clj-a.b.c.core]}
69+
70+ " Removes fragments that start with a number (in this case: `9d`, `8b.c.9d`), since they aren't valid symbols"
71+ 'a.8b.c.9d '{c.9d [a.8b.c.9d]}))
You can’t perform that action at this time.
0 commit comments