From 240b3bffe9539e6bbe76c46bcc6f96eb0abc9c2d Mon Sep 17 00:00:00 2001 From: Laurence Chen Date: Thu, 4 Sep 2025 14:54:33 +0800 Subject: [PATCH 1/3] `clj-kondo` config to make ornament components play nice with linting --- .clj-kondo/config.edn | 3 +++ .clj-kondo/hooks/ornament.clj | 42 +++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 .clj-kondo/config.edn create mode 100644 .clj-kondo/hooks/ornament.clj diff --git a/.clj-kondo/config.edn b/.clj-kondo/config.edn new file mode 100644 index 0000000..4585c52 --- /dev/null +++ b/.clj-kondo/config.edn @@ -0,0 +1,3 @@ +{:lint-as {lambdaisland.ornament/defprop clojure.core/def + lambdaisland.ornament/defrules clojure.core/def} + :hooks {:analyze-call {lambdaisland.ornament/defstyled hooks.ornament/defstyled}}} diff --git a/.clj-kondo/hooks/ornament.clj b/.clj-kondo/hooks/ornament.clj new file mode 100644 index 0000000..4927548 --- /dev/null +++ b/.clj-kondo/hooks/ornament.clj @@ -0,0 +1,42 @@ +(ns hooks.ornament + (:require [clj-kondo.hooks-api :as api])) + +(defn defstyled [{:keys [node]}] + (let [[class-name html-tag & more] (rest (:children node)) + _ (when-not (and (api/token-node? class-name) + (simple-symbol? (api/sexpr class-name))) + (api/reg-finding! {:row (:row (meta class-name)) + :col (:col (meta class-name)) + :message "Style name must be a symbol" + :type :lambdaisland.ornament/invalid-syntax})) + ; _ (prn :class-name class-name) + _ (when-not (api/keyword-node? html-tag) + (api/reg-finding! {:row (:row (meta html-tag)) + :col (:col (meta html-tag)) + :message "Html-tag must be a keyword" + :type :lambdaisland.ornament/invalid-syntax})) + ; _ (prn :html-tag html-tag) + ; _ (prn :more more) + fn-tag (first (drop-while (fn [x] + (or (api/keyword-node? x) + (api/map-node? x) + (api/vector-node? x))) + more)) + _ (prn :fn-tag fn-tag) + _ (when (or (api/list-node? fn-tag) + (nil? fn-tag)) + (api/reg-finding! {:row (:row (meta fn-tag)) + :col (:col (meta fn-tag)) + :message "fn-tag must be at least a list or nil" + :type :lambdaisland.ornament/invalid-syntax}))] + (if (api/list-node? fn-tag) + (let [[binding-vec & body] (:children fn-tag) + new-node (api/list-node + (list* + (api/token-node 'fn) + binding-vec + body))] + (prn :new-node (api/sexpr new-node)) + {:node new-node}) + ;; nil node + {:node true}))) From f5a12362c7666f3cbbf2a99489db8c4b9e870a85 Mon Sep 17 00:00:00 2001 From: Laurence Chen Date: Thu, 4 Sep 2025 15:02:38 +0800 Subject: [PATCH 2/3] add how to use .clj-kondo part to README --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 8efac90..f3a33da 100644 --- a/README.md +++ b/README.md @@ -943,6 +943,14 @@ And get a bullet list which uses bear emojis for the bullets. Girouette provides. You can change that by adding a `^:replace` tag (this uses meta-merge). e.g. `{:colors ^:replace {...}}`) +## clj-kondo Support + +This library includes a built-in clj-kondo configuration to improve linting for Ornament components. + +To use the configuration, simply copy the .clj-kondo/ directory from this repository into the root of your project. + +After copying the directory, clj-kondo will automatically use this configuration to provide more accurate linting and reduce false positives in your Ornament projects. + ## Babashka compatibility Unfortunately Ornament is not bb-compatible, and most likely never will be. From 4e568f750bf726b1ad22b8b0ec8793debd108b7e Mon Sep 17 00:00:00 2001 From: Laurence Chen Date: Thu, 4 Sep 2025 15:28:04 +0800 Subject: [PATCH 3/3] fix github workflow yaml --- .github/workflows/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bc5bda6..5d070f5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -33,7 +33,7 @@ jobs: cli: '1.10.3.943' - name: 🗝 maven cache - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: | ~/.m2 @@ -64,7 +64,7 @@ jobs: cli: '1.10.3.943' - name: 🗝 maven cache - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: | ~/.m2 @@ -74,7 +74,7 @@ jobs: ${{ runner.os }}-maven- - name: 🗝 Clerk Cache - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: .clerk key: ${{ runner.os }}-clerk-cache