Skip to content

Commit d7d0378

Browse files
committed
Fix clj-kondo warnings in src directories
1 parent 3ef0481 commit d7d0378

File tree

21 files changed

+72
-69
lines changed

21 files changed

+72
-69
lines changed

.clj-kondo/config.edn

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{:lint-as {hiccup.def/defhtml clojure.core/defn}
2+
:linters
3+
{:deprecated-var
4+
{:exclude
5+
{ring.middleware.file-info/file-info-response
6+
{:defs [ring.middleware.file-info/wrap-file-info]
7+
:namespaces [ring.middleware.test.file-info]}}}}}

ring-core-protocols/src/ring/core/protocols.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
(io/writer output-stream)))
3838

3939
(extend-protocol StreamableResponseBody
40-
(Class/forName "[B")
40+
#_{:clj-kondo/ignore [:syntax]} (Class/forName "[B")
4141
(write-body-to-stream [body _ ^OutputStream output-stream]
4242
(.write output-stream ^bytes body)
4343
(.close output-stream))

ring-core/src/ring/middleware/content_type.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
([response request]
1515
(content-type-response response request {}))
1616
([response request options]
17-
(if response
17+
(when response
1818
(if (get-header response "Content-Type")
1919
response
2020
(let [mime-type (guess-mime-type request response (:mime-types options))]

ring-core/src/ring/middleware/file.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"Ensures that a directory exists at the given path, throwing if one does not."
1414
[dir-path]
1515
(let [dir (io/as-file dir-path)]
16-
(if-not (.exists dir)
16+
(when-not (.exists dir)
1717
(throw (Exception. (format "Directory does not exist: %s" dir-path))))))
1818

1919
(defn file-request
@@ -27,7 +27,7 @@
2727
:index-files? true
2828
:allow-symlinks? false}
2929
options)]
30-
(if (#{:get :head} (:request-method request))
30+
(when (#{:get :head} (:request-method request))
3131
(let [path (subs (codec/url-decode (request/path-info request)) 1)]
3232
(-> (response/file-response path options)
3333
(head/head-response request)))))))

ring-core/src/ring/middleware/file_info.clj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[ring.util.mime-type :refer [ext-mime-type]]
88
[ring.util.io :refer [last-modified-date]])
99
(:import [java.io File]
10-
[java.util Date Locale TimeZone]
10+
[java.util Locale TimeZone]
1111
[java.text SimpleDateFormat]))
1212

1313
(defn- guess-mime-type
@@ -17,17 +17,17 @@
1717
(or (ext-mime-type (.getPath file) mime-types)
1818
"application/octet-stream"))
1919

20-
(defn- ^SimpleDateFormat make-http-format
20+
(defn- make-http-format
2121
"Formats or parses dates into HTTP date format (RFC 822/1123)."
22-
[]
22+
^SimpleDateFormat []
2323
;; SimpleDateFormat is not threadsafe, so return a new instance each time
2424
(doto (SimpleDateFormat. "EEE, dd MMM yyyy HH:mm:ss ZZZ" Locale/US)
2525
(.setTimeZone (TimeZone/getTimeZone "UTC"))))
2626

2727
(defn- not-modified-since?
2828
"Has the file been modified since the last request from the client?"
29-
[{headers :headers :as req} last-modified]
30-
(if-let [modified-since (headers "if-modified-since")]
29+
[{headers :headers} last-modified]
30+
(when-let [modified-since (headers "if-modified-since")]
3131
(not (.before (.parse (make-http-format) modified-since)
3232
last-modified))))
3333

ring-core/src/ring/middleware/flash.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
{:added "1.2"}
1818
[response request]
1919
(let [{:keys [session flash]} request]
20-
(if response
20+
(when response
2121
(let [session (if (contains? response :session)
2222
(response :session)
2323
session)

ring-core/src/ring/middleware/keyword_params.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
(defn- keyword-syntax?
1111
[s parse-namespaces?]
1212
(or (re-matches re-plain-keyword s)
13-
(if parse-namespaces? (re-matches re-namespaced-keyword s))))
13+
(when parse-namespaces? (re-matches re-namespaced-keyword s))))
1414

1515
(defn- keyify-params [target parse-namespaces?]
1616
(cond

ring-core/src/ring/middleware/multipart_params/temp_file.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
(.delete file)
2727
(swap! file-set disj file))))
2828

29-
(defn- ^File make-temp-file [file-set]
29+
(defn- make-temp-file ^File [file-set]
3030
(let [temp-file (File/createTempFile "ring-multipart-" nil)]
3131
(swap! file-set conj temp-file)
3232
temp-file))

ring-core/src/ring/middleware/nested_params.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
=> [\"foo\" \"bar\" \"\" \"baz\"]"
1313
[param-name]
1414
(let [[_ k ks] (re-matches #"(?s)(.*?)((?:\[.*?\])*)" (name param-name))
15-
keys (if ks (map second (re-seq #"\[(.*?)\]" ks)))]
15+
keys (when ks (map second (re-seq #"\[(.*?)\]" ks)))]
1616
(cons k keys)))
1717

1818
(defn- assoc-vec [m k v]

ring-core/src/ring/middleware/not_modified.clj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
"Middleware that returns a 304 Not Modified response for responses with
33
Last-Modified headers."
44
(:require [ring.util.time :refer [parse-date]]
5-
[ring.util.response :refer [status get-header header]]
5+
[ring.util.response :refer [get-header header]]
66
[ring.util.io :refer [close!]]))
77

88
(defn- etag-match? [request response]
9-
(if-let [etag (get-header response "ETag")]
9+
(when-let [etag (get-header response "ETag")]
1010
(= etag (get-header request "if-none-match"))))
1111

12-
(defn- ^java.util.Date date-header [response header]
13-
(if-let [http-date (get-header response header)]
12+
(defn- date-header ^java.util.Date [response header]
13+
(when-let [http-date (get-header response header)]
1414
(parse-date http-date)))
1515

1616
(defn- not-modified-since? [request response]

ring-core/src/ring/middleware/resource.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
([request root-path]
1414
(resource-request request root-path {}))
1515
([request root-path options]
16-
(if (#{:head :get} (:request-method request))
16+
(when (#{:head :get} (:request-method request))
1717
(let [path (subs (codec/url-decode (request/path-info request)) 1)]
1818
(-> (response/resource-response path (assoc options :root root-path))
1919
(head/head-response request))))))

ring-core/src/ring/middleware/session.clj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
:cookie-attrs (merge {:path "/"
2020
:http-only true}
2121
(options :cookie-attrs)
22-
(if-let [root (options :root)]
22+
(when-let [root (options :root)]
2323
{:path root}))})
2424

2525
(defn- bare-session-request
2626
[request {:keys [store cookie-name]}]
2727
(let [req-key (get-in request [:cookies cookie-name :value])
2828
session (store/read-session store req-key)
29-
session-key (if session req-key)]
29+
session-key (when session req-key)]
3030
(merge request {:session (or session {})
3131
:session/key session-key})))
3232

@@ -43,15 +43,15 @@
4343

4444
(defn- bare-session-response
4545
[response {session-key :session/key} {:keys [store cookie-name cookie-attrs]}]
46-
(let [new-session-key (if (contains? response :session)
46+
(let [new-session-key (when (contains? response :session)
4747
(if-let [session (response :session)]
4848
(if (:recreate (meta session))
4949
(do
5050
(store/delete-session store session-key)
5151
(->> (vary-meta session dissoc :recreate)
5252
(store/write-session store nil)))
5353
(store/write-session store session-key session))
54-
(if session-key
54+
(when session-key
5555
(store/delete-session store session-key))))
5656
session-attrs (:session-cookie-attrs response)
5757
cookie {cookie-name
@@ -70,7 +70,7 @@
7070
([response request]
7171
(session-response response request {}))
7272
([response request options]
73-
(if response
73+
(when response
7474
(-> response
7575
(bare-session-response request options)
7676
(cond-> (:set-cookies? options true) cookies/cookies-response)))))

ring-core/src/ring/middleware/session/cookie.clj

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
[clojure.edn :as edn]
66
[crypto.random :as random]
77
[crypto.equality :as crypto])
8-
(:import [java.security SecureRandom]
9-
[javax.crypto Cipher Mac]
8+
(:import [javax.crypto Cipher Mac]
109
[javax.crypto.spec SecretKeySpec IvParameterSpec]))
1110

1211
(def ^{:private true
@@ -74,7 +73,7 @@
7473
(defn- deserialize [x options]
7574
(edn/read-string (select-keys options [:readers]) x))
7675

77-
(defn- ^String serialize [x options]
76+
(defn- serialize ^String [x options]
7877
{:post [(= x (deserialize % options))]}
7978
(pr-str x))
8079

@@ -88,15 +87,15 @@
8887
"Retrieve a sealed Clojure data structure from a string"
8988
[key ^String string options]
9089
(let [[data mac] (.split string "--")]
91-
(if-let [data (try (codec/base64-decode data)
90+
(when-let [data (try (codec/base64-decode data)
9291
(catch IllegalArgumentException _ nil))]
93-
(if (crypto/eq? mac (hmac key data))
92+
(when (crypto/eq? mac (hmac key data))
9493
(deserialize (decrypt key data) options)))))
9594

9695
(deftype CookieStore [secret-key options]
9796
SessionStore
9897
(read-session [_ data]
99-
(if data (unseal secret-key data options)))
98+
(when data (unseal secret-key data options)))
10099
(write-session [_ _ data]
101100
(seal secret-key data options))
102101
(delete-session [_ _]

ring-core/src/ring/util/io.clj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
(ns ring.util.io
22
"Utility functions for handling I/O."
3-
(:require [clojure.java.io :as io])
43
(:import [java.io PipedInputStream
54
PipedOutputStream
65
ByteArrayInputStream
76
File
8-
Closeable
97
IOException]))
108

119
(defn piped-input-stream

ring-core/src/ring/util/mime_type.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
(defn- filename-ext
105105
"Returns the file extension of a filename or filepath."
106106
[filename]
107-
(if-let [ext (second (re-find #"\.([^./\\]+)$" filename))]
107+
(when-let [ext (second (re-find #"\.([^./\\]+)$" filename))]
108108
(str/lower-case ext)))
109109

110110
(defn ext-mime-type

ring-core/src/ring/util/request.clj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@
1010
"://"
1111
(get-in request [:headers "host"])
1212
(:uri request)
13-
(if-let [query (:query-string request)]
13+
(when-let [query (:query-string request)]
1414
(str "?" query))))
1515

1616
(defn content-type
1717
"Return the content-type of the request, or nil if no content-type is set."
1818
{:added "1.3"}
1919
[request]
20-
(if-let [type ^String (get (:headers request) "content-type")]
20+
(when-let [type ^String (get (:headers request) "content-type")]
2121
(let [i (.indexOf type ";")]
2222
(if (neg? i) type (subs type 0 i)))))
2323

2424
(defn content-length
2525
"Return the content-length of the request, or nil no content-length is set."
2626
{:added "1.3"}
2727
[request]
28-
(if-let [^String length (get-in request [:headers "content-length"])]
28+
(when-let [^String length (get-in request [:headers "content-length"])]
2929
(Long/valueOf length)))
3030

3131
(defn character-encoding
@@ -39,7 +39,7 @@
3939
"True if a request contains a urlencoded form in the body."
4040
{:added "1.3"}
4141
[request]
42-
(if-let [^String type (content-type request)]
42+
(when-let [^String type (content-type request)]
4343
(.startsWith type "application/x-www-form-urlencoded")))
4444

4545
(defmulti ^String body-string

ring-core/src/ring/util/response.clj

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484

8585
(defn- canonical-path ^String [^File file]
8686
(str (.getCanonicalPath file)
87-
(if (.isDirectory file) File/separatorChar)))
87+
(when (.isDirectory file) File/separatorChar)))
8888

8989
(defn- safe-path? [^String root ^String path]
9090
(.startsWith (canonical-path (File. root path))
@@ -99,7 +99,7 @@
9999

100100
(defn- find-file-named [^File dir ^String filename]
101101
(let [path (File. dir filename)]
102-
(if (.isFile path)
102+
(when (.isFile path)
103103
path)))
104104

105105
(defn- find-file-starting-with [^File dir ^String prefix]
@@ -117,13 +117,13 @@
117117

118118
(defn- safely-find-file [^String path opts]
119119
(if-let [^String root (:root opts)]
120-
(if (or (safe-path? root path)
120+
(when (or (safe-path? root path)
121121
(and (:allow-symlinks? opts) (not (directory-transversal? path))))
122122
(File. root path))
123123
(File. path)))
124124

125125
(defn- find-file [^String path opts]
126-
(if-let [^File file (safely-find-file path opts)]
126+
(when-let [^File file (safely-find-file path opts)]
127127
(cond
128128
(.isDirectory file)
129129
(and (:index-files? opts true) (find-index-file file))
@@ -156,7 +156,7 @@
156156
([filepath]
157157
(file-response filepath {}))
158158
([filepath options]
159-
(if-let [file (find-file filepath options)]
159+
(when-let [file (find-file filepath options)]
160160
(let [data (file-data file)]
161161
(-> (response (:content data))
162162
(content-length (:content-length data))
@@ -170,7 +170,7 @@
170170
;; As a work-around, we'll backport the fix from CLJ-1177 into
171171
;; url-as-file.
172172

173-
(defn- ^File url-as-file [^java.net.URL u]
173+
(defn- url-as-file ^File [^java.net.URL u]
174174
(-> (.getFile u)
175175
(str/replace \/ File/separatorChar)
176176
(str/replace "+" (URLEncoder/encode "+" "UTF-8"))
@@ -265,8 +265,8 @@
265265

266266
(defmethod resource-data :file
267267
[url]
268-
(if-let [file (url-as-file url)]
269-
(if-not (.isDirectory file)
268+
(when-let [file (url-as-file url)]
269+
(when-not (.isDirectory file)
270270
(file-data file))))
271271

272272
(defn- add-ending-slash [^String path]
@@ -282,17 +282,17 @@
282282

283283
(defn- connection-content-length [^java.net.URLConnection conn]
284284
(let [len (.getContentLength conn)]
285-
(if (<= 0 len) len)))
285+
(when (<= 0 len) len)))
286286

287287
(defn- connection-last-modified [^java.net.URLConnection conn]
288288
(let [last-mod (.getLastModified conn)]
289-
(if-not (zero? last-mod)
289+
(when-not (zero? last-mod)
290290
(Date. last-mod))))
291291

292292
(defmethod resource-data :jar
293293
[^java.net.URL url]
294294
(let [conn (.openConnection url)]
295-
(if-not (jar-directory? conn)
295+
(when-not (jar-directory? conn)
296296
{:content (.getInputStream conn)
297297
:content-length (connection-content-length conn)
298298
:last-modified (connection-last-modified conn)})))
@@ -301,7 +301,7 @@
301301
"Return a response for the supplied URL."
302302
{:added "1.2"}
303303
[^URL url]
304-
(if-let [data (resource-data url)]
304+
(when-let [data (resource-data url)]
305305
(-> (response (:content data))
306306
(content-length (:content-length data))
307307
(last-modified (:last-modified data)))))
@@ -337,9 +337,9 @@
337337
load #(if-let [loader (:loader options)]
338338
(io/resource % loader)
339339
(io/resource %))]
340-
(if-not (directory-transversal? root+path)
341-
(if-let [resource (load root+path)]
340+
(when-not (directory-transversal? root+path)
341+
(when-let [resource (load root+path)]
342342
(let [response (url-response resource)]
343-
(if (or (not (instance? File (:body response)))
344-
(safe-file-resource? response options))
343+
(when (or (not (instance? File (:body response)))
344+
(safe-file-resource? response options))
345345
response)))))))

ring-core/src/ring/util/time.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
:rfc1036 "EEEE, dd-MMM-yy HH:mm:ss zzz"
1010
:asctime "EEE MMM d HH:mm:ss yyyy"})
1111

12-
(defn- ^SimpleDateFormat formatter [format]
12+
(defn- formatter ^SimpleDateFormat [format]
1313
(doto (SimpleDateFormat. ^String (http-date-formats format) Locale/US)
1414
(.setTimeZone (TimeZone/getTimeZone "GMT"))))
1515

0 commit comments

Comments
 (0)