Skip to content

Commit d827961

Browse files
shen-tianbbatsov
authored andcommitted
Add a cljfmt check (#243)
1 parent 6d0a48b commit d827961

20 files changed

+85
-82
lines changed

.circleci/config.yml

+11-11
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,14 @@ workflows:
170170
# name: Java 11, Clojure master
171171
# clojure_version: "master"
172172
# jdk_version: openjdk11
173-
# - util_job:
174-
# name: Code Linting
175-
# steps:
176-
# - run:
177-
# name: Running Eastwood
178-
# command: |
179-
# make eastwood
180-
# - run:
181-
# name: Running cljfmt
182-
# command: |
183-
# make cljfmt
173+
- util_job:
174+
name: Code Linting
175+
steps:
176+
# - run:
177+
# name: Running Eastwood
178+
# command: |
179+
# make eastwood
180+
- run:
181+
name: Running cljfmt
182+
command: |
183+
make cljfmt

Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ source-deps: .source-deps
1111
test: .source-deps
1212
lein with-profile +$(VERSION),+plugin.mranderson/config test
1313

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

1517
# When releasing, the BUMP variable controls which field in the
1618
# version string will be incremented in the *next* snapshot

project.clj

+10-1
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,14 @@
4747
:java-source-paths ["test/java"]
4848
:resource-paths ["test/resources"
4949
"test/resources/testproject/src"]
50-
:repositories [["snapshots" "https://oss.sonatype.org/content/repositories/snapshots"]]}}
50+
:repositories [["snapshots" "https://oss.sonatype.org/content/repositories/snapshots"]]}
51+
:cljfmt [:test
52+
{:plugins [[lein-cljfmt "0.6.4"]]
53+
:cljfmt {:indents {as-> [[:inner 0]]
54+
as->* [[:inner 0]]
55+
cond-> [[:inner 0]]
56+
cond->* [[:inner 0]]
57+
with-debug-bindings [[:inner 0]]
58+
merge-meta [[:inner 0]]
59+
try-if-let [[:block 1]]}}}]}
5160
:jvm-opts ["-Djava.net.preferIPv4Stack=true"])

src/refactor_nrepl/config.clj

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

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

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

2524
;; Regexes matching paths that are to be ignored
26-
:ignore-paths []
27-
})
25+
:ignore-paths []})
2826

2927
(defn opts-from-msg [msg]
3028
(into {}

src/refactor_nrepl/find/find_macros.clj

+8-8
Original file line numberDiff line numberDiff line change
@@ -138,21 +138,21 @@
138138
macro-suffix (core/suffix macro-name)
139139
alias? ((get-ns-aliases libspecs) macro-prefix)]
140140
(when
141-
(or
141+
(or
142142
;; locally defined macro
143-
(and (= current-ns macro-prefix)
144-
(= sym macro-suffix))
143+
(and (= current-ns macro-prefix)
144+
(= sym macro-suffix))
145145
;; fully qualified
146-
(= sym macro-name)
146+
(= sym macro-name)
147147
;; aliased
148-
(when alias? (= sym (str alias? "/" macro-suffix)))
148+
(when alias? (= sym (str alias? "/" macro-suffix)))
149149
;; referred
150-
(when (macro-referred? libspecs macro-name)
151-
(= sym macro-suffix))
150+
(when (macro-referred? libspecs macro-name)
151+
(= sym macro-suffix))
152152
;; I used to have a clause here for (:use .. :rename {...})
153153
;; but :use is ;; basically deprecated and nobody used :rename to
154154
;; begin with so I dropped it when the test failed.
155-
)
155+
)
156156
macro-name)))
157157

158158
(defn- active-bindings

src/refactor_nrepl/find/find_symbol.clj

+4-4
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@
126126
{:file (.getCanonicalPath file)
127127
:name fully-qualified-name
128128
:match (match file-content
129-
(:line-beg info)
130-
(:line-end info))}))]
129+
(:line-beg info)
130+
(:line-end info))}))]
131131
(map gather locs)))
132132

133133
(defn- find-global-symbol [file ns var-name ignore-errors]
@@ -214,8 +214,8 @@
214214
{:name var-name
215215
:file (.getCanonicalPath (java.io.File. file))
216216
:match (match file-content
217-
(:line-beg %)
218-
(:line-end %))})
217+
(:line-beg %)
218+
(:line-end %))})
219219
(find-nodes var-name
220220
[top-level-form-ast]
221221
#(and (#{:local :binding} (:op %))

src/refactor_nrepl/middleware.clj

+12-14
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
;; The assumption is that if someone is using old lein repl or boot repl
1212
;; they'll end up using the tools.nrepl, otherwise the modern one.
1313
(when-not (resolve 'set-descriptor!)
14-
(if (find-ns 'clojure.tools.nrepl)
15-
(require
16-
'[clojure.tools.nrepl.middleware :refer [set-descriptor!]]
17-
'[clojure.tools.nrepl.misc :refer [response-for]]
18-
'[clojure.tools.nrepl.transport :as transport])
19-
(require
20-
'[nrepl.middleware :refer [set-descriptor!]]
21-
'[nrepl.misc :refer [response-for]]
22-
'[nrepl.transport :as transport])))
14+
(if (find-ns 'clojure.tools.nrepl)
15+
(require
16+
'[clojure.tools.nrepl.middleware :refer [set-descriptor!]]
17+
'[clojure.tools.nrepl.misc :refer [response-for]]
18+
'[clojure.tools.nrepl.transport :as transport])
19+
(require
20+
'[nrepl.middleware :refer [set-descriptor!]]
21+
'[nrepl.misc :refer [response-for]]
22+
'[nrepl.transport :as transport])))
2323

2424
(defn- require-and-resolve [sym]
2525
(require (symbol (namespace sym)))
@@ -183,15 +183,14 @@
183183
:status :done))
184184

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

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

192192
(def refactor-nrepl-ops
193-
{
194-
"artifact-list" artifact-list-reply
193+
{"artifact-list" artifact-list-reply
195194
"artifact-versions" artifact-versions-reply
196195
"clean-ns" clean-ns-reply
197196
"extract-definition" extract-definition-reply
@@ -205,8 +204,7 @@
205204
"find-used-publics" find-used-publics-reply
206205
"version" version-reply
207206
"warm-ast-cache" warm-ast-cache-reply
208-
"warm-macro-occurrences-cache" warm-macro-occurrences-cache-reply
209-
})
207+
"warm-macro-occurrences-cache" warm-macro-occurrences-cache-reply})
210208

211209
(defn wrap-refactor
212210
[handler]

src/refactor_nrepl/ns/prune_dependencies.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
(let [ns-name (str (:ns libspec))]
120120
(some (fn [^String pattern]
121121
(re-find (re-pattern pattern) ns-name))
122-
(:libspec-whitelist config/*config*))))
122+
(:libspec-whitelist config/*config*))))
123123

124124
(defn- prune-libspec [symbols-in-file current-ns libspec]
125125
(if (libspec-should-never-be-pruned? libspec)

src/refactor_nrepl/ns/resolve_missing.clj

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
{:name candidate :type :class})))
3636
candidates))
3737

38-
3938
(defn- inlined-dependency? [candidate]
4039
(or (-> candidate str (.startsWith "deps."))
4140
(-> candidate str (.startsWith "mranderson"))

src/refactor_nrepl/ns/slam/hound/regrow.clj

+18-19
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@
6060

6161
(defn- ns->symbols []
6262
(caching :ns->symbols
63-
(let [xs (all-ns)]
64-
(zipmap xs (mapv (comp set keys ns-publics) xs)))))
63+
(let [xs (all-ns)]
64+
(zipmap xs (mapv (comp set keys ns-publics) xs)))))
6565

6666
(defn- symbols->ns-syms*
6767
([]
@@ -78,7 +78,6 @@
7878
(defn- symbols->ns-syms []
7979
(cache-with-dirty-tracking :symbols->ns-syms symbols->ns-syms*))
8080

81-
8281
(defn- walk
8382
"Adapted from clojure.walk/walk and clojure.walk/prewalk; this version
8483
preserves metadata on compound forms."
@@ -110,12 +109,12 @@
110109

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

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

132131
(defn- alias-candidates [type missing body]
133132
(set
134-
(let [syms-with-alias (get (ns-qualifed-syms body) missing)]
135-
(when (seq syms-with-alias)
136-
(let [ns->syms (ns->symbols)]
137-
(for [ns (all-ns)
138-
:when (set/subset? syms-with-alias (ns->syms ns))]
139-
(ns-name ns)))))))
133+
(let [syms-with-alias (get (ns-qualifed-syms body) missing)]
134+
(when (seq syms-with-alias)
135+
(let [ns->syms (ns->symbols)]
136+
(for [ns (all-ns)
137+
:when (set/subset? syms-with-alias (ns->syms ns))]
138+
(ns-name ns)))))))
140139

141140
(defn candidates
142141
"Return a set of class or ns symbols that match the given constraints."
@@ -155,7 +154,7 @@
155154
(alias-candidates type missing body')))))
156155
:refer (get (symbols->ns-syms) missing)
157156
:rename (reduce-kv
158-
(fn [s ns orig->rename]
159-
(cond->* s
160-
(some #{missing} (vals orig->rename)) (conj ns)))
161-
#{} (:rename old-ns-map))))
157+
(fn [s ns orig->rename]
158+
(cond->* s
159+
(some #{missing} (vals orig->rename)) (conj ns)))
160+
#{} (:rename old-ns-map))))

src/refactor_nrepl/plugin.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
(defn- warn-no-project []
4545
(do
4646
(lein/warn "Warning: refactor-nrepl needs to run in the context of a project.")
47-
(lein/warn "Warning: refactor-nrepl middleware won't be activated." )))
47+
(lein/warn "Warning: refactor-nrepl middleware won't be activated.")))
4848

4949
(defn middleware
5050
[project]

test/refactor_nrepl/artifacts_test.clj

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
(deftest creates-a-map-of-artifacts
2121
(reset! artifacts/artifacts {})
2222
(with-redefs
23-
[artifacts/get-clojars-artifacts! (constantly clojars-artifacts)
24-
artifacts/get-mvn-artifacts! (constantly clojure-artifacts)
25-
artifacts/get-mvn-versions! (constantly clojure-versions)]
23+
[artifacts/get-clojars-artifacts! (constantly clojars-artifacts)
24+
artifacts/get-mvn-artifacts! (constantly clojure-artifacts)
25+
artifacts/get-mvn-versions! (constantly clojure-versions)]
2626

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

test/refactor_nrepl/core_test.clj

-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
[refactor-nrepl.config :as config]
44
[refactor-nrepl.core :refer [ignore-dir-on-classpath?]]))
55

6-
76
(defmacro assert-ignored-paths
87
[paths pred]
98
`(doseq [p# ~paths]
109
(is (~pred (ignore-dir-on-classpath? p#)))))
1110

12-
1311
(deftest test-ignore-dir-on-classpath?
1412
(let [not-ignored ["/home/user/project/test"
1513
"/home/user/project/src"

test/refactor_nrepl/ns/clean_ns_test.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
(deftest throws-on-malformed-ns
9595
(is (thrown? IllegalStateException
9696
(core/read-ns-form-with-meta (.getAbsolutePath
97-
(File. "test/resources/clojars-artifacts.edn"))))))
97+
(File. "test/resources/clojars-artifacts.edn"))))))
9898

9999
(deftest preserves-other-elements
100100
(let [actual (clean-ns ns1)

test/refactor_nrepl/rename_file_or_dir_test.clj

+2-1
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,10 @@
146146
(is (some #(.endsWith % "non_clj_file") @files))
147147
(is (= 4 (count (filter #(.endsWith % ".cljs") @files)))))))
148148

149-
149+
150150
;;; cljs
151151

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

test/refactor_nrepl/s_expressions_test.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@
2929
(t/is (= "{:qux [#{more}]}" (apply sut/get-enclosing-sexp file-content map-location)))
3030
(t/is (= nil (apply sut/get-enclosing-sexp weird-file-content weird-location)))
3131
(t/is (= nil (sut/get-first-sexp weird-file-content)))
32-
(t/is (= "#{foo bar baz}"(sut/get-first-sexp file-content-with-set))))
32+
(t/is (= "#{foo bar baz}" (sut/get-first-sexp file-content-with-set))))

test/resources/cljcns.cljc

+1-2
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,4 @@
8383
(PushbackReader. nil))
8484

8585
(proxy [FilenameFilter] []
86-
(accept [d n] true))
87-
))
86+
(accept [d n] true))))

test/resources/ns2_cleaned_meta.clj

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
(ns ^{:author "Trurl and Klapaucius", :doc "test ns with meta"}
22
resources.ns2-meta
3-
(:require [clojure
4-
[edn :refer :all :rename {read rd, read-string rs}]
5-
[instant :refer :all]
6-
[pprint :refer [cl-format fresh-line get-pretty-writer]]
7-
[string :refer :all :rename {reverse bar, replace foo}]
8-
[test :refer :all]]))
3+
(:require [clojure
4+
[edn :refer :all :rename {read rd, read-string rs}]
5+
[instant :refer :all]
6+
[pprint :refer [cl-format fresh-line get-pretty-writer]]
7+
[string :refer :all :rename {reverse bar, replace foo}]
8+
[test :refer :all]]))

test/resources/ns2_meta.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
;; ===========================================================================
88
(ns ^{:author "Trurl and Klapaucius"
99
:doc "test ns with meta"}
10-
resources.ns2-meta
10+
resources.ns2-meta
1111
(:require
1212
[clojure.pprint :refer [fresh-line]]
1313
[clojure.pprint :refer [get-pretty-writer]]

test/resources/testproject/src/com/example/shadowed_macro_usages.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
(defn shadow-macro-in-fn-param [my-macro]
55
(my-macro :shadowed-by-function-param))
66

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

0 commit comments

Comments
 (0)