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 2
2
3
3
## Unreleased
4
4
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
+
5
7
## 3.5.4
6
8
7
9
* [ #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 1
1
(ns refactor-nrepl.ns.suggest-aliases
2
2
" Suggestion of aliases based on these guidelines: https://stuartsierra.com/2015/05/10/clojure-namespace-aliases"
3
3
(:require
4
+ [clojure.edn :as edn]
4
5
[clojure.string :as string]))
5
6
6
7
(defn test-like-ns-name? [ns-sym]
12
13
(string/starts-with? last-fragment " test-" )
13
14
(some #{" test" " unit" " integration" " acceptance" " functional" " generative" } fragments)))))))
14
15
16
+ (def readable-as-symbol?
17
+ (memoize
18
+ (fn [s]
19
+ (try
20
+ (symbol? (edn/read-string s))
21
+ (catch Exception _
22
+ false )))))
23
+
15
24
(defn suggested-aliases [namespace-name]
16
25
(let [fragments (-> namespace-name str (string/split #"\. " ))
17
26
fragments (into []
29
38
(range 1 (inc (count fragments)))
30
39
(repeat (distinct fragments)))
31
40
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]]))))
35
46
fragments)]
36
47
(dissoc v namespace-name)))
Original file line number Diff line number Diff line change 21
21
'unit.foo true
22
22
'foo.unit true ))
23
23
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
+
24
43
(deftest suggested-aliases
25
44
(are [desc input expected] (testing input
26
45
(is (= expected
46
65
" Removes redundant bits such as `clj-` and `.core`"
47
66
'clj-a.b.c.core '{c [clj-a.b.c.core]
48
67
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