-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from PEZ/add-clj-kondo-config
Add clj-kondo hook and config for linting `defcomponent`
- Loading branch information
Showing
6 changed files
with
87 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{:config-paths ["../resources/clj-kondo.exports/cjohansen/dumdom"]} |
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 |
---|---|---|
|
@@ -6,3 +6,4 @@ target | |
checkouts | ||
.cpcache | ||
cljs-test-runner-out | ||
.clj-kondo/cjohansen/dumdom |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{:linters {:dumdom/component-options {:level :warning}} | ||
:hooks {:analyze-call {dumdom.core/defcomponent dumdom.defcomponent/defcomponent}}} |
69 changes: 69 additions & 0 deletions
69
resources/clj-kondo.exports/cjohansen/dumdom/dumdom/defcomponent.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,69 @@ | ||
(comment ; add-libs | ||
'{:deps {clj-kondo/clj-kondo {:mvn/version "2024.02.12"}}}) | ||
|
||
(ns dumdom.defcomponent | ||
(:require [clj-kondo.hooks-api :as api])) | ||
|
||
(def valid-opts #{:on-mount | ||
:on-update | ||
:on-render | ||
:on-unmount | ||
:will-appear | ||
:did-appear | ||
:will-enter | ||
:did-enter | ||
:will-leave | ||
:did-leave | ||
:name}) | ||
|
||
(defn- extract-docstr | ||
[[docstr? & forms :as remaining-forms]] | ||
(if (api/string-node? docstr?) | ||
[docstr? forms] | ||
[(api/string-node "no docs") remaining-forms])) | ||
|
||
(defn- extract-opts | ||
([forms] | ||
(extract-opts forms [])) | ||
([[k v & forms :as remaining-forms] opts] | ||
(if (api/keyword-node? k) | ||
(do | ||
(when-not (valid-opts (api/sexpr k)) | ||
(api/reg-finding! (assoc (meta k) | ||
:message (str "Invalid option: `" k "`") | ||
:type :dumdom/component-options))) | ||
(extract-opts forms (into opts [k v]))) | ||
[(api/map-node opts) remaining-forms]))) | ||
|
||
(defn ^:export defcomponent [{:keys [node]}] | ||
(let [[name & forms] (rest (:children node)) | ||
[docstr forms] (extract-docstr forms) | ||
[opts forms] (extract-opts forms) | ||
new-node (api/list-node | ||
(list* | ||
(api/token-node 'defn) | ||
name | ||
docstr | ||
opts | ||
forms))] | ||
{:node new-node})) | ||
|
||
(comment | ||
(def code (str '(defcomponent heading | ||
"" | ||
:on-render (fn [dom-node val old-val]) | ||
:invalid (fn []) | ||
[data] | ||
(def data data) | ||
[:h2 {:style {:background :black | ||
:color :white}} | ||
(pr-str (:text data))]))) | ||
|
||
(defcomponent {:node (api/parse-string code)}) | ||
|
||
(require '[clj-kondo.core :as clj-kondo]) | ||
(:findings (with-in-str (str "(require '[dumdom.core :refer [defcomponent]])" | ||
" " | ||
code) | ||
(clj-kondo/run! {:lint ["-"]}))) | ||
:rcf) |