From c4e84c2875fa4b53a6eae1a2ce0236b75f856277 Mon Sep 17 00:00:00 2001 From: Juho Teperi Date: Thu, 5 Mar 2020 13:32:48 +0200 Subject: [PATCH] Add clj-kondo and fix most linting warnings --- .clj-kondo/config.edn | 6 + Justfile | 10 ++ examples/frontend-auth/src/backend/server.clj | 3 +- examples/frontend-auth/src/frontend/core.cljs | 1 - .../src/backend/server.clj | 3 +- .../src/frontend/core.cljs | 1 - .../frontend-links/src/backend/server.clj | 3 +- .../frontend-links/src/frontend/core.cljs | 1 - .../frontend-prompt/src/backend/server.clj | 3 +- .../frontend-prompt/src/frontend/core.cljs | 4 +- .../src/clj/backend/server.clj | 3 +- .../src/cljs/frontend_re_frame/core.cljs | 16 ++- examples/frontend/src/backend/server.clj | 3 +- examples/frontend/src/frontend/core.cljs | 1 - examples/http-swagger/src/example/server.clj | 7 +- .../pedestal-swagger/src/example/server.clj | 8 +- .../test/example/server_test.clj | 2 +- .../ring-spec-swagger/src/example/server.clj | 7 +- .../test/example/server_test.clj | 2 +- examples/ring-swagger/src/example/server.clj | 7 +- lint.sh | 15 +++ modules/reitit-core/src/reitit/impl.cljc | 6 +- modules/reitit-dev/src/reitit/dev/pretty.cljc | 1 - .../reitit-frontend/src/reitit/frontend.cljs | 7 +- .../src/reitit/frontend/history.cljs | 12 +- .../reitit-http/src/reitit/http/coercion.cljc | 6 +- .../src/reitit/swagger_ui.cljc | 6 +- .../reitit-swagger/src/reitit/swagger.cljc | 13 ++- perf-test/clj/reitit/bide_perf_test.clj | 2 +- perf-test/clj/reitit/calf_perf_test.clj | 11 +- perf-test/clj/reitit/coercion_perf_test.clj | 8 +- perf-test/clj/reitit/cors_perf_test.clj | 2 +- perf-test/clj/reitit/go_perf_test.clj | 3 +- perf-test/clj/reitit/impl_perf_test.clj | 15 +-- perf-test/clj/reitit/json_perf.cljc | 2 +- perf-test/clj/reitit/json_size_perf.cljc | 2 +- perf-test/clj/reitit/lupapiste_perf_test.clj | 3 +- .../reitit/middleware_interceptor_perf.clj | 2 +- perf-test/clj/reitit/nodejs_perf_test.clj | 2 +- .../clj/reitit/opensensors_perf_test.clj | 9 +- .../clj/reitit/prefix_tree_perf_test.clj | 3 +- perf-test/clj/reitit/request_perf.cljc | 7 +- perf-test/clj/reitit/ring_perf_test.clj | 1 - perf-test/clj/reitit/static_perf_test.clj | 9 +- test/cljc/reitit/core_test.cljc | 12 +- test/cljc/reitit/swagger_test.clj | 2 +- test/cljs/reitit/frontend/history_test.cljs | 107 +++++++++--------- 47 files changed, 178 insertions(+), 181 deletions(-) create mode 100644 .clj-kondo/config.edn create mode 100644 Justfile create mode 100755 lint.sh diff --git a/.clj-kondo/config.edn b/.clj-kondo/config.edn new file mode 100644 index 00000000..f1384b24 --- /dev/null +++ b/.clj-kondo/config.edn @@ -0,0 +1,6 @@ +{;;:skip-comments true + :lint-as {potemkin/def-derived-map clojure.core/defrecord} + :linters {:if {:level :off} + :unused-binding {:level :off} + :unused-referred-var {:exclude {clojure.test [deftest testing is are] + cljs.test [deftest testing is are]}}}} diff --git a/Justfile b/Justfile new file mode 100644 index 00000000..0487b8ac --- /dev/null +++ b/Justfile @@ -0,0 +1,10 @@ +help: + @just --list + +# Initializes lint +init-lint: + clj-kondo --lint $(lein classpath) + +# Lints the project +lint: + ./lint.sh diff --git a/examples/frontend-auth/src/backend/server.clj b/examples/frontend-auth/src/backend/server.clj index 88171cfa..24c80d9f 100644 --- a/examples/frontend-auth/src/backend/server.clj +++ b/examples/frontend-auth/src/backend/server.clj @@ -1,6 +1,5 @@ (ns backend.server - (:require [clojure.java.io :as io] - [ring.util.response :as resp] + (:require [ring.util.response :as resp] [ring.middleware.content-type :as content-type])) (def handler diff --git a/examples/frontend-auth/src/frontend/core.cljs b/examples/frontend-auth/src/frontend/core.cljs index d054b610..5b393dcf 100644 --- a/examples/frontend-auth/src/frontend/core.cljs +++ b/examples/frontend-auth/src/frontend/core.cljs @@ -3,7 +3,6 @@ [reitit.frontend :as rf] [reitit.frontend.easy :as rfe] [reitit.frontend.controllers :as rfc] - [reitit.coercion :as rc] [reitit.coercion.schema :as rsc] [schema.core :as s] [fipp.edn :as fedn])) diff --git a/examples/frontend-controllers/src/backend/server.clj b/examples/frontend-controllers/src/backend/server.clj index 88171cfa..24c80d9f 100644 --- a/examples/frontend-controllers/src/backend/server.clj +++ b/examples/frontend-controllers/src/backend/server.clj @@ -1,6 +1,5 @@ (ns backend.server - (:require [clojure.java.io :as io] - [ring.util.response :as resp] + (:require [ring.util.response :as resp] [ring.middleware.content-type :as content-type])) (def handler diff --git a/examples/frontend-controllers/src/frontend/core.cljs b/examples/frontend-controllers/src/frontend/core.cljs index 50986e76..60cd6f17 100644 --- a/examples/frontend-controllers/src/frontend/core.cljs +++ b/examples/frontend-controllers/src/frontend/core.cljs @@ -3,7 +3,6 @@ [reitit.frontend :as rf] [reitit.frontend.easy :as rfe] [reitit.frontend.controllers :as rfc] - [reitit.coercion :as rc] [reitit.coercion.schema :as rsc] [schema.core :as s] [fipp.edn :as fedn])) diff --git a/examples/frontend-links/src/backend/server.clj b/examples/frontend-links/src/backend/server.clj index 88171cfa..24c80d9f 100644 --- a/examples/frontend-links/src/backend/server.clj +++ b/examples/frontend-links/src/backend/server.clj @@ -1,6 +1,5 @@ (ns backend.server - (:require [clojure.java.io :as io] - [ring.util.response :as resp] + (:require [ring.util.response :as resp] [ring.middleware.content-type :as content-type])) (def handler diff --git a/examples/frontend-links/src/frontend/core.cljs b/examples/frontend-links/src/frontend/core.cljs index cc84dcf3..77a7d55f 100644 --- a/examples/frontend-links/src/frontend/core.cljs +++ b/examples/frontend-links/src/frontend/core.cljs @@ -2,7 +2,6 @@ (:require [clojure.string :as string] [fipp.edn :as fedn] [reagent.core :as r] - [reitit.coercion :as rc] [reitit.coercion.spec :as rss] [reitit.frontend :as rf] [reitit.frontend.easy :as rfe] diff --git a/examples/frontend-prompt/src/backend/server.clj b/examples/frontend-prompt/src/backend/server.clj index 88171cfa..24c80d9f 100644 --- a/examples/frontend-prompt/src/backend/server.clj +++ b/examples/frontend-prompt/src/backend/server.clj @@ -1,6 +1,5 @@ (ns backend.server - (:require [clojure.java.io :as io] - [ring.util.response :as resp] + (:require [ring.util.response :as resp] [ring.middleware.content-type :as content-type])) (def handler diff --git a/examples/frontend-prompt/src/frontend/core.cljs b/examples/frontend-prompt/src/frontend/core.cljs index 2b589678..9a6ec058 100644 --- a/examples/frontend-prompt/src/frontend/core.cljs +++ b/examples/frontend-prompt/src/frontend/core.cljs @@ -1,11 +1,9 @@ (ns frontend.core (:require [fipp.edn :as fedn] [reagent.core :as r] - [reitit.coercion :as rc] [reitit.coercion.spec :as rss] [reitit.frontend :as rf] - [reitit.frontend.easy :as rfe] - [spec-tools.data-spec :as ds])) + [reitit.frontend.easy :as rfe])) ;; Implementing conditional prompt on navigation with Reitit frontend. diff --git a/examples/frontend-re-frame/src/clj/backend/server.clj b/examples/frontend-re-frame/src/clj/backend/server.clj index 88171cfa..24c80d9f 100644 --- a/examples/frontend-re-frame/src/clj/backend/server.clj +++ b/examples/frontend-re-frame/src/clj/backend/server.clj @@ -1,6 +1,5 @@ (ns backend.server - (:require [clojure.java.io :as io] - [ring.util.response :as resp] + (:require [ring.util.response :as resp] [ring.middleware.content-type :as content-type])) (def handler diff --git a/examples/frontend-re-frame/src/cljs/frontend_re_frame/core.cljs b/examples/frontend-re-frame/src/cljs/frontend_re_frame/core.cljs index a15a34b0..0da5910c 100644 --- a/examples/frontend-re-frame/src/cljs/frontend_re_frame/core.cljs +++ b/examples/frontend-re-frame/src/cljs/frontend_re_frame/core.cljs @@ -1,13 +1,11 @@ (ns frontend-re-frame.core - (:require - [re-frame.core :as re-frame] - [reagent.core :as reagent] - [reitit.core :as r] - [reitit.coercion :as rc] - [reitit.coercion.spec :as rss] - [reitit.frontend :as rf] - [reitit.frontend.controllers :as rfc] - [reitit.frontend.easy :as rfe])) + (:require [re-frame.core :as re-frame] + [reagent.core :as reagent] + [reitit.core :as r] + [reitit.coercion.spec :as rss] + [reitit.frontend :as rf] + [reitit.frontend.controllers :as rfc] + [reitit.frontend.easy :as rfe])) ;;; Events ;;; diff --git a/examples/frontend/src/backend/server.clj b/examples/frontend/src/backend/server.clj index 88171cfa..24c80d9f 100644 --- a/examples/frontend/src/backend/server.clj +++ b/examples/frontend/src/backend/server.clj @@ -1,6 +1,5 @@ (ns backend.server - (:require [clojure.java.io :as io] - [ring.util.response :as resp] + (:require [ring.util.response :as resp] [ring.middleware.content-type :as content-type])) (def handler diff --git a/examples/frontend/src/frontend/core.cljs b/examples/frontend/src/frontend/core.cljs index fcd720f5..904305f5 100644 --- a/examples/frontend/src/frontend/core.cljs +++ b/examples/frontend/src/frontend/core.cljs @@ -2,7 +2,6 @@ (:require [reagent.core :as r] [reitit.frontend :as rf] [reitit.frontend.easy :as rfe] - [reitit.coercion :as rc] [reitit.coercion.spec :as rss] [spec-tools.data-spec :as ds] [fipp.edn :as fedn])) diff --git a/examples/http-swagger/src/example/server.clj b/examples/http-swagger/src/example/server.clj index 4f4676af..d652cdb4 100644 --- a/examples/http-swagger/src/example/server.clj +++ b/examples/http-swagger/src/example/server.clj @@ -11,9 +11,10 @@ [reitit.http.interceptors.muuntaja :as muuntaja] [reitit.http.interceptors.exception :as exception] [reitit.http.interceptors.multipart :as multipart] - [reitit.http.interceptors.dev :as dev] - [reitit.http.spec :as spec] - [spec-tools.spell :as spell] + ;; Uncomment to use + ; [reitit.http.interceptors.dev :as dev] + ; [reitit.http.spec :as spec] + ; [spec-tools.spell :as spell] [ring.adapter.jetty :as jetty] [aleph.http :as aleph] [muuntaja.core :as m] diff --git a/examples/pedestal-swagger/src/example/server.clj b/examples/pedestal-swagger/src/example/server.clj index 244188eb..69b2f865 100644 --- a/examples/pedestal-swagger/src/example/server.clj +++ b/examples/pedestal-swagger/src/example/server.clj @@ -11,10 +11,10 @@ [reitit.http.interceptors.muuntaja :as muuntaja] [reitit.http.interceptors.exception :as exception] [reitit.http.interceptors.multipart :as multipart] - [reitit.http.interceptors.dev :as dev] - [reitit.http.spec :as spec] - [spec-tools.spell :as spell] - [io.pedestal.http :as server] + ;; Uncomment to use + ; [reitit.http.interceptors.dev :as dev] + ; [reitit.http.spec :as spec] + ; [spec-tools.spell :as spell] [reitit.pedestal :as pedestal] [clojure.core.async :as a] [clojure.java.io :as io] diff --git a/examples/ring-malli-swagger/test/example/server_test.clj b/examples/ring-malli-swagger/test/example/server_test.clj index e35726b8..e296b5a8 100644 --- a/examples/ring-malli-swagger/test/example/server_test.clj +++ b/examples/ring-malli-swagger/test/example/server_test.clj @@ -1,5 +1,5 @@ (ns example.server-test - (:require [clojure.test :refer :all] + (:require [clojure.test :refer [deftest testing is]] [example.server :refer [app]] [ring.mock.request :refer [request json-body]])) diff --git a/examples/ring-spec-swagger/src/example/server.clj b/examples/ring-spec-swagger/src/example/server.clj index 4a807f75..69615800 100644 --- a/examples/ring-spec-swagger/src/example/server.clj +++ b/examples/ring-spec-swagger/src/example/server.clj @@ -9,9 +9,10 @@ [reitit.ring.middleware.exception :as exception] [reitit.ring.middleware.multipart :as multipart] [reitit.ring.middleware.parameters :as parameters] - [reitit.ring.middleware.dev :as dev] - [reitit.ring.spec :as spec] - [spec-tools.spell :as spell] + ;; Uncomment to use + ; [reitit.ring.middleware.dev :as dev] + ; [reitit.ring.spec :as spec] + ; [spec-tools.spell :as spell] [ring.adapter.jetty :as jetty] [muuntaja.core :as m] [clojure.spec.alpha :as s] diff --git a/examples/ring-spec-swagger/test/example/server_test.clj b/examples/ring-spec-swagger/test/example/server_test.clj index e35726b8..e296b5a8 100644 --- a/examples/ring-spec-swagger/test/example/server_test.clj +++ b/examples/ring-spec-swagger/test/example/server_test.clj @@ -1,5 +1,5 @@ (ns example.server-test - (:require [clojure.test :refer :all] + (:require [clojure.test :refer [deftest testing is]] [example.server :refer [app]] [ring.mock.request :refer [request json-body]])) diff --git a/examples/ring-swagger/src/example/server.clj b/examples/ring-swagger/src/example/server.clj index dd661ce7..8416c2b4 100644 --- a/examples/ring-swagger/src/example/server.clj +++ b/examples/ring-swagger/src/example/server.clj @@ -9,9 +9,10 @@ [reitit.ring.middleware.exception :as exception] [reitit.ring.middleware.multipart :as multipart] [reitit.ring.middleware.parameters :as parameters] - [reitit.ring.middleware.dev :as dev] - [reitit.ring.spec :as spec] - [spec-tools.spell :as spell] + ;; Uncomment to use + ; [reitit.ring.middleware.dev :as dev] + ; [reitit.ring.spec :as spec] + ; [spec-tools.spell :as spell] [ring.adapter.jetty :as jetty] [muuntaja.core :as m] [clojure.java.io :as io])) diff --git a/lint.sh b/lint.sh new file mode 100755 index 00000000..1a111793 --- /dev/null +++ b/lint.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +EXIT=0 + +clj-kondo --lint modules/*/src test perf-test +EXIT=$(( EXIT + $? )) + +for file in examples/*/src; do + echo + echo "Linting $file" + clj-kondo --lint "$file" + EXIT=$(( EXIT + $? )) +done + +exit $EXIT diff --git a/modules/reitit-core/src/reitit/impl.cljc b/modules/reitit-core/src/reitit/impl.cljc index c99d593b..2144d000 100644 --- a/modules/reitit-core/src/reitit/impl.cljc +++ b/modules/reitit-core/src/reitit/impl.cljc @@ -4,11 +4,9 @@ [clojure.set :as set] [meta-merge.core :as mm] [reitit.trie :as trie] - [reitit.exception :as exception] [reitit.exception :as ex]) #?(:clj - (:import (java.util.regex Pattern) - (java.util HashMap Map) + (:import (java.util HashMap Map) (java.net URLEncoder URLDecoder)))) (defn parse [path opts] @@ -138,7 +136,7 @@ (when-not (every? #(contains? path-params %) required) (let [defined (-> path-params keys set) missing (set/difference required defined)] - (exception/fail! + (ex/fail! (str "missing path-params for route " template " -> " missing) {:path-params path-params, :required required})))) diff --git a/modules/reitit-dev/src/reitit/dev/pretty.cljc b/modules/reitit-dev/src/reitit/dev/pretty.cljc index 7a60664c..5379a442 100644 --- a/modules/reitit-dev/src/reitit/dev/pretty.cljc +++ b/modules/reitit-dev/src/reitit/dev/pretty.cljc @@ -4,7 +4,6 @@ [reitit.exception :as exception] [arrangement.core] ;; spell-spec - [spec-tools.spell :as spell] [spell-spec.expound] ;; expound [expound.ansi] diff --git a/modules/reitit-frontend/src/reitit/frontend.cljs b/modules/reitit-frontend/src/reitit/frontend.cljs index 071e296d..6913a438 100644 --- a/modules/reitit-frontend/src/reitit/frontend.cljs +++ b/modules/reitit-frontend/src/reitit/frontend.cljs @@ -1,12 +1,11 @@ (ns reitit.frontend (:require [clojure.set :as set] [reitit.coercion :as coercion] - [reitit.coercion :as rc] [reitit.core :as r]) (:import goog.Uri goog.Uri.QueryData)) -(defn- query-param [^goog.Uri.QueryData q k] +(defn- query-param [^QueryData q k] (let [vs (.getValues q k)] (if (< (alength vs) 2) (aget vs 0) @@ -14,7 +13,7 @@ (defn query-params "Given goog.Uri, read query parameters into Clojure map." - [^goog.Uri uri] + [^Uri uri] (let [q (.getQueryData uri)] (->> q (.getKeys) @@ -51,7 +50,7 @@ ([raw-routes] (router raw-routes {})) ([raw-routes opts] - (r/router raw-routes (merge {:compile rc/compile-request-coercers} opts)))) + (r/router raw-routes (merge {:compile coercion/compile-request-coercers} opts)))) (defn match-by-name! "Logs problems using console.warn" diff --git a/modules/reitit-frontend/src/reitit/frontend/history.cljs b/modules/reitit-frontend/src/reitit/frontend/history.cljs index 7dd1011b..0e4d21d9 100644 --- a/modules/reitit-frontend/src/reitit/frontend/history.cljs +++ b/modules/reitit-frontend/src/reitit/frontend/history.cljs @@ -2,7 +2,6 @@ "Provides integration to hash-change or HTML5 History events." (:require [reitit.core :as reitit] - [reitit.core :as r] [reitit.frontend :as rf] [goog.events :as gevents]) (:import goog.Uri)) @@ -59,9 +58,10 @@ el (recur (.-parentNode el))))))) -(defn- event-target [event] +(defn- event-target "Read event's target from composed path to get shadow dom working, - fallback to target property if not available" + fallback to target property if not available" + [event] (let [original-event (.getBrowserEvent event)] (if (exists? (.-composedPath original-event)) (aget (.composedPath original-event) 0) @@ -176,7 +176,7 @@ (href history k params nil)) ([history k params query] (let [match (rf/match-by-name! (:router history) k params)] - (-href history (r/match->path match query))))) + (-href history (reitit/match->path match query))))) (defn push-state "Sets the new route, leaving previous route in history." @@ -186,7 +186,7 @@ (push-state history k params nil)) ([history k params query] (let [match (rf/match-by-name! (:router history) k params) - path (r/match->path match query)] + path (reitit/match->path match query)] ;; pushState and replaceState don't trigger popstate event so call on-navigate manually (.pushState js/window.history nil "" (-href history path)) (-on-navigate history path)))) @@ -199,6 +199,6 @@ (replace-state history k params nil)) ([history k params query] (let [match (rf/match-by-name! (:router history) k params) - path (r/match->path match query)] + path (reitit/match->path match query)] (.replaceState js/window.history nil "" (-href history path)) (-on-navigate history path)))) diff --git a/modules/reitit-http/src/reitit/http/coercion.cljc b/modules/reitit-http/src/reitit/http/coercion.cljc index 459aaadb..cf3dba03 100644 --- a/modules/reitit-http/src/reitit/http/coercion.cljc +++ b/modules/reitit-http/src/reitit/http/coercion.cljc @@ -43,9 +43,9 @@ (let [coercers (coercion/response-coercers coercion responses opts)] {:leave (fn [ctx] (let [request (:request ctx) - response (:response ctx)] - (let [response (coercion/coerce-response coercers request response)] - (assoc ctx :response response))))})))}) + response (:response ctx) + response (coercion/coerce-response coercers request response)] + (assoc ctx :response response)))})))}) (defn coerce-exceptions-interceptor "Interceptor for handling coercion exceptions. diff --git a/modules/reitit-swagger-ui/src/reitit/swagger_ui.cljc b/modules/reitit-swagger-ui/src/reitit/swagger_ui.cljc index a16c6dfc..53a6c04c 100644 --- a/modules/reitit-swagger-ui/src/reitit/swagger_ui.cljc +++ b/modules/reitit-swagger-ui/src/reitit/swagger_ui.cljc @@ -1,8 +1,6 @@ (ns reitit.swagger-ui - (:require [clojure.string :as str] - [reitit.ring :as ring] - #?@(:clj [ - [jsonista.core :as j]]))) + #?(:clj (:require [reitit.ring :as ring] + [jsonista.core :as j]))) #?(:clj (defn create-swagger-ui-handler diff --git a/modules/reitit-swagger/src/reitit/swagger.cljc b/modules/reitit-swagger/src/reitit/swagger.cljc index 1d4491ad..3ff90932 100644 --- a/modules/reitit-swagger/src/reitit/swagger.cljc +++ b/modules/reitit-swagger/src/reitit/swagger.cljc @@ -67,9 +67,10 @@ (defn- swagger-path [path opts] (-> path (trie/normalize opts) (str/replace #"\{\*" "{"))) -(defn create-swagger-handler [] +(defn create-swagger-handler "Create a ring handler to emit swagger spec. Collects all routes from router which have an intersecting `[:swagger :id]` and which are not marked with `:no-doc` route data." + [] (fn create-swagger ([{::r/keys [router match] :keys [request-method]}] (let [{:keys [id] :or {id ::default} :as swagger} (-> match :result request-method :data :swagger) @@ -95,11 +96,11 @@ (strip-top-level-keys swagger))])) transform-path (fn [[p _ c]] (if-let [endpoint (some->> c (keep transform-endpoint) (seq) (into {}))] - [(swagger-path p (r/options router)) endpoint]))] - (let [map-in-order #(->> % (apply concat) (apply array-map)) - paths (->> router (r/compiled-routes) (filter accept-route) (map transform-path) map-in-order)] - {:status 200 - :body (meta-merge swagger {:paths paths})}))) + [(swagger-path p (r/options router)) endpoint])) + map-in-order #(->> % (apply concat) (apply array-map)) + paths (->> router (r/compiled-routes) (filter accept-route) (map transform-path) map-in-order)] + {:status 200 + :body (meta-merge swagger {:paths paths})})) ([req res raise] (try (res (create-swagger req)) diff --git a/perf-test/clj/reitit/bide_perf_test.clj b/perf-test/clj/reitit/bide_perf_test.clj index 495b455b..0bd69693 100644 --- a/perf-test/clj/reitit/bide_perf_test.clj +++ b/perf-test/clj/reitit/bide_perf_test.clj @@ -1,7 +1,7 @@ (ns reitit.bide-perf-test (:require [criterium.core :as cc] [reitit.core :as reitit] - [reitit.perf-utils :refer :all] + [reitit.perf-utils :refer [suite title]] [bidi.bidi :as bidi] [ataraxy.core :as ataraxy] diff --git a/perf-test/clj/reitit/calf_perf_test.clj b/perf-test/clj/reitit/calf_perf_test.clj index 55a0cb52..139b4353 100644 --- a/perf-test/clj/reitit/calf_perf_test.clj +++ b/perf-test/clj/reitit/calf_perf_test.clj @@ -1,9 +1,7 @@ (ns reitit.calf-perf-test (:require [criterium.core :as cc] - [reitit.perf-utils :refer :all] [ring.util.codec] [reitit.impl] - [clojure.edn :as edn] [reitit.ring :as ring] [reitit.core :as r])) @@ -24,11 +22,10 @@ (defn test! [f input] - (do - (println "\u001B[33m") - (println (pr-str input) "=>" (pr-str (f input))) - (println "\u001B[0m") - (cc/quick-bench (f input)))) + (println "\u001B[33m") + (println (pr-str input) "=>" (pr-str (f input))) + (println "\u001B[0m") + (cc/quick-bench (f input))) (defn h11 [id type] {:status 200 :headers {"Content-Type" "text/plain"} diff --git a/perf-test/clj/reitit/coercion_perf_test.clj b/perf-test/clj/reitit/coercion_perf_test.clj index 45d5b3d5..4647ccc1 100644 --- a/perf-test/clj/reitit/coercion_perf_test.clj +++ b/perf-test/clj/reitit/coercion_perf_test.clj @@ -1,11 +1,9 @@ (ns reitit.coercion-perf-test - (:require [clojure.test :refer [deftest testing is]] - [criterium.core :as cc] - [reitit.perf-utils :refer :all] + (:require [criterium.core :as cc] + [reitit.perf-utils :refer [bench! suite title]] [clojure.spec.alpha :as s] [spec-tools.core :as st] [muuntaja.middleware :as mm] - [muuntaja.core :as m] [jsonista.core :as j] [reitit.ring.coercion :as rrc] [reitit.coercion.spec :as spec] @@ -91,7 +89,7 @@ (comment (doseq [coercion [nil (->NoOpCoercion) spec/coercion]] - (suite (str (if coercion (protocol/get-name coercion)))) + (suite (str (if coercion (coercion/-get-name coercion)))) (let [routes ["/api" ["/ping" {:parameters {:body {:x int?, :y int?}} :responses {200 {:body {:total pos-int?}}} diff --git a/perf-test/clj/reitit/cors_perf_test.clj b/perf-test/clj/reitit/cors_perf_test.clj index a87544bc..7c2e78bd 100644 --- a/perf-test/clj/reitit/cors_perf_test.clj +++ b/perf-test/clj/reitit/cors_perf_test.clj @@ -1,5 +1,5 @@ (ns reitit.cors-perf-test - (:require [reitit.perf-utils :refer :all] + (:require [reitit.perf-utils :refer [b!]] [ring.middleware.cors :as cors])) ;; diff --git a/perf-test/clj/reitit/go_perf_test.clj b/perf-test/clj/reitit/go_perf_test.clj index ba03b753..2fc773b9 100644 --- a/perf-test/clj/reitit/go_perf_test.clj +++ b/perf-test/clj/reitit/go_perf_test.clj @@ -1,8 +1,7 @@ (ns reitit.go-perf-test (:require [criterium.core :as cc] - [reitit.perf-utils :refer :all] + [reitit.perf-utils :refer [suite title]] [reitit.ring :as ring] - [reitit.trie :as trie] [clojure.string :as str])) ;; diff --git a/perf-test/clj/reitit/impl_perf_test.clj b/perf-test/clj/reitit/impl_perf_test.clj index 1f1f90ed..2a1d6dd7 100644 --- a/perf-test/clj/reitit/impl_perf_test.clj +++ b/perf-test/clj/reitit/impl_perf_test.clj @@ -1,8 +1,7 @@ (ns reitit.impl-perf-test (:require [criterium.core :as cc] - [reitit.perf-utils :refer :all] + [reitit.perf-utils :refer [suite]] [ring.util.codec] - [reitit.impl] [reitit.impl :as impl]) (:import (java.net URLDecoder URLEncoder))) @@ -23,11 +22,10 @@ (defn test! [f input] - (do - (println "\u001B[33m") - (println (pr-str input) "=>" (pr-str (f input))) - (println "\u001B[0m") - (cc/quick-bench (f input)))) + (println "\u001B[33m") + (println (pr-str input) "=>" (pr-str (f input))) + (println "\u001B[0m") + (cc/quick-bench (f input))) (defn url-decode-naive [s] (URLDecoder/decode @@ -190,5 +188,4 @@ (url-encode!) (form-decode!) (form-encode!) - (url-encode-coll!) - (split!)) + (url-encode-coll!)) diff --git a/perf-test/clj/reitit/json_perf.cljc b/perf-test/clj/reitit/json_perf.cljc index 5c26dd0a..e64b1d77 100644 --- a/perf-test/clj/reitit/json_perf.cljc +++ b/perf-test/clj/reitit/json_perf.cljc @@ -1,6 +1,6 @@ (ns reitit.json-perf (:require [criterium.core :as cc] - [reitit.perf-utils :refer :all] + [reitit.perf-utils :refer [title]] ;; aleph [aleph.http :as http] diff --git a/perf-test/clj/reitit/json_size_perf.cljc b/perf-test/clj/reitit/json_size_perf.cljc index b9004f09..b9bd9c41 100644 --- a/perf-test/clj/reitit/json_size_perf.cljc +++ b/perf-test/clj/reitit/json_size_perf.cljc @@ -1,6 +1,6 @@ (ns reitit.json-size-perf (:require [criterium.core :as cc] - [reitit.perf-utils :refer :all] + [reitit.perf-utils :refer [title]] [reitit.ring :as ring] [muuntaja.middleware :as mm] [reitit.coercion.spec] diff --git a/perf-test/clj/reitit/lupapiste_perf_test.clj b/perf-test/clj/reitit/lupapiste_perf_test.clj index 537c2a35..3f6a0388 100644 --- a/perf-test/clj/reitit/lupapiste_perf_test.clj +++ b/perf-test/clj/reitit/lupapiste_perf_test.clj @@ -1,6 +1,5 @@ (ns reitit.lupapiste-perf-test - (:require [clojure.test :refer [deftest testing is]] - [reitit.perf-utils :refer :all] + (:require [reitit.perf-utils :refer [bench!! handler valid-urls]] [reitit.core :as reitit] [reitit.ring :as ring] diff --git a/perf-test/clj/reitit/middleware_interceptor_perf.clj b/perf-test/clj/reitit/middleware_interceptor_perf.clj index 1fcb9507..f4114b6b 100644 --- a/perf-test/clj/reitit/middleware_interceptor_perf.clj +++ b/perf-test/clj/reitit/middleware_interceptor_perf.clj @@ -1,6 +1,6 @@ (ns reitit.middleware-interceptor-perf (:require [criterium.core :as cc] - [reitit.perf-utils :refer :all] + [reitit.perf-utils :refer [title]] [reitit.middleware :as middleware] [reitit.interceptor :as interceptor] diff --git a/perf-test/clj/reitit/nodejs_perf_test.clj b/perf-test/clj/reitit/nodejs_perf_test.clj index 5a427e1c..40fde7a0 100644 --- a/perf-test/clj/reitit/nodejs_perf_test.clj +++ b/perf-test/clj/reitit/nodejs_perf_test.clj @@ -1,5 +1,5 @@ (ns reitit.nodejs-perf-test - (:require [reitit.perf-utils :refer :all] + (:require [reitit.perf-utils :refer [title]] [immutant.web :as web] [reitit.ring :as ring])) diff --git a/perf-test/clj/reitit/opensensors_perf_test.clj b/perf-test/clj/reitit/opensensors_perf_test.clj index 886f11e3..0c041de4 100644 --- a/perf-test/clj/reitit/opensensors_perf_test.clj +++ b/perf-test/clj/reitit/opensensors_perf_test.clj @@ -16,7 +16,6 @@ [io.pedestal.http.route.definition.table :as table] [io.pedestal.http.route.map-tree :as map-tree] [io.pedestal.http.route.router :as pedestal] - [reitit.core :as r] [criterium.core :as cc])) ;; @@ -592,10 +591,6 @@ ["/v1/orgs/:org-id/members/invitation-data/:user-id" :get (constantly "") :route-name :test/route39]])) {:path-info "/v1/orgs/0/members/invitation-data/1" :request-method :get}) - (require '[io.pedestal.http.route.definition.table :as table]) - (require '[io.pedestal.http.route.map-tree :as map-tree]) - (require '[io.pedestal.http.route.router :as pedestal]) - (pedestal/find-route (map-tree/router (table/table-routes @@ -640,7 +635,7 @@ router (reitit/router routes) reitit-f #(reitit/match-by-path router (:uri %)) reitit-ring-f (ring/ring-handler (ring/router opensensors-routes)) - reitit-ring-linear-f (ring/ring-handler (ring/router opensensors-routes {:router r/linear-router})) + reitit-ring-linear-f (ring/ring-handler (ring/router opensensors-routes {:router reitit/linear-router})) reitit-ring-fast-f (ring/ring-handler (ring/router opensensors-routes) nil {:inject-router? false, :inject-match? false}) bidi-f #(bidi/match-route opensensors-bidi-routes (:uri %)) calfpath-macros-f opensensors-calfpath-macro-handler @@ -727,7 +722,7 @@ ;; 293ns (pre-defined parameters) (let [app (ring/ring-handler (ring/router opensensors-routes) {:inject-match? false, :inject-router? false}) request {:uri "/v1/users/1/devices/1", :request-method :get}] - (doseq [[p r] (-> app (ring/get-router) (r/routes))] + (doseq [[p r] (-> app (ring/get-router) (reitit/routes))] (when-not (app {:uri p, :request-method :get}) (println "FAIL:" p))) (println (app request)) diff --git a/perf-test/clj/reitit/prefix_tree_perf_test.clj b/perf-test/clj/reitit/prefix_tree_perf_test.clj index 0e6e2091..737ae4c6 100644 --- a/perf-test/clj/reitit/prefix_tree_perf_test.clj +++ b/perf-test/clj/reitit/prefix_tree_perf_test.clj @@ -1,6 +1,5 @@ (ns reitit.prefix-tree-perf-test - (:require [clojure.test :refer :all] - [io.pedestal.http.route.prefix-tree :as p] + (:require [io.pedestal.http.route.prefix-tree :as p] [reitit.trie :as trie] [criterium.core :as cc])) diff --git a/perf-test/clj/reitit/request_perf.cljc b/perf-test/clj/reitit/request_perf.cljc index eb552d7f..cafd205c 100644 --- a/perf-test/clj/reitit/request_perf.cljc +++ b/perf-test/clj/reitit/request_perf.cljc @@ -1,6 +1,6 @@ (ns reitit.request-perf (:require [criterium.core :as cc] - [reitit.perf-utils :refer :all] + [reitit.perf-utils :refer [title]] [potemkin :as p])) (set! *warn-on-reflection* true) @@ -25,8 +25,7 @@ (-request-method [this]) (-path-params [this])) -(p/def-derived-map - ZeroCopyRequest +(p/def-derived-map ZeroCopyRequest [raw] :uri (-uri raw) :request-method (-request-method raw) @@ -42,6 +41,8 @@ :request-method (-request-method raw) :path-params (-path-params raw)}) +(defrecord RecordRequest [uri request-method path-params]) + (defn record-request [raw] (->RecordRequest (-uri raw) (-request-method raw) (-path-params raw))) diff --git a/perf-test/clj/reitit/ring_perf_test.clj b/perf-test/clj/reitit/ring_perf_test.clj index b3226120..354940e9 100644 --- a/perf-test/clj/reitit/ring_perf_test.clj +++ b/perf-test/clj/reitit/ring_perf_test.clj @@ -1,6 +1,5 @@ (ns reitit.ring-perf-test (:require [criterium.core :as cc] - [reitit.perf-utils :refer :all] [reitit.ring :as ring])) ;; diff --git a/perf-test/clj/reitit/static_perf_test.clj b/perf-test/clj/reitit/static_perf_test.clj index 90cba0b1..01f8deb8 100644 --- a/perf-test/clj/reitit/static_perf_test.clj +++ b/perf-test/clj/reitit/static_perf_test.clj @@ -1,7 +1,7 @@ (ns reitit.static-perf-test - (:require [reitit.perf-utils :refer :all] - [immutant.web :as web] + (:require [immutant.web :as web] [reitit.ring :as ring] + [reitit.ring.mime :as reitit-mime] [clojure.java.io :as io] [criterium.core :as cc] [ring.util.response] @@ -48,8 +48,7 @@ (ring.middleware.defaults/wrap-defaults ring.middleware.defaults/site-defaults))) (comment - (def server (web/run #'app {:port 3000, :dispatch? false, :server {:always-set-keep-alive false}})) - (routing-test)) + (def server (web/run #'app1 {:port 3000, :dispatch? false, :server {:always-set-keep-alive false}}))) (defn bench-resources [] @@ -104,4 +103,4 @@ ;; 106ns (cc/quick-bench - (reitit.ring.mime/ext-mime-type name reitit.ring.mime/default-mime-types)))) + (reitit-mime/ext-mime-type name reitit-mime/default-mime-types)))) diff --git a/test/cljc/reitit/core_test.cljc b/test/cljc/reitit/core_test.cljc index 889cf1d8..c1161931 100644 --- a/test/cljc/reitit/core_test.cljc +++ b/test/cljc/reitit/core_test.cljc @@ -1,9 +1,9 @@ (ns reitit.core-test (:require [clojure.test :refer [deftest testing is are]] - [reitit.core :as r #?@(:cljs [:refer [Match Router]])] + [reitit.core :as r #?@(:cljs [:refer [Router]])] [reitit.impl :as impl]) #?(:clj - (:import (reitit.core Match Router) + (:import (reitit.core Router) (clojure.lang ExceptionInfo)))) (deftest reitit-test @@ -241,10 +241,10 @@ (is (= 2 @compile-times)))))) (testing "default compile" - (let [router (r/router ["/ping" (constantly "ok")])] - (let [{:keys [result]} (r/match-by-path router "/ping")] - (is result) - (is (= "ok" (result))))))) + (let [router (r/router ["/ping" (constantly "ok")]) + {:keys [result]} (r/match-by-path router "/ping")] + (is result) + (is (= "ok" (result)))))) (testing "custom router" (let [router (r/router ["/ping"] {:router (fn [_ _] diff --git a/test/cljc/reitit/swagger_test.clj b/test/cljc/reitit/swagger_test.clj index 6214cf74..1e5b24f8 100644 --- a/test/cljc/reitit/swagger_test.clj +++ b/test/cljc/reitit/swagger_test.clj @@ -1,5 +1,5 @@ (ns reitit.swagger-test - (:require [clojure.test :refer :all] + (:require [clojure.test :refer [deftest is testing]] [reitit.ring :as ring] [reitit.swagger :as swagger] [reitit.swagger-ui :as swagger-ui] diff --git a/test/cljs/reitit/frontend/history_test.cljs b/test/cljs/reitit/frontend/history_test.cljs index 2873d730..cf5341fb 100644 --- a/test/cljs/reitit/frontend/history_test.cljs +++ b/test/cljs/reitit/frontend/history_test.cljs @@ -1,7 +1,6 @@ (ns reitit.frontend.history-test (:require [clojure.test :refer [deftest testing is are async]] [reitit.core :as r] - [reitit.frontend :as rf] [reitit.frontend.history :as rfh] [reitit.frontend.test-utils :refer [capture-console]] [goog.events :as gevents])) @@ -43,32 +42,32 @@ (gevents/removeAll js/window goog.events.EventType.HASHCHANGE) (async done - (let [n (atom 0) - history (rfh/start! router - (fn [match history] - (let [url (rfh/-get-path history)] - (case (swap! n inc) - 1 (do (is (= "/" url) - "start at root") - (rfh/push-state history ::foo)) - 2 (do (is (= "/foo" url) - "push-state") - (.back js/window.history)) - 3 (do (is (= "/" url) - "go back") - (rfh/push-state history ::bar {:id 1})) - 4 (do (is (= "/bar/1" url) - "push-state 2") - (rfh/replace-state history ::bar {:id 2})) - 5 (do (is (= "/bar/2" url) - "replace-state") - (.back js/window.history)) - 6 (do (is (= "/" url) - "go back after replace state") - (rfh/stop! history) - (done)) - (do (is false "extra event"))))) - {:use-fragment true})])))) + (let [n (atom 0)] + (rfh/start! router + (fn [match history] + (let [url (rfh/-get-path history)] + (case (swap! n inc) + 1 (do (is (= "/" url) + "start at root") + (rfh/push-state history ::foo)) + 2 (do (is (= "/foo" url) + "push-state") + (.back js/window.history)) + 3 (do (is (= "/" url) + "go back") + (rfh/push-state history ::bar {:id 1})) + 4 (do (is (= "/bar/1" url) + "push-state 2") + (rfh/replace-state history ::bar {:id 2})) + 5 (do (is (= "/bar/2" url) + "replace-state") + (.back js/window.history)) + 6 (do (is (= "/" url) + "go back after replace state") + (rfh/stop! history) + (done)) + (is false "extra event")))) + {:use-fragment true}))))) (deftest html5-history-test (when browser @@ -100,33 +99,33 @@ (gevents/removeAll js/window goog.events.EventType.HASHCHANGE) (async done - (let [n (atom 0) - history (rfh/start! router - (fn [match history] - (let [url (rfh/-get-path history)] - (case (swap! n inc) - 1 (do (rfh/push-state history ::frontpage)) - 2 (do (is (= "/" url) - "start at root") - (rfh/push-state history ::foo)) - 3 (do (is (= "/foo" url) - "push-state") - (.back js/window.history)) - 4 (do (is (= "/" url) - "go back") - (rfh/push-state history ::bar {:id 1})) - 5 (do (is (= "/bar/1" url) - "push-state 2") - (rfh/replace-state history ::bar {:id 2})) - 6 (do (is (= "/bar/2" url) - "replace-state") - (.back js/window.history)) - 7 (do (is (= "/" url) - "go back after replace state") - (rfh/stop! history) - (done)) - (do (is false "extra event"))))) - {:use-fragment false})])))) + (let [n (atom 0)] + (rfh/start! router + (fn [match history] + (let [url (rfh/-get-path history)] + (case (swap! n inc) + 1 (rfh/push-state history ::frontpage) + 2 (do (is (= "/" url) + "start at root") + (rfh/push-state history ::foo)) + 3 (do (is (= "/foo" url) + "push-state") + (.back js/window.history)) + 4 (do (is (= "/" url) + "go back") + (rfh/push-state history ::bar {:id 1})) + 5 (do (is (= "/bar/1" url) + "push-state 2") + (rfh/replace-state history ::bar {:id 2})) + 6 (do (is (= "/bar/2" url) + "replace-state") + (.back js/window.history)) + 7 (do (is (= "/" url) + "go back after replace state") + (rfh/stop! history) + (done)) + (is false "extra event")))) + {:use-fragment false}))))) (deftest html5-history-link-click-test (when browser