Permalink
Browse files

use *config* to specify users' style preferences, for example `:group…

…-imports-by-package`
  • Loading branch information...
1 parent 79a1c9b commit 63a3a61ecf1b456d862b9a47daaddb96e26362b7 Alex Baranosky committed Dec 24, 2012
Showing with 27 additions and 10 deletions.
  1. +6 −2 src/slam/hound/stitch.clj
  2. +21 −8 test/slam/hound/stitch_test.clj
@@ -1,5 +1,7 @@
(ns slam.hound.stitch
- (:use [slam.hound.prettify :only [prettify]]))
+ (:require [slam.hound.config :refer [*config*]]
+ [slam.hound.prettify :refer [prettify]]))
+
(def ^:private ns-map-clauses [:require-as :require-refer :import])
@@ -22,7 +24,9 @@
(defn collapse-clause [ns-map clause]
(case clause
:require-refer (update-in ns-map [:require-refer] group-by-namespace)
- :import (update-in ns-map [:import] group-by-package)
+ :import (if (:group-imports-by-package *config*)
+ (update-in ns-map [:import] group-by-package)
+ ns-map)
:require-as ns-map))
(defn- collapse-clauses [ns-map]
@@ -1,5 +1,6 @@
(ns slam.hound.stitch-test
- (:require [clojure.test :refer [deftest is]]
+ (:require [clojure.test :refer [deftest is testing]]
+ [slam.hound.config :refer [*config*]]
[slam.hound.stitch :refer [ns-from-map stitch-up sort-subclauses collapse-clause]]))
(def sample-ns-form '(ns slamhound.sample
@@ -42,13 +43,25 @@
(sort-subclauses sample-ns-map))))
(deftest ^:unit test-collapse-import
- (is (= {:import '[(clojure.lang Compiler$BodyExpr)
- (java.io ByteArrayInputStream File)
- (java.util UUID)]}
- (collapse-clause {:import '(clojure.lang.Compiler$BodyExpr
- java.io.ByteArrayInputStream
- java.io.File java.util.UUID)}
- :import))))
+ (testing "defaults to grouping imports by package"
+ (is (= {:import '[(clojure.lang Compiler$BodyExpr)
+ (java.io ByteArrayInputStream File)
+ (java.util UUID)]}
+ (collapse-clause {:import '(clojure.lang.Compiler$BodyExpr
+ java.io.ByteArrayInputStream
+ java.io.File java.util.UUID)}
+ :import))))
+
+ (testing "you can turn off grouping by package"
+ (is (= {:import '[clojure.lang.Compiler$BodyExpr
+ java.io.ByteArrayInputStream
+ java.io.File
+ java.util.UUID]}
+ (binding [*config* (assoc *config* :group-imports-by-package false)]
+ (collapse-clause {:import '(clojure.lang.Compiler$BodyExpr
+ java.io.ByteArrayInputStream
+ java.io.File java.util.UUID)}
+ :import))))))
(deftest ^:unit test-collapse-use
(is (= {:require-refer '[[clojure.test :refer [deftest is]]

0 comments on commit 63a3a61

Please sign in to comment.