WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit d68dcbb

Browse files
committed
maint: update clj-kondo lib imports
1 parent 1e50570 commit d68dcbb

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
(ns babashka.fs
2+
(:require [clj-kondo.hooks-api :as api]))
3+
4+
(defn- symbol-node? [node]
5+
(and (api/token-node? node)
6+
(symbol? (api/sexpr node))))
7+
8+
(defn with-temp-dir
9+
[{:keys [node]}]
10+
(let [args (rest (:children node))
11+
binding-like-vector (first args)
12+
body (rest args)]
13+
(when-not (zero? (count args)) ;; let clj-kondo report on arity
14+
(if-not (api/vector-node? binding-like-vector)
15+
(api/reg-finding! (assoc (meta binding-like-vector)
16+
:message "babashka.fs/with-temp-dir requires a vector for first arg"
17+
:type :babashka-fs/with-temp-dir-first-arg-not-vector))
18+
(let [[binding-sym options & rest-in-vec] (:children binding-like-vector)]
19+
(when (not (symbol-node? binding-sym))
20+
(api/reg-finding! (assoc (meta (or binding-sym binding-like-vector))
21+
:message "babashka.fs/with-temp-dir vector arg requires binding-name symbol as first value"
22+
:type :babashka-fs/with-temp-dir-vector-arg-needs-binding-symbol)))
23+
(doseq [extra-vector-arg rest-in-vec]
24+
(api/reg-finding! (assoc (meta extra-vector-arg)
25+
:message "babashka.fs/with-temp-dir vector arg accepts at most 2 values"
26+
:type :babashka-fs/with-temp-dir-vector-arg-extra-value)))
27+
28+
(when binding-sym
29+
{:node (api/list-node
30+
;; satisfy linter by creating binding for for binding-sym
31+
(list*
32+
(api/token-node 'let)
33+
;; it doesn't really matter what we bind to, so long as it is bound
34+
(api/vector-node [binding-sym (api/token-node nil)])
35+
options ;; avoid unused binding when options is a binding
36+
body))}))))))
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
{:lint-as {babashka.fs/with-temp-dir clojure.core/let}}
1+
{:linters {:babashka-fs/with-temp-dir-first-arg-not-vector {:level :error}
2+
:babashka-fs/with-temp-dir-vector-arg-needs-binding-symbol {:level :error}
3+
:babashka-fs/with-temp-dir-vector-arg-extra-value {:level :error}}
4+
:hooks {:analyze-call {babashka.fs/with-temp-dir babashka.fs/with-temp-dir}}}

0 commit comments

Comments
 (0)