-
Notifications
You must be signed in to change notification settings - Fork 175
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 #202 from Garmelon/clj-kondo-support
Add clj-kondo support for defelem and defhtml
- Loading branch information
Showing
5 changed files
with
45 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/hiccup/hiccup"]} |
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 |
---|---|---|
|
@@ -9,3 +9,5 @@ pom.xml.asc | |
*.class | ||
.lein-* | ||
.nrepl-port | ||
.clj-kondo/* | ||
!.clj-kodo/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 |
---|---|---|
@@ -1 +1,2 @@ | ||
{:deps {org.clojure/clojure {:mvn/version "1.7.0"}}} | ||
{:paths ["src" "resources"] | ||
:deps {org.clojure/clojure {:mvn/version "1.7.0"}}} |
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 @@ | ||
{:lint-as {hiccup.def/defhtml clojure.core/defn} | ||
:hooks {:analyze-call {hiccup.def/defelem hiccup.hooks/defelem}}} |
38 changes: 38 additions & 0 deletions
38
resources/clj-kondo.exports/hiccup/hiccup/hiccup/hooks.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 hiccup.hooks | ||
(:require [clj-kondo.hooks-api :as api] | ||
[clojure.set :as set])) | ||
|
||
;; See https://github.com/clj-kondo/clj-kondo/blob/master/doc/hooks.md | ||
|
||
(defn- parse-defn [elems] | ||
(let [[fhead fbody] (split-with #(not (or (api/vector-node? %) | ||
(api/list-node? %))) | ||
elems) | ||
arities (if (api/vector-node? (first fbody)) | ||
(list (api/list-node fbody)) | ||
fbody)] | ||
[fhead arities])) | ||
|
||
(defn- count-args [arity] | ||
(let [args (first (api/sexpr arity))] | ||
(if (= '& (fnext (reverse args))) | ||
true ; unbounded args | ||
(count args)))) | ||
|
||
(defn- dummy-arity [arg-count] | ||
(api/list-node | ||
(list | ||
(api/vector-node | ||
(vec (repeat arg-count (api/token-node '_))))))) | ||
|
||
(defn defelem [{:keys [node]}] | ||
(let [[_ & rest] (:children node) | ||
[fhead arities] (parse-defn rest) | ||
arg-counts (set (filter number? (map count-args arities))) | ||
dummy-arg-counts (set/difference (set (map inc arg-counts)) arg-counts) | ||
dummy-arities (for [n dummy-arg-counts] (dummy-arity n))] | ||
{:node | ||
(api/list-node | ||
(list* | ||
(api/token-node 'clojure.core/defn) | ||
(concat fhead arities dummy-arities)))})) |