-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:active-group/active-clojure
- Loading branch information
Showing
5 changed files
with
96 additions
and
1 deletion.
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
7 changes: 7 additions & 0 deletions
7
resources/clj-kondo.exports/de.active-group/active-clojure/config.edn
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,7 @@ | ||
{:linters {:monad/empty {:level :error}} | ||
:hooks {:analyze-call {active.clojure.monad/monadic hooks.monad/monadic | ||
active.clojure.cljs.record/define-record-type hooks.record/define-record-type | ||
active.clojure.cljs.record/define-singleton-type hooks.record/define-singleton-type | ||
active.clojure.sum-type/define-sum-type hooks.sum-type/define-sum-type | ||
active.clojure.record/define-record-type hooks.record/define-record-type | ||
active.clojure.record/define-singleton-type hooks.record/define-singleton-type}}} |
38 changes: 38 additions & 0 deletions
38
resources/clj-kondo.exports/de.active-group/active-clojure/hooks/monad.clj
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,38 @@ | ||
(ns hooks.monad | ||
(:require [clj-kondo.hooks-api :as api])) | ||
|
||
(defn monadic | ||
[{:keys [:node]}] | ||
(letfn [(rewrite-monadic-form | ||
[forms] | ||
(if (empty? forms) | ||
forms | ||
(let [form (first forms) | ||
forms (rest forms)] | ||
(cond | ||
(= :vector (:tag form)) | ||
(api/list-node | ||
(list (api/token-node 'let) | ||
form | ||
(rewrite-monadic-form forms))) | ||
(and (= :list (:tag form)) | ||
(= 2 (count (:children form))) | ||
(= "let" (:string-value (first (:children form))))) | ||
(api/list-node | ||
(list (first (:children form)) | ||
(second (:children form)) | ||
(rewrite-monadic-form forms))) | ||
:else | ||
(if (empty? forms) | ||
form | ||
(api/list-node | ||
(list (api/token-node 'do) | ||
form | ||
(rewrite-monadic-form forms))))))))] | ||
(let [[& forms] (rest (:children node))] | ||
(if (empty? forms) | ||
(api/reg-finding! (assoc (meta node) | ||
:message "monadic must not be empty" | ||
:type :monad/empty)) | ||
(let [new-node (rewrite-monadic-form forms)] | ||
{:node new-node}))))) |
37 changes: 37 additions & 0 deletions
37
resources/clj-kondo.exports/de.active-group/active-clojure/hooks/record.clj
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,37 @@ | ||
(ns hooks.record | ||
(:require [clj-kondo.hooks-api :as api])) | ||
|
||
(defn define-record-type | ||
[{:keys [:node]}] | ||
(let [[record-name & more] (rest (:children node)) | ||
[constructor-spec predicate field-specs] (if (api/map-node? (first more)) | ||
;; remove options | ||
(rest more) | ||
more) | ||
[constructor & _fields] (if-let [ch (:children constructor-spec)] | ||
ch | ||
[constructor-spec]) | ||
accessors (map second (partition 2 (:children field-specs))) | ||
new-node | ||
(api/list-node | ||
(list* (api/token-node 'do) | ||
(api/list-node [(api/token-node 'declare) record-name]) | ||
(api/list-node [(api/token-node 'declare) predicate]) | ||
(api/list-node [(api/token-node 'declare) constructor]) | ||
(map (fn [t] (api/list-node [(api/token-node 'declare) t])) | ||
(if-let [projection-lens (and (api/map-node? (first more)) | ||
(:projection-lens (api/sexpr (first more))))] | ||
(conj accessors (api/token-node projection-lens)) | ||
accessors))))] | ||
{:node new-node})) | ||
|
||
(defn define-singleton-type | ||
[expr] | ||
(update expr :node | ||
(fn [node] | ||
(let [[record-name singleton predicate] (rest (:children node))] | ||
(api/list-node | ||
(list (api/token-node 'do) | ||
(api/list-node [(api/token-node 'declare) record-name]) | ||
(api/list-node [(api/token-node 'declare) singleton]) | ||
(api/list-node [(api/token-node 'declare) predicate]))))))) |
13 changes: 13 additions & 0 deletions
13
resources/clj-kondo.exports/de.active-group/active-clojure/hooks/sum_type.clj
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,13 @@ | ||
(ns hooks.sum-type | ||
(:require [clj-kondo.hooks-api :as api])) | ||
|
||
(defn define-sum-type | ||
[expr] | ||
(update expr :node | ||
(fn [node] | ||
(let [[sum-type-name predicate] (rest (:children node))] | ||
(api/list-node | ||
(list (api/token-node 'do) | ||
(api/list-node [(api/token-node 'declare) sum-type-name]) | ||
(api/list-node [(api/token-node 'declare) predicate]))))))) | ||
|