Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Disjoin current ns from candidate namespaces

If a user moves `myvar` from `my.ns.a` to `my.longer.ns.b` then runs
slamhound on `my.ns.a` to refer the var from `my.longer.ns.b`m slamhound
constructs the following ns:

(ns my.ns.a
  (:require [my.ns.a :refer [myvar]]))

This throws a circular dependency error and should be avoided.
  • Loading branch information...
commit 53339e5f9efc0e63e61a7f85c7ce64782477b498 1 parent 1d24464
@guns guns authored
Showing with 11 additions and 9 deletions.
  1. +8 −9 src/slam/hound/regrow.clj
  2. +3 −0  test/slam/hound/regrow_test.clj
View
17 src/slam/hound/regrow.clj
@@ -108,7 +108,7 @@
(defn- filter-excludes
"Disjoin namespace symbols from candidates that match the :exclude, :xrefer,
and :refer values in old-ns-map."
- [candidates type missing old-ns-map]
+ [type missing old-ns-map candidates]
(if (= type :refer)
(let [{:keys [exclude xrefer refer]} old-ns-map
cs (reduce (fn [s [ns syms]]
@@ -172,14 +172,13 @@
[candidates type missing old-ns-map]
;; TODO: prefer things in classes to jars
(debug :disambiguating missing :in candidates)
- (let [cs (filter-excludes candidates type missing old-ns-map)
- cs (remove #(re-find disambiguator-blacklist (str %)) cs)
- cs (sort-by (juxt
- (in-originals-fn type missing old-ns-map)
- (last-segment-matches-fn type missing)
- (is-project-namespace-fn type)
- (comp count str))
- cs)]
+ (let [cs (->> (disj candidates (:name old-ns-map))
+ (filter-excludes type missing old-ns-map)
+ (remove #(re-find disambiguator-blacklist (str %)))
+ (sort-by (juxt (in-originals-fn type missing old-ns-map)
+ (last-segment-matches-fn type missing)
+ (is-project-namespace-fn type)
+ (comp count str))))]
(when-let [c (first cs)]
;; Honor any old [c :refer :all] specs - issue #50
(if (and (= type :refer)
View
3  test/slam/hound/regrow_test.clj
@@ -42,6 +42,9 @@
'#{clojure.set clojure.string korma.core}))))
(deftest ^:unit test-disambiguate
+ (testing "removes namespace matching :name in old-ns-map"
+ (is (= (disambiguate '#{foo bar} :alias 'foo '{:name foo})
+ '[:alias bar])))
(testing "removes candidates matching disambiguator-blacklist"
(is (nil? (disambiguate '#{swank lancet} :alias 'swank {}))))
(testing "removes namespaces with excluded vars"
Please sign in to comment.
Something went wrong with that request. Please try again.