Skip to content

Commit 6315889

Browse files
Merge pull request #196 from naiquevin/pr-ignore-paths
Add config for ignoring specific paths
2 parents d290bc4 + 067054d commit 6315889

File tree

5 files changed

+49
-3
lines changed

5 files changed

+49
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
### New features
2020

2121
* New config setting `:libspec-whitelist` which makes it possible to create a seq of namespaces `clean-ns` shouldn't prune. This is useful for libspecs which aren't used except through side-effecting loads.
22+
* New config setting `:ignore-paths` for ignoring certain paths when finding dirs on classpath.
2223

2324
## 2.2.0
2425

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ Configuration settings are passed along with each msg, currently the recognized
8585
;; This seq of strings will be used as regexp patterns to match
8686
;; against the libspec name.
8787
:libspec-whitelist ["^cljsjs"]
88+
89+
;; Regexes matching paths that are to be ignored
90+
:ignore-paths []
8891
}
8992
```
9093

src/refactor_nrepl/config.clj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
;; This seq of strings will be used as regexp patterns to match
2222
;; against the libspec name.
2323
:libspec-whitelist ["^cljsjs"]
24+
25+
;; Regexes matching paths that are to be ignored
26+
:ignore-paths []
2427
})
2528

2629
(defn opts-from-msg [msg]

src/refactor_nrepl/core.clj

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
[clojure.tools.reader.reader-types :as readers]
77
[me.raynes.fs :as fs]
88
[refactor-nrepl.util :refer [normalize-to-unix-path]]
9-
[refactor-nrepl.s-expressions :as sexp])
9+
[refactor-nrepl.s-expressions :as sexp]
10+
[refactor-nrepl.config :as config])
1011
(:import [java.io File FileReader PushbackReader StringReader]))
1112

1213
(defn version []
@@ -30,13 +31,23 @@
3031
[readable]
3132
(-> readable slurp ns-from-string))
3233

34+
(defn ignore-dir-on-classpath?
35+
[^String path]
36+
(or (.endsWith path "target/srcdeps")
37+
(reduce (fn [acc x]
38+
(if (re-find x path)
39+
(reduced true)
40+
acc))
41+
false
42+
(:ignore-paths config/*config*))))
43+
3344
(defn dirs-on-classpath
3445
"Return all dirs on classpath, filtering out our inlined deps
35-
directory."
46+
directory and paths matching :ignore-paths specified in config."
3647
[]
3748
(->> (cp/classpath)
3849
(filter fs/directory?)
39-
(remove #(-> % str normalize-to-unix-path (.endsWith "target/srcdeps")))))
50+
(remove #(-> % str normalize-to-unix-path ignore-dir-on-classpath?))))
4051

4152
(defn project-root
4253
"Return the project root directory.

test/refactor_nrepl/core_test.clj

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
(ns refactor-nrepl.core-test
2+
(:require [clojure.test :refer :all]
3+
[refactor-nrepl.config :as config]
4+
[refactor-nrepl.core :refer [ignore-dir-on-classpath?]]))
5+
6+
7+
(defmacro assert-ignored-paths
8+
[paths pred]
9+
`(doseq [p# ~paths]
10+
(is (~pred (ignore-dir-on-classpath? p#)))))
11+
12+
13+
(deftest test-ignore-dir-on-classpath?
14+
(let [not-ignored ["/home/user/project/test"
15+
"/home/user/project/src"
16+
"/home/user/project/target/classes"]
17+
sometimes-ignored ["/home/user/project/checkouts/subproject"
18+
"/home/user/project/resources"]
19+
always-ignored ["/home/user/project/target/srcdeps"]]
20+
(testing "predicate to ignore dirs on classpath with default config"
21+
(assert-ignored-paths (concat not-ignored sometimes-ignored) false?)
22+
(assert-ignored-paths always-ignored true?))
23+
(testing "predicate to ignore dirs on classpath with custom config"
24+
(binding [config/*config* (assoc config/*config*
25+
:ignore-paths
26+
[#".+checkouts/.+" #"resources"])]
27+
(assert-ignored-paths not-ignored false?)
28+
(assert-ignored-paths (concat always-ignored sometimes-ignored) true?)))))

0 commit comments

Comments
 (0)