-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1de9d9b
commit df773c3
Showing
14 changed files
with
380 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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+}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.