Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,14 @@ workflows:
# name: Java 11, Clojure master
# clojure_version: "master"
# jdk_version: openjdk11
# - util_job:
# name: Code Linting
# steps:
# - run:
# name: Running Eastwood
# command: |
# make eastwood
# - run:
# name: Running cljfmt
# command: |
# make cljfmt
- util_job:
name: Code Linting
steps:
# - run:
# name: Running Eastwood
# command: |
# make eastwood
- run:
name: Running cljfmt
command: |
make cljfmt
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ source-deps: .source-deps
test: .source-deps
lein with-profile +$(VERSION),+plugin.mranderson/config test

cljfmt:
lein with-profile +$(VERSION),+cljfmt cljfmt check

# When releasing, the BUMP variable controls which field in the
# version string will be incremented in the *next* snapshot
Expand Down
11 changes: 10 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,14 @@
:java-source-paths ["test/java"]
:resource-paths ["test/resources"
"test/resources/testproject/src"]
:repositories [["snapshots" "https://oss.sonatype.org/content/repositories/snapshots"]]}}
:repositories [["snapshots" "https://oss.sonatype.org/content/repositories/snapshots"]]}
:cljfmt [:test
{:plugins [[lein-cljfmt "0.6.4"]]
:cljfmt {:indents {as-> [[:inner 0]]
as->* [[:inner 0]]
cond-> [[:inner 0]]
cond->* [[:inner 0]]
with-debug-bindings [[:inner 0]]
merge-meta [[:inner 0]]
try-if-let [[:block 1]]}}}]}
:jvm-opts ["-Djava.net.preferIPv4Stack=true"])
6 changes: 2 additions & 4 deletions src/refactor_nrepl/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

;; NOTE: Update the readme whenever this map is changed
(def ^:dynamic *config*
{
;; Verbose setting for debugging. The biggest effect this has is
{;; Verbose setting for debugging. The biggest effect this has is
;; to not catch any exceptions to provide meaningful error
;; messages for the client.

Expand All @@ -23,8 +22,7 @@
:libspec-whitelist ["^cljsjs"]

;; Regexes matching paths that are to be ignored
:ignore-paths []
})
:ignore-paths []})

(defn opts-from-msg [msg]
(into {}
Expand Down
16 changes: 8 additions & 8 deletions src/refactor_nrepl/find/find_macros.clj
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,21 @@
macro-suffix (core/suffix macro-name)
alias? ((get-ns-aliases libspecs) macro-prefix)]
(when
(or
(or
;; locally defined macro
(and (= current-ns macro-prefix)
(= sym macro-suffix))
(and (= current-ns macro-prefix)
(= sym macro-suffix))
;; fully qualified
(= sym macro-name)
(= sym macro-name)
;; aliased
(when alias? (= sym (str alias? "/" macro-suffix)))
(when alias? (= sym (str alias? "/" macro-suffix)))
;; referred
(when (macro-referred? libspecs macro-name)
(= sym macro-suffix))
(when (macro-referred? libspecs macro-name)
(= sym macro-suffix))
;; I used to have a clause here for (:use .. :rename {...})
;; but :use is ;; basically deprecated and nobody used :rename to
;; begin with so I dropped it when the test failed.
)
)
macro-name)))

(defn- active-bindings
Expand Down
8 changes: 4 additions & 4 deletions src/refactor_nrepl/find/find_symbol.clj
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@
{:file (.getCanonicalPath file)
:name fully-qualified-name
:match (match file-content
(:line-beg info)
(:line-end info))}))]
(:line-beg info)
(:line-end info))}))]
(map gather locs)))

(defn- find-global-symbol [file ns var-name ignore-errors]
Expand Down Expand Up @@ -214,8 +214,8 @@
{:name var-name
:file (.getCanonicalPath (java.io.File. file))
:match (match file-content
(:line-beg %)
(:line-end %))})
(:line-beg %)
(:line-end %))})
(find-nodes var-name
[top-level-form-ast]
#(and (#{:local :binding} (:op %))
Expand Down
26 changes: 12 additions & 14 deletions src/refactor_nrepl/middleware.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
;; The assumption is that if someone is using old lein repl or boot repl
;; they'll end up using the tools.nrepl, otherwise the modern one.
(when-not (resolve 'set-descriptor!)
(if (find-ns 'clojure.tools.nrepl)
(require
'[clojure.tools.nrepl.middleware :refer [set-descriptor!]]
'[clojure.tools.nrepl.misc :refer [response-for]]
'[clojure.tools.nrepl.transport :as transport])
(require
'[nrepl.middleware :refer [set-descriptor!]]
'[nrepl.misc :refer [response-for]]
'[nrepl.transport :as transport])))
(if (find-ns 'clojure.tools.nrepl)
(require
'[clojure.tools.nrepl.middleware :refer [set-descriptor!]]
'[clojure.tools.nrepl.misc :refer [response-for]]
'[clojure.tools.nrepl.transport :as transport])
(require
'[nrepl.middleware :refer [set-descriptor!]]
'[nrepl.misc :refer [response-for]]
'[nrepl.transport :as transport])))

(defn- require-and-resolve [sym]
(require (symbol (namespace sym)))
Expand Down Expand Up @@ -183,15 +183,14 @@
:status :done))

(def ^:private find-used-publics
(delay (require-and-resolve 'refactor-nrepl.find.find-used-publics/find-used-publics) ))
(delay (require-and-resolve 'refactor-nrepl.find.find-used-publics/find-used-publics)))

(defn- find-used-publics-reply [{:keys [transport] :as msg}]
(reply transport msg
:used-publics (serialize-response msg (@find-used-publics msg)) :status :done))

(def refactor-nrepl-ops
{
"artifact-list" artifact-list-reply
{"artifact-list" artifact-list-reply
"artifact-versions" artifact-versions-reply
"clean-ns" clean-ns-reply
"extract-definition" extract-definition-reply
Expand All @@ -205,8 +204,7 @@
"find-used-publics" find-used-publics-reply
"version" version-reply
"warm-ast-cache" warm-ast-cache-reply
"warm-macro-occurrences-cache" warm-macro-occurrences-cache-reply
})
"warm-macro-occurrences-cache" warm-macro-occurrences-cache-reply})

(defn wrap-refactor
[handler]
Expand Down
2 changes: 1 addition & 1 deletion src/refactor_nrepl/ns/prune_dependencies.clj
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
(let [ns-name (str (:ns libspec))]
(some (fn [^String pattern]
(re-find (re-pattern pattern) ns-name))
(:libspec-whitelist config/*config*))))
(:libspec-whitelist config/*config*))))

(defn- prune-libspec [symbols-in-file current-ns libspec]
(if (libspec-should-never-be-pruned? libspec)
Expand Down
1 change: 0 additions & 1 deletion src/refactor_nrepl/ns/resolve_missing.clj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
{:name candidate :type :class})))
candidates))


(defn- inlined-dependency? [candidate]
(or (-> candidate str (.startsWith "deps."))
(-> candidate str (.startsWith "mranderson"))
Expand Down
37 changes: 18 additions & 19 deletions src/refactor_nrepl/ns/slam/hound/regrow.clj
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@

(defn- ns->symbols []
(caching :ns->symbols
(let [xs (all-ns)]
(zipmap xs (mapv (comp set keys ns-publics) xs)))))
(let [xs (all-ns)]
(zipmap xs (mapv (comp set keys ns-publics) xs)))))

(defn- symbols->ns-syms*
([]
Expand All @@ -78,7 +78,6 @@
(defn- symbols->ns-syms []
(cache-with-dirty-tracking :symbols->ns-syms symbols->ns-syms*))


(defn- walk
"Adapted from clojure.walk/walk and clojure.walk/prewalk; this version
preserves metadata on compound forms."
Expand Down Expand Up @@ -110,12 +109,12 @@

(def ^:private ns-qualifed-syms
(memoize
(fn [body]
(apply merge-with set/union {}
(for [ss (symbols-in-body body)
:let [[_ alias var-name] (re-matches #"(.+)/(.+)" (str ss))]
:when alias]
{(symbol alias) #{(symbol var-name)}})))))
(fn [body]
(apply merge-with set/union {}
(for [ss (symbols-in-body body)
:let [[_ alias var-name] (re-matches #"(.+)/(.+)" (str ss))]
:when alias]
{(symbol alias) #{(symbol var-name)}})))))

(defn- ns-import-candidates
"Search (all-ns) for imports that match missing-sym, returning a set of
Expand All @@ -131,12 +130,12 @@

(defn- alias-candidates [type missing body]
(set
(let [syms-with-alias (get (ns-qualifed-syms body) missing)]
(when (seq syms-with-alias)
(let [ns->syms (ns->symbols)]
(for [ns (all-ns)
:when (set/subset? syms-with-alias (ns->syms ns))]
(ns-name ns)))))))
(let [syms-with-alias (get (ns-qualifed-syms body) missing)]
(when (seq syms-with-alias)
(let [ns->syms (ns->symbols)]
(for [ns (all-ns)
:when (set/subset? syms-with-alias (ns->syms ns))]
(ns-name ns)))))))

(defn candidates
"Return a set of class or ns symbols that match the given constraints."
Expand All @@ -155,7 +154,7 @@
(alias-candidates type missing body')))))
:refer (get (symbols->ns-syms) missing)
:rename (reduce-kv
(fn [s ns orig->rename]
(cond->* s
(some #{missing} (vals orig->rename)) (conj ns)))
#{} (:rename old-ns-map))))
(fn [s ns orig->rename]
(cond->* s
(some #{missing} (vals orig->rename)) (conj ns)))
#{} (:rename old-ns-map))))
2 changes: 1 addition & 1 deletion src/refactor_nrepl/plugin.clj
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
(defn- warn-no-project []
(do
(lein/warn "Warning: refactor-nrepl needs to run in the context of a project.")
(lein/warn "Warning: refactor-nrepl middleware won't be activated." )))
(lein/warn "Warning: refactor-nrepl middleware won't be activated.")))

(defn middleware
[project]
Expand Down
6 changes: 3 additions & 3 deletions test/refactor_nrepl/artifacts_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
(deftest creates-a-map-of-artifacts
(reset! artifacts/artifacts {})
(with-redefs
[artifacts/get-clojars-artifacts! (constantly clojars-artifacts)
artifacts/get-mvn-artifacts! (constantly clojure-artifacts)
artifacts/get-mvn-versions! (constantly clojure-versions)]
[artifacts/get-clojars-artifacts! (constantly clojars-artifacts)
artifacts/get-mvn-artifacts! (constantly clojure-artifacts)
artifacts/get-mvn-versions! (constantly clojure-versions)]

(is (#'artifacts/stale-cache?))

Expand Down
2 changes: 0 additions & 2 deletions test/refactor_nrepl/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
[refactor-nrepl.config :as config]
[refactor-nrepl.core :refer [ignore-dir-on-classpath?]]))


(defmacro assert-ignored-paths
[paths pred]
`(doseq [p# ~paths]
(is (~pred (ignore-dir-on-classpath? p#)))))


(deftest test-ignore-dir-on-classpath?
(let [not-ignored ["/home/user/project/test"
"/home/user/project/src"
Expand Down
2 changes: 1 addition & 1 deletion test/refactor_nrepl/ns/clean_ns_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
(deftest throws-on-malformed-ns
(is (thrown? IllegalStateException
(core/read-ns-form-with-meta (.getAbsolutePath
(File. "test/resources/clojars-artifacts.edn"))))))
(File. "test/resources/clojars-artifacts.edn"))))))

(deftest preserves-other-elements
(let [actual (clean-ns ns1)
Expand Down
3 changes: 2 additions & 1 deletion test/refactor_nrepl/rename_file_or_dir_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,10 @@
(is (some #(.endsWith % "non_clj_file") @files))
(is (= 4 (count (filter #(.endsWith % ".cljs") @files)))))))


;;; cljs


(def from-file-path-cljs (.getAbsolutePath (File. "test/resources/testproject/src/com/move/ns_to_be_moved_cljs.cljs")))
(def to-file-path-cljs (.getAbsolutePath (File. "test/resources/testproject/src/com/move/moved_ns_cljs.cljs")))

Expand Down
2 changes: 1 addition & 1 deletion test/refactor_nrepl/s_expressions_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
(t/is (= "{:qux [#{more}]}" (apply sut/get-enclosing-sexp file-content map-location)))
(t/is (= nil (apply sut/get-enclosing-sexp weird-file-content weird-location)))
(t/is (= nil (sut/get-first-sexp weird-file-content)))
(t/is (= "#{foo bar baz}"(sut/get-first-sexp file-content-with-set))))
(t/is (= "#{foo bar baz}" (sut/get-first-sexp file-content-with-set))))
3 changes: 1 addition & 2 deletions test/resources/cljcns.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,4 @@
(PushbackReader. nil))

(proxy [FilenameFilter] []
(accept [d n] true))
))
(accept [d n] true))))
12 changes: 6 additions & 6 deletions test/resources/ns2_cleaned_meta.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
(ns ^{:author "Trurl and Klapaucius", :doc "test ns with meta"}
resources.ns2-meta
(:require [clojure
[edn :refer :all :rename {read rd, read-string rs}]
[instant :refer :all]
[pprint :refer [cl-format fresh-line get-pretty-writer]]
[string :refer :all :rename {reverse bar, replace foo}]
[test :refer :all]]))
(:require [clojure
[edn :refer :all :rename {read rd, read-string rs}]
[instant :refer :all]
[pprint :refer [cl-format fresh-line get-pretty-writer]]
[string :refer :all :rename {reverse bar, replace foo}]
[test :refer :all]]))
2 changes: 1 addition & 1 deletion test/resources/ns2_meta.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
;; ===========================================================================
(ns ^{:author "Trurl and Klapaucius"
:doc "test ns with meta"}
resources.ns2-meta
resources.ns2-meta
(:require
[clojure.pprint :refer [fresh-line]]
[clojure.pprint :refer [get-pretty-writer]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
(defn shadow-macro-in-fn-param [my-macro]
(my-macro :shadowed-by-function-param))

(defn shadow-macro-in-let[my-macro]
(defn shadow-macro-in-let [my-macro]
(let [my-macro (fn not-a-macro [])]
(my-macro :shadowed-by-let)))