Skip to content

Commit

Permalink
Bump lazytest to 1.3.0, include readme tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahTheDuke committed Oct 23, 2024
1 parent 135ff97 commit a466f57
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .clj-kondo/cond_plus/cond_plus/config.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{:linters {:cond-plus/empty-else {:level :error}
:cond-plus/missing-fn {:level :error}
:cond-plus/non-final-else {:level :error}
:cond-plus/sequence {:level :error}
:unresolved-symbol {:exclude [(cond-plus.core/cond+ [=> else])]}}
:hooks {:analyze-call {cond-plus.core/cond+ hooks.cond-plus-hook/cond+}}}
65 changes: 65 additions & 0 deletions .clj-kondo/cond_plus/cond_plus/hooks/cond_plus_hook.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
(ns hooks.cond-plus-hook
(:require [clj-kondo.hooks-api :as api]))

(defn analyze-clauses [clauses]
(reduce
(fn [found-else? clause]
;; non-sequence clause
(if (not (or (api/list-node? clause)
(api/vector-node? clause)))
(let [{:keys [row col]} (meta clause)]
(api/reg-finding!
{:message "must be sequence"
:type :cond-plus/sequence
:row row
:col col})
found-else?)
(let [[sym arrow fn-expr] (api/sexpr clause)]
(cond
;; non-final else
found-else?
(do (api/reg-finding!
(merge
{:message ":else must be in final position"
:type :cond-plus/non-final-else}
found-else?))
(reduced nil))
;; check fn-exprs
(and (or (= :> arrow)
(= '=> arrow))
(nil? fn-expr))
(let [{:keys [row col]} (meta clause)]
(api/reg-finding!
{:message "fn-expr must have third position symbol"
:type :cond-plus/missing-fn
:row row
:col col})
found-else?)
;; else handling
(or (= :else sym)
(= 'else sym))
(if found-else?
(let [{:keys [row col]} (meta clause)]
(api/reg-finding!
{:message "only one :else clause allowed"
:type :cond-plus/empty-else
:row row
:col col})
;; early exit cuz not worth analyzing the rest
(reduced nil))
(do (when-not arrow
(let [{:keys [row col]} (meta clause)]
(api/reg-finding!
{:message ":else must have a body"
:type :cond-plus/empty-else
:row row
:col col})))
;; Store row and col from existing else as we don't throw until
;; we've seen a following clause
(select-keys (meta clause) [:row :col])))))))
nil
clauses))

(defn cond+ [{:keys [node]}]
(analyze-clauses (rest (:children node)))
node)
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ More explicit instructions can be found in the [installation][installation], [us

### Clojure CLI

```clojure
```clojure lazytest/skip=true
:aliases {:splint {:extra-deps {io.github.noahtheduke/splint {:mvn/version "1.18.0"}
org.clojure/clojure {:mvn/version "1.11.1"}}
:main-opts ["-m" "noahtheduke.splint"]}}
Expand All @@ -32,7 +32,7 @@ Run with `clojure -M:splint [args...]`.

Add this to `project.clj`:

```clojure
```clojure lazytest/skip=true
:profiles {:dev {:dependencies [[io.github.noahtheduke/splint "1.18.0"]
[org.clojure/clojure "1.11.1"]]}}
:aliases {"splint" ["run" "-m" "noahtheduke.splint"]})
Expand Down
2 changes: 1 addition & 1 deletion deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"-f" "rebel-readline.main/-main"]}
:test {:extra-paths ["test"]
:extra-deps {nubank/matcher-combinators {:mvn/version "3.9.1"}
io.github.noahtheduke/lazytest {:mvn/version "1.2.0"}}}
io.github.noahtheduke/lazytest {:mvn/version "1.3.0"}}}
:runner {:main-opts ["-m" "lazytest.main"]}
:profile {:extra-deps {com.clojure-goes-fast/clj-async-profiler {:mvn/version "1.2.2"}
com.clojure-goes-fast/clj-memory-meter {:mvn/version "0.3.0"}}
Expand Down
8 changes: 6 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,19 @@ clj-kondo:
clojure-lsp:
clojure-lsp diagnostics

[no-exit-message]
@test-raw *args:
clojure -M:dev:test:runner --md README.md {{args}}

[no-exit-message]
test *args="--output dots":
clojure -M:dev:test:runner -e :integration {{args}}
just test-raw -e :integration {{args}}

[no-exit-message]
test-all *args="--output dots":
just clojure-lsp
bb run splint
clojure -M:dev:test:runner {{args}}
just test-raw {{args}}

@new-rule arg:
clojure -M:new-rule -n {{arg}}
Expand Down

0 comments on commit a466f57

Please sign in to comment.