Skip to content

Commit 2e09299

Browse files
committed
addresses #1 improve clj-kondo support
Signed-off-by: Sean Corfield <[email protected]>
1 parent 025f62b commit 2e09299

File tree

6 files changed

+27
-11
lines changed

6 files changed

+27
-11
lines changed

deps.edn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{:paths ["src"]
1+
{:paths ["src" "resources"]
22
:deps {org.clojure/clojure {:mvn/version "1.8.0"}}
33

44
:aliases

resources/clj-kondo.exports/org.clj-commons/slingshot/clj_kondo/clj_commons/slingshot/try_plus.clj

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
1313
(api/vector-node [selector (api/token-node nil)])
1414
exprs))]))
1515
(seq? catchee-sexpr)
16-
(api/list-node
17-
(list* catch (api/token-node 'Exception) (api/token-node '_e#)
18-
(api/list-node
19-
(list (api/token-node 'fn)
20-
(api/vector-node [(api/token-node '%)])
21-
catchee))
22-
exprs))
16+
(let [[v & exprs] exprs]
17+
(api/list-node
18+
(list* catch (api/token-node 'Exception) v
19+
(api/list-node
20+
(list (api/token-node 'fn)
21+
(api/vector-node [(api/token-node '%)])
22+
catchee))
23+
exprs)))
2324
:else catch-node)))
2425

2526
(defn try+ [{:keys [node]}]

src/clj_commons/slingshot/test.clj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
(pr-str e#) '~selector)})
2323
e#))))
2424

25+
(defmacro thrown+?
26+
"(is (thrown+? selector expr))"
27+
[_selector _expr]
28+
(throw (IllegalStateException.
29+
"thrown+? must be used inside an 'is' form")))
30+
2531
(defmethod assert-expr 'thrown+-with-msg? [msg form]
2632
;; (is (thrown+-with-msg? s re expr))
2733
;; Asserts that evaluating expr throws an object that matches
@@ -47,3 +53,9 @@
4753
:actual (format "thrown+-with-msg?: %s did not match %s"
4854
(pr-str e#) '~selector)})
4955
e#))))
56+
57+
(defmacro thrown+-with-msg?
58+
"(is (thrown+-with-msg? selector pattern expr))"
59+
[_selector _pattern _expr]
60+
(throw (IllegalStateException.
61+
"thrown+-with-msg? must be used inside an 'is' form")))

test/clj_commons/slingshot/support_test.clj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
(ns clj-commons.slingshot.support-test
22
(:require
33
[clj-commons.slingshot :refer [throw+ try+]]
4-
[clj-commons.slingshot.support :refer :all]
4+
[clj-commons.slingshot.support :refer [*catch-hook* *throw-hook* parse-try+
5+
resolve-local stack-trace wrap]]
56
[clojure.test :refer [deftest is]]))
67

78
(deftest test-parse-try+
@@ -54,6 +55,7 @@
5455
(deftest test-resolve-local
5556
(let [a 4]
5657
(is (= 4 (resolve-local a)))
58+
#_{:clj-kondo/ignore [:unresolved-symbol]}
5759
(is (nil? (resolve-local b)))))
5860

5961
(deftest test-wrap
@@ -80,7 +82,7 @@
8082
(is (= (set (keys @test-hooked))
8183
(set [:object :message :cause :stack-trace])))
8284
(is (= "throw-hook-string" (:object @test-hooked))))
83-
(binding [*throw-hook* (fn [x] 42)]
85+
(binding [*throw-hook* (fn [_] 42)]
8486
(is (= (throw+ "something") 42))))
8587

8688
(def catch-hooked (atom nil))

test/clj_commons/slingshot/test_test.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(ns clj-commons.slingshot.test-test
22
(:require
33
[clj-commons.slingshot :refer [throw+]]
4-
[clj-commons.slingshot.test]
4+
[clj-commons.slingshot.test :refer [thrown+? thrown+-with-msg?]]
55
[clojure.test :refer [deftest is]]))
66

77
(deftest test-slingshot-test-macros

test/clj_commons/slingshot_test.clj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
(try (throw exception-1)
8282
(catch Exception e [:class-exception e])))))
8383
(testing "IllegalArgumentException thrown by clojure/core"
84+
#_{:clj-kondo/ignore [:type-mismatch]}
8485
(is (= :class-iae (first (mega-try (str/replace "foo" 1 1)))))))
8586

8687
(testing "catch by java class generically"

0 commit comments

Comments
 (0)