diff --git a/dev/compojure_api_dev/expand_kondo_feature.clj b/dev/compojure_api_dev/expand_kondo_feature.clj new file mode 100644 index 00000000..57c44319 --- /dev/null +++ b/dev/compojure_api_dev/expand_kondo_feature.clj @@ -0,0 +1,9 @@ +(ns compojure-api-dev.expand-kondo-feature) + +(defn visit-forms-in-file [file] + {:pre [(string? file)]} + (spit (str/replace "\n" new-forms) + file)) + +(defn -main [& files] + (run! visit-forms-in-file files)) diff --git a/project.clj b/project.clj index ac12927b..e9cad8a5 100644 --- a/project.clj +++ b/project.clj @@ -47,8 +47,13 @@ [criterium "0.4.5"]] :ring {:handler examples.thingie/app :reload-paths ["src" "examples/thingie/src"]} - :source-paths ["examples/thingie/src" "examples/thingie/dev-src"] + :source-paths ["examples/thingie/src" + "examples/thingie/dev-src" + "dev"] :main examples.server} + :expand-kondo-feature {:source-paths ["dev"] + :dependencies [[org.clojure/tools.reader "1.5.0"] + [org.clojure/tools.namespace "1.5.0"]]} :perf {:jvm-opts ^:replace ["-server" "-Xmx4096m" "-Dclojure.compiler.direct-linking=true"]} diff --git a/resources/clj-kondo.exports/metosin/compojure-api/compojure/api/common.clj b/resources/clj-kondo.exports/metosin/compojure-api/compojure/api/common.clj index 23951dd5..78a21197 100644 --- a/resources/clj-kondo.exports/metosin/compojure-api/compojure/api/common.clj +++ b/resources/clj-kondo.exports/metosin/compojure-api/compojure/api/common.clj @@ -1,5 +1,5 @@ (ns compojure.api.common - #?@(:bb [] + #?@(:default [] :default [(:require [linked.core :as linked])])) (defn plain-map? @@ -52,7 +52,7 @@ x y)) -#?(:bb nil +#?(:default nil :default (defn fifo-memoize [f size] "Returns a memoized version of a referentially transparent f. The diff --git a/resources/clj-kondo.exports/metosin/compojure-api/compojure/api/core.clj b/resources/clj-kondo.exports/metosin/compojure-api/compojure/api/core.clj index 74db7e9e..5ecbacff 100644 --- a/resources/clj-kondo.exports/metosin/compojure-api/compojure/api/core.clj +++ b/resources/clj-kondo.exports/metosin/compojure-api/compojure/api/core.clj @@ -1,11 +1,10 @@ -;; :bb reader feature assumes clj-kondo (ns compojure.api.core (:require [compojure.api.meta :as meta] - #?@(:bb [] + #?@(:default [] :default [[compojure.api.async] [compojure.core :as compojure]]) - [compojure.api.routes #?(:bb :as-alias :default :as) routes] - [compojure.api.middleware #?(:bb :as-alias :default :as) mw])) + [compojure.api.routes #?(:default :as-alias :default :as) routes] + [compojure.api.middleware #?(:default :as-alias :default :as) mw])) (defn ring-handler "Creates vanilla ring-handler from any invokable thing (e.g. compojure-api route)" @@ -17,7 +16,7 @@ (defn routes "Create a Ring handler by combining several handlers into one." [& handlers] - #?(:bb (throw (ex-info "Not supported in bb")) + #?(:default (throw (ex-info "Not supported in bb")) :default (let [handlers (seq (keep identity (flatten handlers)))] (routes/map->Route {:childs (vec handlers) @@ -43,7 +42,7 @@ "Routes without route-documentation. Can be used to wrap routes, not satisfying compojure.api.routes/Routing -protocol." [& handlers] - #?(:bb (throw (ex-info "Not supported in bb")) + #?(:default (throw (ex-info "Not supported in bb")) :default (let [handlers (keep identity handlers)] (routes/map->Route {:handler (meta/routing handlers)})))) @@ -70,7 +69,7 @@ {:style/indent 1 :supercedes "middleware"} [middleware & body] - #?(:bb (throw (ex-info "Not supported in bb")) + #?(:default (throw (ex-info "Not supported in bb")) :default (let [handler (apply routes body) x-handler (compojure/wrap-routes handler (mw/compose-middleware middleware))] @@ -79,13 +78,13 @@ {:childs [handler] :handler x-handler})))) -(defmacro context {:style/indent 2} [& args] (meta/restructure nil args {:context? true :&form &form :&env &env :kondo-rule? #?(:bb true :default false)})) +(defmacro context {:style/indent 2} [& args] (meta/restructure nil args {:context? true :&form &form :&env &env :kondo-rule? #?(:default true :default false)})) -(defmacro GET {:style/indent 2} [& args] (meta/restructure :get args #?(:bb {:kondo-rule? true} :default nil))) -(defmacro ANY {:style/indent 2} [& args] (meta/restructure nil args #?(:bb {:kondo-rule? true} :default nil))) -(defmacro HEAD {:style/indent 2} [& args] (meta/restructure :head args #?(:bb {:kondo-rule? true} :default nil))) -(defmacro PATCH {:style/indent 2} [& args] (meta/restructure :patch args #?(:bb {:kondo-rule? true} :default nil))) -(defmacro DELETE {:style/indent 2} [& args] (meta/restructure :delete args #?(:bb {:kondo-rule? true} :default nil))) -(defmacro OPTIONS {:style/indent 2} [& args] (meta/restructure :options args #?(:bb {:kondo-rule? true} :default nil))) -(defmacro POST {:style/indent 2} [& args] (meta/restructure :post args #?(:bb {:kondo-rule? true} :default nil))) -(defmacro PUT {:style/indent 2} [& args] (meta/restructure :put args #?(:bb {:kondo-rule? true} :default nil))) +(defmacro GET {:style/indent 2} [& args] (meta/restructure :get args #?(:default {:kondo-rule? true} :default nil))) +(defmacro ANY {:style/indent 2} [& args] (meta/restructure nil args #?(:default {:kondo-rule? true} :default nil))) +(defmacro HEAD {:style/indent 2} [& args] (meta/restructure :head args #?(:default {:kondo-rule? true} :default nil))) +(defmacro PATCH {:style/indent 2} [& args] (meta/restructure :patch args #?(:default {:kondo-rule? true} :default nil))) +(defmacro DELETE {:style/indent 2} [& args] (meta/restructure :delete args #?(:default {:kondo-rule? true} :default nil))) +(defmacro OPTIONS {:style/indent 2} [& args] (meta/restructure :options args #?(:default {:kondo-rule? true} :default nil))) +(defmacro POST {:style/indent 2} [& args] (meta/restructure :post args #?(:default {:kondo-rule? true} :default nil))) +(defmacro PUT {:style/indent 2} [& args] (meta/restructure :put args #?(:default {:kondo-rule? true} :default nil))) diff --git a/resources/clj-kondo.exports/metosin/compojure-api/compojure/api/meta.clj b/resources/clj-kondo.exports/metosin/compojure-api/compojure/api/meta.clj index fee947cf..ba00d78f 100644 --- a/resources/clj-kondo.exports/metosin/compojure-api/compojure/api/meta.clj +++ b/resources/clj-kondo.exports/metosin/compojure-api/compojure/api/meta.clj @@ -320,7 +320,7 @@ swagger (-> (dissoc :swagger) (rsc/deep-merge swagger)))) (defn restructure [method [path arg & args] {:keys [context? kondo-rule?]}] - #?(:bb (assert kondo-rule?) + #?(:default (assert kondo-rule?) :default nil) (let [[options body] (extract-parameters args true) [path-string lets arg-with-request arg] (destructure-compojure-api-request path arg) diff --git a/scripts/regen-kondo.clj b/scripts/regen-kondo.clj index bf3b7771..01e946d6 100755 --- a/scripts/regen-kondo.clj +++ b/scripts/regen-kondo.clj @@ -6,8 +6,3 @@ rm -r resources/clj-kondo.exports mkdir -p resources/clj-kondo.exports/metosin/compojure-api/compojure/api bb -f ./scripts/regen_kondo_config.clj - -# rename to .clj -cp src/compojure/api/common.cljc resources/clj-kondo.exports/metosin/compojure-api/compojure/api/common.clj -cp src/compojure/api/core.cljc resources/clj-kondo.exports/metosin/compojure-api/compojure/api/core.clj -cp src/compojure/api/meta.cljc resources/clj-kondo.exports/metosin/compojure-api/compojure/api/meta.clj diff --git a/scripts/regen_kondo_config.clj b/scripts/regen_kondo_config.clj index 8cc9f77e..0e0a7c9f 100755 --- a/scripts/regen_kondo_config.clj +++ b/scripts/regen_kondo_config.clj @@ -1,8 +1,19 @@ #!/usr/bin/env bb -(ns regen-kondo-config) +(ns regen-kondo-config + (:require [clojure.string :as str])) + +(def renames + ;; rename to .clj + {"src/compojure/api/common.cljc" "resources/clj-kondo.exports/metosin/compojure-api/compojure/api/common.clj" + "src/compojure/api/core.cljc" "resources/clj-kondo.exports/metosin/compojure-api/compojure/api/core.clj" + "src/compojure/api/meta.cljc" "resources/clj-kondo.exports/metosin/compojure-api/compojure/api/meta.clj"}) + (defn -main [& args] + (doseq [[from to] renames] + (spit to + (str/replace (slurp from) ":clj-kondo" ":default"))) (spit "resources/clj-kondo.exports/metosin/compojure-api/config.edn" '{:hooks {:macroexpand diff --git a/src/compojure/api/common.cljc b/src/compojure/api/common.cljc index 23951dd5..0e57af50 100644 --- a/src/compojure/api/common.cljc +++ b/src/compojure/api/common.cljc @@ -1,5 +1,5 @@ (ns compojure.api.common - #?@(:bb [] + #?@(:clj-kondo [] :default [(:require [linked.core :as linked])])) (defn plain-map? @@ -52,7 +52,7 @@ x y)) -#?(:bb nil +#?(:clj-kondo nil :default (defn fifo-memoize [f size] "Returns a memoized version of a referentially transparent f. The diff --git a/src/compojure/api/core.cljc b/src/compojure/api/core.cljc index 74db7e9e..2337bd36 100644 --- a/src/compojure/api/core.cljc +++ b/src/compojure/api/core.cljc @@ -1,11 +1,10 @@ -;; :bb reader feature assumes clj-kondo (ns compojure.api.core (:require [compojure.api.meta :as meta] - #?@(:bb [] + #?@(:clj-kondo [] :default [[compojure.api.async] [compojure.core :as compojure]]) - [compojure.api.routes #?(:bb :as-alias :default :as) routes] - [compojure.api.middleware #?(:bb :as-alias :default :as) mw])) + [compojure.api.routes #?(:clj-kondo :as-alias :default :as) routes] + [compojure.api.middleware #?(:clj-kondo :as-alias :default :as) mw])) (defn ring-handler "Creates vanilla ring-handler from any invokable thing (e.g. compojure-api route)" @@ -17,7 +16,7 @@ (defn routes "Create a Ring handler by combining several handlers into one." [& handlers] - #?(:bb (throw (ex-info "Not supported in bb")) + #?(:clj-kondo (throw (ex-info "Not supported in bb")) :default (let [handlers (seq (keep identity (flatten handlers)))] (routes/map->Route {:childs (vec handlers) @@ -43,7 +42,7 @@ "Routes without route-documentation. Can be used to wrap routes, not satisfying compojure.api.routes/Routing -protocol." [& handlers] - #?(:bb (throw (ex-info "Not supported in bb")) + #?(:clj-kondo (throw (ex-info "Not supported in bb")) :default (let [handlers (keep identity handlers)] (routes/map->Route {:handler (meta/routing handlers)})))) @@ -70,7 +69,7 @@ {:style/indent 1 :supercedes "middleware"} [middleware & body] - #?(:bb (throw (ex-info "Not supported in bb")) + #?(:clj-kondo (throw (ex-info "Not supported in bb")) :default (let [handler (apply routes body) x-handler (compojure/wrap-routes handler (mw/compose-middleware middleware))] @@ -79,13 +78,13 @@ {:childs [handler] :handler x-handler})))) -(defmacro context {:style/indent 2} [& args] (meta/restructure nil args {:context? true :&form &form :&env &env :kondo-rule? #?(:bb true :default false)})) +(defmacro context {:style/indent 2} [& args] (meta/restructure nil args {:context? true :&form &form :&env &env :kondo-rule? #?(:clj-kondo true :default false)})) -(defmacro GET {:style/indent 2} [& args] (meta/restructure :get args #?(:bb {:kondo-rule? true} :default nil))) -(defmacro ANY {:style/indent 2} [& args] (meta/restructure nil args #?(:bb {:kondo-rule? true} :default nil))) -(defmacro HEAD {:style/indent 2} [& args] (meta/restructure :head args #?(:bb {:kondo-rule? true} :default nil))) -(defmacro PATCH {:style/indent 2} [& args] (meta/restructure :patch args #?(:bb {:kondo-rule? true} :default nil))) -(defmacro DELETE {:style/indent 2} [& args] (meta/restructure :delete args #?(:bb {:kondo-rule? true} :default nil))) -(defmacro OPTIONS {:style/indent 2} [& args] (meta/restructure :options args #?(:bb {:kondo-rule? true} :default nil))) -(defmacro POST {:style/indent 2} [& args] (meta/restructure :post args #?(:bb {:kondo-rule? true} :default nil))) -(defmacro PUT {:style/indent 2} [& args] (meta/restructure :put args #?(:bb {:kondo-rule? true} :default nil))) +(defmacro GET {:style/indent 2} [& args] (meta/restructure :get args #?(:clj-kondo {:kondo-rule? true} :default nil))) +(defmacro ANY {:style/indent 2} [& args] (meta/restructure nil args #?(:clj-kondo {:kondo-rule? true} :default nil))) +(defmacro HEAD {:style/indent 2} [& args] (meta/restructure :head args #?(:clj-kondo {:kondo-rule? true} :default nil))) +(defmacro PATCH {:style/indent 2} [& args] (meta/restructure :patch args #?(:clj-kondo {:kondo-rule? true} :default nil))) +(defmacro DELETE {:style/indent 2} [& args] (meta/restructure :delete args #?(:clj-kondo {:kondo-rule? true} :default nil))) +(defmacro OPTIONS {:style/indent 2} [& args] (meta/restructure :options args #?(:clj-kondo {:kondo-rule? true} :default nil))) +(defmacro POST {:style/indent 2} [& args] (meta/restructure :post args #?(:clj-kondo {:kondo-rule? true} :default nil))) +(defmacro PUT {:style/indent 2} [& args] (meta/restructure :put args #?(:clj-kondo {:kondo-rule? true} :default nil))) diff --git a/src/compojure/api/meta.cljc b/src/compojure/api/meta.cljc index fee947cf..788819ab 100644 --- a/src/compojure/api/meta.cljc +++ b/src/compojure/api/meta.cljc @@ -320,7 +320,7 @@ swagger (-> (dissoc :swagger) (rsc/deep-merge swagger)))) (defn restructure [method [path arg & args] {:keys [context? kondo-rule?]}] - #?(:bb (assert kondo-rule?) + #?(:clj-kondo (assert kondo-rule?) :default nil) (let [[options body] (extract-parameters args true) [path-string lets arg-with-request arg] (destructure-compojure-api-request path arg)