mirror of
https://github.com/metosin/reitit.git
synced 2026-01-12 01:49:51 +00:00
Merge pull request #771 from mthl/lint
Fix linting issues and run Clj-kondo in CI
This commit is contained in:
commit
8907dfc5f5
22 changed files with 76 additions and 63 deletions
|
|
@ -1,5 +1,6 @@
|
|||
{;;:skip-comments true
|
||||
:lint-as {potemkin/def-derived-map clojure.core/defrecord}
|
||||
:lint-as {potemkin/def-derived-map clojure.core/defrecord
|
||||
clojure.test.check.clojure-test/defspec clojure.test/deftest}
|
||||
:linters {:missing-else-branch {:level :off}
|
||||
:unused-binding {:level :off}
|
||||
:unused-referred-var {:exclude {clojure.test [deftest testing is are]
|
||||
|
|
|
|||
4
.github/workflows/testsuite.yml
vendored
4
.github/workflows/testsuite.yml
vendored
|
|
@ -36,12 +36,16 @@ jobs:
|
|||
uses: DeLaGuardo/setup-clojure@13.1
|
||||
with:
|
||||
lein: 2.9.5
|
||||
clj-kondo: 2025.12.23
|
||||
|
||||
# Install openapi-schema-validator for openapi-tests
|
||||
# Uses node version from the ubuntu-latest
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Run Linter
|
||||
run: ./lint.sh
|
||||
|
||||
- name: Run tests
|
||||
run: ./scripts/test.sh clj
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
(ns frontend-re-frame.core
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[reagent.core :as reagent]
|
||||
[reagent.dom :as rd]
|
||||
[reitit.core :as r]
|
||||
[reitit.coercion.spec :as rss]
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@
|
|||
[reitit.ring.middleware.multipart :as multipart]
|
||||
[reitit.ring.middleware.parameters :as parameters]
|
||||
[ring.adapter.jetty :as jetty]
|
||||
[malli.core :as malli]
|
||||
[muuntaja.core :as m]))
|
||||
|
||||
(def Transaction
|
||||
|
|
|
|||
|
|
@ -244,7 +244,7 @@
|
|||
(if coercer
|
||||
(let [result (coercer query-params :default)]
|
||||
(if (error? result)
|
||||
(throw (ex-info (str "Query parameters coercion failed")
|
||||
(throw (ex-info "Query parameters coercion failed"
|
||||
result))
|
||||
result))
|
||||
query-params))))
|
||||
|
|
|
|||
|
|
@ -7,6 +7,10 @@
|
|||
([type data]
|
||||
(throw (ex-info (str type) {:type type, :data data}))))
|
||||
|
||||
(defn unsupported-protocol-method!
|
||||
[method]
|
||||
(fail! :unsupported-protocol-method {:method method}))
|
||||
|
||||
(defn get-message [e]
|
||||
#?(:clj (.getMessage ^Exception e) :cljs (ex-message e)))
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
(ns ^:no-doc reitit.impl
|
||||
#?(:cljs (:require-macros [reitit.impl]))
|
||||
(:require [clojure.set :as set]
|
||||
[clojure.string :as str]
|
||||
(:require [clojure.string :as str]
|
||||
[meta-merge.core :as mm]
|
||||
[reitit.exception :as ex]
|
||||
[reitit.trie :as trie])
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@
|
|||
;; TODO: this is hack, but seems to work and is safe.
|
||||
(defn source-str [[target _ file line]]
|
||||
(try
|
||||
(if (and (not= 1 line))
|
||||
(if (not= 1 line)
|
||||
(let [file-name (str/replace file #"(.*?)\.\S[^\.]+" "$1")
|
||||
target-name (name target)
|
||||
ns (str (subs target-name 0 (or (str/index-of target-name (str file-name "$")) 0)) file-name)]
|
||||
|
|
@ -190,7 +190,7 @@
|
|||
(color :title message " ")
|
||||
(color :title-dark (repeat-str "-" between) " ")
|
||||
(color :title source) " "
|
||||
(color :title-dark (str "--"))]))
|
||||
(color :title-dark "--")]))
|
||||
|
||||
(defn footer [{:keys [width]}]
|
||||
(color :title-dark (repeat-str "-" width)))
|
||||
|
|
|
|||
|
|
@ -22,12 +22,12 @@
|
|||
compile (fn [[path data] opts scope]
|
||||
(interceptor/compile-result [path data] opts scope))
|
||||
->endpoint (fn [p d m s]
|
||||
(let [d (ring/-compile-coercion d)]
|
||||
(let [compiled (compile [p d] opts s)]
|
||||
(-> compiled
|
||||
(map->Endpoint)
|
||||
(assoc :path p)
|
||||
(assoc :method m)))))
|
||||
(let [d (ring/-compile-coercion d)
|
||||
compiled (compile [p d] opts s)]
|
||||
(-> compiled
|
||||
(map->Endpoint)
|
||||
(assoc :path p)
|
||||
(assoc :method m))))
|
||||
->methods (fn [any? data]
|
||||
(reduce
|
||||
(fn [acc method]
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@
|
|||
(:require [io.pedestal.http :as http]
|
||||
[io.pedestal.interceptor :as interceptor]
|
||||
[io.pedestal.interceptor.chain :as chain]
|
||||
[reitit.exception :as ex]
|
||||
[reitit.http]
|
||||
[reitit.interceptor])
|
||||
(:import (java.lang.reflect Method)
|
||||
(reitit.interceptor Executor)))
|
||||
(:import (java.lang.reflect Method)))
|
||||
|
||||
;; TODO: variadic
|
||||
(defn- arities [f]
|
||||
|
|
@ -46,12 +46,16 @@
|
|||
|
||||
(def pedestal-executor
|
||||
(reify
|
||||
Executor
|
||||
reitit.interceptor/Executor
|
||||
(queue [_ interceptors]
|
||||
(->> interceptors
|
||||
(map (fn [{::interceptor/keys [handler] :as interceptor}]
|
||||
(or handler interceptor)))
|
||||
(keep ->interceptor)))
|
||||
(execute [_ _ _]
|
||||
(ex/unsupported-protocol-method! 'reitit.interceptor/execute))
|
||||
(execute [_ _ _ _ _]
|
||||
(ex/unsupported-protocol-method! 'reitit.interceptor/execute))
|
||||
(enqueue [_ context interceptors]
|
||||
(chain/enqueue context interceptors))))
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
(ns reitit.interceptor.sieppari
|
||||
(:require [reitit.interceptor :as interceptor]
|
||||
(:require [reitit.exception :as ex]
|
||||
[reitit.interceptor :as interceptor]
|
||||
[sieppari.core :as sieppari]
|
||||
[sieppari.queue :as queue]))
|
||||
|
||||
|
|
@ -15,4 +16,6 @@
|
|||
(execute [_ interceptors request]
|
||||
(sieppari/execute interceptors request))
|
||||
(execute [_ interceptors request respond raise]
|
||||
(sieppari/execute interceptors request respond raise))))
|
||||
(sieppari/execute interceptors request respond raise))
|
||||
(enqueue [_ _ _]
|
||||
(ex/unsupported-protocol-method! 'reitit.interceptor/enqueue))))
|
||||
|
|
|
|||
|
|
@ -80,12 +80,15 @@
|
|||
(defrecord NoOpCoercion []
|
||||
coercion/Coercion
|
||||
(-get-name [_] :no-op)
|
||||
(-get-options [_])
|
||||
(-get-apidocs [_ _ {:keys [parameters responses] :as info}])
|
||||
(-get-model-apidocs [_ _ _ _])
|
||||
(-compile-model [_ model _] model)
|
||||
(-open-model [_ spec] spec)
|
||||
(-encode-error [_ error] error)
|
||||
(-request-coercer [_ type spec] (fn [value format] value))
|
||||
(-response-coercer [this spec] (coercion/request-coercer this :response spec {})))
|
||||
(-response-coercer [this spec] (coercion/request-coercer this :response spec {}))
|
||||
(-query-string-coercer [_ _]))
|
||||
|
||||
(comment
|
||||
(doseq [coercion [nil (->NoOpCoercion) spec/coercion]]
|
||||
|
|
|
|||
|
|
@ -53,27 +53,27 @@
|
|||
request (json-request data)
|
||||
request! (request-stream request)]]
|
||||
|
||||
"10b"
|
||||
;; # 10b
|
||||
;; 38µs (c-api 1.x)
|
||||
;; 14µs (c-api 2.0.0-alpha21)
|
||||
;; 6µs
|
||||
|
||||
"100b"
|
||||
;; # 100b
|
||||
;; 74µs (c-api 1.x)
|
||||
;; 16µs (c-api 2.0.0-alpha21)
|
||||
;; 8µs
|
||||
|
||||
"1k"
|
||||
;; # 1k
|
||||
;; 322µs (c-api 1.x)
|
||||
;; 24µs (c-api 2.0.0-alpha21)
|
||||
;; 16µs
|
||||
|
||||
"10k"
|
||||
;; # 10k
|
||||
;; 3300µs (c-api 1.x)
|
||||
;; 120µs (c-api 2.0.0-alpha21)
|
||||
;; 110µs
|
||||
|
||||
"100k"
|
||||
;; # 100k
|
||||
;; 10600µs (c-api 1.x)
|
||||
;; 1100µs (c-api 2.0.0-alpha21)
|
||||
;; 1100µs
|
||||
|
|
@ -37,40 +37,40 @@
|
|||
(defn routing-test []
|
||||
|
||||
;; 21385 / 14337
|
||||
"barista"
|
||||
;; "barista"
|
||||
|
||||
;; 26259 / 25571
|
||||
"choreographer"
|
||||
;; "choreographer"
|
||||
|
||||
;; 24277 / 19174
|
||||
"clutch"
|
||||
;; "clutch"
|
||||
|
||||
;; 26158 / 25584
|
||||
"connect"
|
||||
;; "connect"
|
||||
|
||||
;; 24614 / 25413
|
||||
"escort"
|
||||
;; "escort"
|
||||
|
||||
;; 21979 / 18595
|
||||
"express"
|
||||
;; "express"
|
||||
|
||||
;; 23123 / 25405
|
||||
"find-my-way"
|
||||
;; "find-my-way"
|
||||
|
||||
;; 24798 / 25286
|
||||
"http-hash"
|
||||
;; "http-hash"
|
||||
|
||||
;; 24215 / 23670
|
||||
"i40"
|
||||
;; "i40"
|
||||
|
||||
;; 23561 / 26278
|
||||
"light-router"
|
||||
;; "light-router"
|
||||
|
||||
;; 28362 / 30056
|
||||
"http-raw"
|
||||
;; "http-raw"
|
||||
|
||||
;; 25310 / 25126
|
||||
"regex"
|
||||
;; "regex"
|
||||
|
||||
;; 112719 / 113959
|
||||
(title "reitit")
|
||||
|
|
|
|||
|
|
@ -308,10 +308,10 @@
|
|||
["/ping" {:get {:interceptors [{:enter #(a/go %)}]
|
||||
:handler (fn [_] (a/go response))}}])
|
||||
(ring/create-default-handler)
|
||||
{:executor sieppari/executor})]
|
||||
(let [respond (promise)]
|
||||
(app {:request-method :get, :uri "/ping"} respond ::irrelevant)
|
||||
(is (= response (deref respond 100 ::timeout)))))))
|
||||
{:executor sieppari/executor})
|
||||
respond (promise)]
|
||||
(app {:request-method :get, :uri "/ping"} respond ::irrelevant)
|
||||
(is (= response (deref respond 100 ::timeout))))))
|
||||
|
||||
(defrecord MyAsyncContext [])
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
(:require [clojure.spec.alpha :as cs]
|
||||
[clojure.string :as str]
|
||||
[clojure.test :refer [deftest is testing]]
|
||||
[malli.core :as m]
|
||||
[malli.experimental.lite :as l]
|
||||
[reitit.coercion :as coercion]
|
||||
[reitit.coercion.malli]
|
||||
|
|
@ -10,8 +9,7 @@
|
|||
[reitit.coercion.spec]
|
||||
[reitit.core :as r]
|
||||
[schema.core :as s]
|
||||
[spec-tools.data-spec :as ds]
|
||||
[malli.transform :as mt])
|
||||
[spec-tools.data-spec :as ds])
|
||||
#?(:clj
|
||||
(:import (clojure.lang ExceptionInfo))))
|
||||
|
||||
|
|
@ -110,7 +108,6 @@
|
|||
(testing "spec-coercion (shallow)"
|
||||
(testing "succeeds"
|
||||
(let [m (r/match-by-path r "/spec-shallow/1/abba")]
|
||||
(def MATCH m)
|
||||
(is (= {:path {:keyword :abba, :number 1}, :query nil}
|
||||
(coercion/coerce! m))))
|
||||
(let [m (r/match-by-path r "/spec-shallow/1/abba")]
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
(ns reitit.core-test
|
||||
(:require [clojure.test :refer [are deftest is testing]]
|
||||
[reitit.core :as r #?@(:cljs [:refer [Router]])]
|
||||
[reitit.core :as r]
|
||||
[reitit.impl :as impl])
|
||||
#?(:clj
|
||||
(:import (clojure.lang ExceptionInfo)
|
||||
(reitit.core Router))))
|
||||
(:import (clojure.lang ExceptionInfo))))
|
||||
|
||||
(defn- var-handler [& _]
|
||||
"var-handler")
|
||||
|
|
@ -261,10 +260,12 @@
|
|||
(is (= #'var-handler result))))))
|
||||
|
||||
(testing "custom router"
|
||||
(let [router (r/router ["/ping"] {:router (fn [_ _]
|
||||
(reify Router
|
||||
(r/router-name [_]
|
||||
::custom)))})]
|
||||
(let [router (r/router
|
||||
["/ping"]
|
||||
{:router (fn [_ _]
|
||||
#_{:clj-kondo/ignore [:missing-protocol-method]}
|
||||
(reify r/Router
|
||||
(router-name [_] ::custom)))})]
|
||||
(is (= ::custom (r/router-name router)))))
|
||||
|
||||
(testing "bide sample"
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
[jsonista.core :as j]
|
||||
[malli.core :as mc]
|
||||
[matcher-combinators.test :refer [match?]]
|
||||
[matcher-combinators.matchers :as matchers]
|
||||
[muuntaja.core :as m]
|
||||
[reitit.coercion.malli :as malli]
|
||||
[reitit.coercion.schema :as schema]
|
||||
|
|
|
|||
|
|
@ -4,18 +4,18 @@
|
|||
#?@(:clj [[muuntaja.core]
|
||||
[muuntaja.middleware]
|
||||
[jsonista.core :as j]
|
||||
[reitit.ring.middleware.muuntaja]])
|
||||
[reitit.coercion.schema :as schema]
|
||||
[reitit.ring.middleware.muuntaja]
|
||||
[schema.core :as s]])
|
||||
[malli.core :as m]
|
||||
[malli.util :as mu]
|
||||
[meta-merge.core :refer [meta-merge]]
|
||||
[reitit.coercion.malli :as malli]
|
||||
[reitit.coercion.schema :as schema]
|
||||
[reitit.coercion.spec :as spec]
|
||||
[reitit.core :as r]
|
||||
[reitit.ring :as ring]
|
||||
[reitit.ring.spec]
|
||||
[reitit.ring.coercion :as rrc]
|
||||
[schema.core :as s]
|
||||
[clojure.spec.alpha]
|
||||
[spec-tools.data-spec :as ds])
|
||||
#?(:clj
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
[reitit.core :as r]
|
||||
[reitit.middleware :as middleware]
|
||||
[reitit.ring :as ring]
|
||||
[reitit.trie :as trie])
|
||||
#?(:clj [reitit.trie :as trie]
|
||||
:cljs [reitit.trie :as-alias trie]))
|
||||
#?(:clj
|
||||
(:import (clojure.lang ExceptionInfo))))
|
||||
|
||||
|
|
@ -847,23 +848,22 @@
|
|||
(let [body (:body (app {:request-method :get, :uri (str "/" n)}))]
|
||||
(is (= body (str n))))))))))))
|
||||
|
||||
(declare routes)
|
||||
(def routes (atom nil))
|
||||
|
||||
(deftest reloading-ring-handler-test
|
||||
(let [r (fn [body] {:status 200, :body body})]
|
||||
(def routes ["/" (constantly (r "1"))]) ;; initial value
|
||||
|
||||
(let [create-handler (fn [] (ring/ring-handler (ring/router routes)))]
|
||||
(reset! routes ["/" (constantly (r "1"))]) ;; initial value
|
||||
(let [create-handler (fn [] (ring/ring-handler (ring/router @routes)))]
|
||||
(testing "static ring handler does not see underlying route changes"
|
||||
(let [app (create-handler)]
|
||||
(is (= (r "1") (app {:uri "/", :request-method :get})))
|
||||
(def routes ["/" (constantly (r "2"))]) ;; redefine
|
||||
(reset! routes ["/" (constantly (r "2"))]) ;; redefine
|
||||
(is (= (r "1") (app {:uri "/", :request-method :get})))))
|
||||
|
||||
(testing "reloading ring handler sees underlying route changes"
|
||||
(let [app (ring/reloading-ring-handler create-handler)]
|
||||
(is (= (r "2") (app {:uri "/", :request-method :get})))
|
||||
(def routes ["/" (constantly (r "3"))]) ;; redefine again
|
||||
(reset! routes ["/" (constantly (r "3"))]) ;; redefine again
|
||||
(is (= (r "3") (app {:uri "/", :request-method :get}))))))))
|
||||
|
||||
(defrecord FooTest [a b])
|
||||
|
|
|
|||
Loading…
Reference in a new issue