Skip to content

Commit 420526f

Browse files
committed
chore: adds kondo files
1 parent afcd9ff commit 420526f

File tree

4 files changed

+162
-0
lines changed

4 files changed

+162
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; Copyright 2024 Nubank NA
2+
3+
; The use and distribution terms for this software are covered by the
4+
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0)
5+
; which can be found in the file epl-v10.html at the root of this distribution.
6+
;
7+
; By using this software in any fashion, you are agreeing to be bound by
8+
; the terms of this license.
9+
;
10+
; You must not remove this notice, or any other, from this software.
11+
12+
{:hooks
13+
{:analyze-call
14+
{io.pedestal.log/trace hooks.io.pedestal.log/log-expr
15+
io.pedestal.log/debug hooks.io.pedestal.log/log-expr
16+
io.pedestal.log/info hooks.io.pedestal.log/log-expr
17+
io.pedestal.log/warn hooks.io.pedestal.log/log-expr
18+
io.pedestal.log/error hooks.io.pedestal.log/log-expr}}}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
; Copyright 2024 Nubank NA
2+
3+
; The use and distribution terms for this software are covered by the
4+
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0)
5+
; which can be found in the file epl-v10.html at the root of this distribution.
6+
;
7+
; By using this software in any fashion, you are agreeing to be bound by
8+
; the terms of this license.
9+
;
10+
; You must not remove this notice, or any other, from this software.
11+
12+
(ns hooks.io.pedestal.log
13+
(:require [clj-kondo.hooks-api :as api]))
14+
15+
(defn log-expr
16+
"Expands (log-expr :a :A :b :B ... )
17+
to (hash-map :a :A :b :B ... ) per clj-kondo examples."
18+
[{:keys [:node]}]
19+
(let [[k v & _kvs] (rest (:children node))]
20+
(when-not (and k v)
21+
(throw (ex-info "No kv pair provided" {})))
22+
(let [new-node (api/list-node
23+
(list*
24+
(api/token-node 'hash-map)
25+
(rest (:children node))))]
26+
{:node (vary-meta new-node assoc :clj-kondo/ignore [:unused-value])})))
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{:lint-as {potemkin.collections/compile-if clojure.core/if
2+
potemkin.collections/reify-map-type clojure.core/reify
3+
potemkin.collections/def-map-type clj-kondo.lint-as/def-catch-all
4+
potemkin.collections/def-derived-map clj-kondo.lint-as/def-catch-all
5+
6+
potemkin.types/reify+ clojure.core/reify
7+
potemkin.types/defprotocol+ clojure.core/defprotocol
8+
potemkin.types/deftype+ clojure.core/deftype
9+
potemkin.types/defrecord+ clojure.core/defrecord
10+
potemkin.types/definterface+ clojure.core/defprotocol
11+
potemkin.types/extend-protocol+ clojure.core/extend-protocol
12+
potemkin.types/def-abstract-type clj-kondo.lint-as/def-catch-all
13+
14+
potemkin.utils/doit clojure.core/doseq
15+
potemkin.utils/doary clojure.core/doseq
16+
potemkin.utils/condp-case clojure.core/condp
17+
potemkin.utils/fast-bound-fn clojure.core/bound-fn
18+
19+
potemkin.walk/prewalk clojure.walk/prewalk
20+
potemkin.walk/postwalk clojure.walk/postwalk
21+
potemkin.walk/walk clojure.walk/walk
22+
23+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
24+
;;;; top-level from import-vars
25+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26+
27+
;; Have hooks
28+
;;potemkin/import-fn potemkin.namespaces/import-fn
29+
;;potemkin/import-macro potemkin.namespaces/import-macro
30+
;;potemkin/import-def potemkin.namespaces/import-def
31+
32+
;; Internal, not transitive
33+
;;potemkin/unify-gensyms potemkin.macros/unify-gensyms
34+
;;potemkin/normalize-gensyms potemkin.macros/normalize-gensyms
35+
;;potemkin/equivalent? potemkin.macros/equivalent?
36+
37+
potemkin/condp-case clojure.core/condp
38+
potemkin/doit potemkin.utils/doit
39+
potemkin/doary potemkin.utils/doary
40+
41+
potemkin/def-abstract-type clj-kondo.lint-as/def-catch-all
42+
potemkin/reify+ clojure.core/reify
43+
potemkin/defprotocol+ clojure.core/defprotocol
44+
potemkin/deftype+ clojure.core/deftype
45+
potemkin/defrecord+ clojure.core/defrecord
46+
potemkin/definterface+ clojure.core/defprotocol
47+
potemkin/extend-protocol+ clojure.core/extend-protocol
48+
49+
potemkin/reify-map-type clojure.core/reify
50+
potemkin/def-derived-map clj-kondo.lint-as/def-catch-all
51+
potemkin/def-map-type clj-kondo.lint-as/def-catch-all}
52+
53+
;; leave import-vars alone, kondo special-cases it
54+
:hooks {:macroexpand {#_#_potemkin.namespaces/import-vars potemkin.namespaces/import-vars
55+
potemkin.namespaces/import-fn potemkin.namespaces/import-fn
56+
potemkin.namespaces/import-macro potemkin.namespaces/import-macro
57+
potemkin.namespaces/import-def potemkin.namespaces/import-def
58+
59+
#_#_potemkin/import-vars potemkin.namespaces/import-vars
60+
potemkin/import-fn potemkin.namespaces/import-fn
61+
potemkin/import-macro potemkin.namespaces/import-macro
62+
potemkin/import-def potemkin.namespaces/import-def}}}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
(ns potemkin.namespaces
2+
(:require [clj-kondo.hooks-api :as api]))
3+
4+
(defn import-macro*
5+
([sym]
6+
`(def ~(-> sym name symbol) ~sym))
7+
([sym name]
8+
`(def ~name ~sym)))
9+
10+
(defmacro import-fn
11+
([sym]
12+
(import-macro* sym))
13+
([sym name]
14+
(import-macro* sym name)))
15+
16+
(defmacro import-macro
17+
([sym]
18+
(import-macro* sym))
19+
([sym name]
20+
(import-macro* sym name)))
21+
22+
(defmacro import-def
23+
([sym]
24+
(import-macro* sym))
25+
([sym name]
26+
(import-macro* sym name)))
27+
28+
#_
29+
(defmacro import-vars
30+
"Imports a list of vars from other namespaces."
31+
[& syms]
32+
(let [unravel (fn unravel [x]
33+
(if (sequential? x)
34+
(->> x
35+
rest
36+
(mapcat unravel)
37+
(map
38+
#(symbol
39+
(str (first x)
40+
(when-let [n (namespace %)]
41+
(str "." n)))
42+
(name %))))
43+
[x]))
44+
syms (mapcat unravel syms)
45+
result `(do
46+
~@(map
47+
(fn [sym]
48+
(let [vr (resolve sym)
49+
m (meta vr)]
50+
(cond
51+
(nil? vr) `(throw (ex-info (format "`%s` does not exist" '~sym) {}))
52+
(:macro m) `(def ~(-> sym name symbol) ~sym)
53+
(:arglists m) `(def ~(-> sym name symbol) ~sym)
54+
:else `(def ~(-> sym name symbol) ~sym))))
55+
syms))]
56+
result))

0 commit comments

Comments
 (0)