From 72f49fee052e039e0095954707a258656b537c15 Mon Sep 17 00:00:00 2001 From: Pireax Date: Mon, 13 Jul 2020 23:08:33 +0200 Subject: [PATCH 1/9] Add linting support, remove unused files --- .clj-kondo/config.edn | 31 +++++++++++++++++++ .../https-instance-securitygroup.config | 9 ------ .gitignore | 1 + .travis.yml | 1 - project.clj | 5 +-- src/clj/orcpub/pedestal.clj | 3 +- 6 files changed, 36 insertions(+), 14 deletions(-) create mode 100644 .clj-kondo/config.edn delete mode 100644 .ebextensions/https-instance-securitygroup.config delete mode 100644 .travis.yml diff --git a/.clj-kondo/config.edn b/.clj-kondo/config.edn new file mode 100644 index 000000000..5fcace5e2 --- /dev/null +++ b/.clj-kondo/config.edn @@ -0,0 +1,31 @@ +{:linters {:if {:level :off} + :unused-namespace {:level :off} + :unused-binding {:level :off} + :unresolved-symbol + {:exclude + [(clojure.core.match/match) + (cljs.core.match/match) + (io.pedestal.interceptor.error/error-dispatch) + (orcpub.modifiers/modifier) + (orcpub.modifiers/deferred-modifier) + (orcpub.modifiers/cum-sum-mod) + (orcpub.modifiers/vec-mod) + (orcpub.modifiers/set-mod) + (orcpub.modifiers/map-mod) + (orcpub.modifiers/fn-mod) + (orcpub.dnd.e5.modifiers/spells-known-cfg) + (orcpub.dnd.e5.modifiers/prop-trait) + (orcpub.dnd.e5.modifiers/dependent-trait) + (orcpub.dnd.e5.modifiers/dependent-trait-2) + (orcpub.dnd.e5.modifiers/skill-proficiency) + (orcpub.dnd.e5.modifiers/skill-expertise) + (orcpub.dnd.e5.modifiers/tool-expertise) + (orcpub.dnd.e5.modifiers/ac-bonus-fn) + (orcpub.dnd.e5.modifiers/attack) + (orcpub.dnd.e5.modifiers/action) + (orcpub.dnd.e5.modifiers/bonus-action) + (orcpub.dnd.e5.modifiers/reaction) + (orcpub.dnd.e5.modifiers/level-val) + (orcpub.entity-spec/make-entity)]}} + :lint-as {reagent.core/with-let clojure.core/let + hiccup.def/defhtml clojure.core/defn}} \ No newline at end of file diff --git a/.ebextensions/https-instance-securitygroup.config b/.ebextensions/https-instance-securitygroup.config deleted file mode 100644 index 578ee1f92..000000000 --- a/.ebextensions/https-instance-securitygroup.config +++ /dev/null @@ -1,9 +0,0 @@ -Resources: - sslSecurityGroupIngress: - Type: AWS::EC2::SecurityGroupIngress - Properties: - GroupId: {"Fn::GetAtt" : ["AWSEBSecurityGroup", "GroupId"]} - IpProtocol: tcp - ToPort: 443 - FromPort: 443 - CidrIp: 0.0.0.0/0 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 55677f550..aacb42646 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ pom.xml /out/ /target/ /node_modules/ +/.clj-kondo/.cache .lein-deps-sum .lein-repl-history .lein-plugins/ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 079130527..000000000 --- a/.travis.yml +++ /dev/null @@ -1 +0,0 @@ -language: clojure diff --git a/project.clj b/project.clj index 45911895d..7ddee03e4 100644 --- a/project.clj +++ b/project.clj @@ -69,6 +69,7 @@ [lein-cljsbuild "1.1.7" :exclusions [[org.clojure/clojure]]] [lein-garden "0.3.0"] [lein-environ "1.1.0"] + [lein-cljfmt "0.6.8"] #_[lein-resource "16.9.1"]] :source-paths ["src/clj" "src/cljc" "src/cljs"] @@ -93,8 +94,6 @@ ;; Compress the output? :pretty-print? false}}]} - :prep-tasks [["garden" "once"]] - :cljsbuild {:builds {:dev { @@ -172,6 +171,7 @@ "externs" ["do" "clean" ["run" "-m" "externs"]] "rebuild-modules" ["run" "-m" "user" "--rebuild-modules"] + "lint" ["with-profile" "lint" "run" "-m" "clj-kondo.main" "--lint" "src"] "prod-build" ^{:doc "Recompile code with prod profile."} ["externs" ["with-profile" "prod" "cljsbuild" "once" "main"]]} @@ -227,6 +227,7 @@ ;;:output-dir "resources/public/js/compiled/out" :optimizations :advanced :pretty-print false}}}}} + :lint {:dependencies [[clj-kondo "RELEASE"]]} ;; Use like: lein with-profile +start-server repl :start-server {:repl-options {:init-ns user :init (start-server)}}}) diff --git a/src/clj/orcpub/pedestal.clj b/src/clj/orcpub/pedestal.clj index f8c40525c..118358319 100644 --- a/src/clj/orcpub/pedestal.clj +++ b/src/clj/orcpub/pedestal.clj @@ -1,8 +1,7 @@ (ns orcpub.pedestal (:require [com.stuartsierra.component :as component] [io.pedestal.http :as http] - [pandect.algo.sha1 :refer :all] - [ring.middleware.etag :refer [wrap-etag]] + [pandect.algo.sha1 :refer [sha1]] [datomic.api :as d] [clojure.string :as s] [clj-time.format :as tf] From 1e5f0d8e5112d5c9f72d14ac5761cadd8b273194 Mon Sep 17 00:00:00 2001 From: Pireax Date: Tue, 14 Jul 2020 21:54:13 +0200 Subject: [PATCH 2/9] Fix some linting issues --- .clj-kondo/config.edn | 2 +- src/clj/orcpub/db/schema.clj | 6 - src/clj/orcpub/email.clj | 6 +- src/clj/orcpub/pdf.clj | 350 ++++++++++++++-------------- src/clj/orcpub/pedestal.clj | 6 +- src/clj/orcpub/routes.clj | 34 ++- src/cljc/orcpub/dnd/e5/classes.cljc | 6 +- src/cljc/orcpub/dnd/e5/options.cljc | 6 +- src/cljc/orcpub/entity.cljc | 7 +- src/cljs/orcpub/dnd/e5/db.cljs | 6 +- src/cljs/orcpub/dnd/e5/events.cljs | 102 ++++---- src/cljs/orcpub/dnd/e5/views.cljs | 9 +- 12 files changed, 264 insertions(+), 276 deletions(-) diff --git a/.clj-kondo/config.edn b/.clj-kondo/config.edn index 5fcace5e2..af974ea9a 100644 --- a/.clj-kondo/config.edn +++ b/.clj-kondo/config.edn @@ -28,4 +28,4 @@ (orcpub.dnd.e5.modifiers/level-val) (orcpub.entity-spec/make-entity)]}} :lint-as {reagent.core/with-let clojure.core/let - hiccup.def/defhtml clojure.core/defn}} \ No newline at end of file + hiccup.def/defhtml clojure.core/defn}} diff --git a/src/clj/orcpub/db/schema.clj b/src/clj/orcpub/db/schema.clj index 1b4e88553..6ddbbe9d0 100644 --- a/src/clj/orcpub/db/schema.clj +++ b/src/clj/orcpub/db/schema.clj @@ -21,12 +21,6 @@ :db/cardinality :db.cardinality/one :db/noHistory true}) -(defn fulltext-prop [key] - {:db/ident key - :db/valueType :db.type/string - :db/cardinality :db.cardinality/one - :db/fulltext true}) - (defn fulltext-prop [key] {:db/ident key :db/valueType :db.type/string diff --git a/src/clj/orcpub/email.clj b/src/clj/orcpub/email.clj index acffc4a81..258d48c47 100644 --- a/src/clj/orcpub/email.clj +++ b/src/clj/orcpub/email.clj @@ -85,7 +85,7 @@ :subject "Exception" :body [{:type "text/plain" :content (let [writer (java.io.StringWriter.)] - (do (clojure.pprint/pprint (:request context) writer) - (clojure.pprint/pprint (or (ex-data exception) exception) writer) - (str writer)))}]}))) + (clojure.pprint/pprint (:request context) writer) + (clojure.pprint/pprint (or (ex-data exception) exception) writer) + (str writer))}]}))) diff --git a/src/clj/orcpub/pdf.clj b/src/clj/orcpub/pdf.clj index 92f4e1126..937781e20 100644 --- a/src/clj/orcpub/pdf.clj +++ b/src/clj/orcpub/pdf.clj @@ -1,10 +1,11 @@ (ns orcpub.pdf (:require [clojure.string :as s] + [clojure.stacktrace :as strace] + [clojure.java.io :as io] [orcpub.common :as common] [orcpub.dnd.e5.display :as dis5e] [orcpub.dnd.e5.monsters :as monsters] - [orcpub.dnd.e5.options :as options] - [clojure.java.io :as io]) + [orcpub.dnd.e5.options :as options]) (:import (org.apache.pdfbox.pdmodel.interactive.form PDCheckBox PDComboBox PDListBox PDRadioButton PDTextField) (org.apache.pdfbox.cos COSName) (org.apache.pdfbox.pdmodel PDPage PDDocument PDPageContentStream PDResources) @@ -52,7 +53,7 @@ (instance? PDCheckBox field) (if v "Yes" "Off") (instance? PDTextField field) (str v) :else nil)))) - (catch Exception e (prn "failed writing field: " k v (clojure.stacktrace/print-stack-trace e))))) + (catch Exception e (prn "failed writing field: " k v (strace/print-stack-trace e))))) (when flatten (.setNeedAppearances form false) (.flatten form)))) @@ -356,131 +357,128 @@ :let [spell-index (+ i (* j num-boxes-x))]] (if-let [{:keys [class-nm dc attack-bonus spell] :as spell-data} (get (vec spells) spell-index)] - (do - (if spell - (do - (let [{:keys [description - casting-time - duration - level - ritual - range]} spell - x (+ margin-x (* box-width i)) - y (+ margin-y (* box-height j)) - - {:keys [page source description summary components]} spell - - dc-str (str "DC " dc) - remaining-desc-lines - (draw-text-to-box cs - (or description - (if summary - (str summary - " (see " - (if source - (s/upper-case (name source)) - "PHB") - " " - page - " for more details)") - "")) - (:plain fonts) - 8 - (+ x 0.12) ; from the left - (- 11.0 y 1.08) ;from the top down - (- box-width 0.24) - (- box-height 1.13))] - (if (-> components :material-component) - (draw-text-to-box cs - (str (s/capitalize (-> components :material-component))) - (:italic fonts) - 8 - (+ x 0.12) - (- 11.0 y 0.55) - (- box-width 0.24) - 0.5)) - (draw-imagex cs - card-logo-img - (+ x 1.9) - (+ y 0.02) - 1.0 + (let [{:keys [description + casting-time + duration + level + ritual + range]} spell + x (+ margin-x (* box-width i)) + y (+ margin-y (* box-height j)) + + {:keys [page source description summary components]} spell + + dc-str (str "DC " dc) + remaining-desc-lines + (draw-text-to-box cs + (or description + (if summary + (str summary + " (see " + (if source + (s/upper-case (name source)) + "PHB") + " " + page + " for more details)") + "")) + (:plain fonts) + 8 + (+ x 0.12) ; from the left + (- 11.0 y 1.08) ;from the top down + (- box-width 0.24) + (- box-height 1.13))] + (if (-> components :material-component) + (draw-text-to-box cs + (str (s/capitalize (-> components :material-component))) + (:italic fonts) + 8 + (+ x 0.12) + (- 11.0 y 0.55) + (- box-width 0.24) + 0.5)) + (draw-imagex cs + card-logo-img + (+ x 1.9) + (+ y 0.02) + 1.0 + 0.25) + (draw-text-to-box cs + (:name spell) + (:bold fonts) + 10 + (+ x 0.12) + (- 11.0 y) + (- box-width 0.3) + 0.2) + (draw-text-to-box cs + (if ritual " (ritual)" "") + (:italic fonts) + 10 + (+ x 0.12 (string-width (:name spell) (:bold fonts) 10)) + (- 11.0 y) + (- box-width 0.3) + 0.2) + (draw-text-to-box cs + (if (not= class-nm "Homebrew") + (str (spell-school-level spell class-nm) " " dc-str (str " Spell Mod " (common/bonus-str attack-bonus))) + (spell-school-level spell class-nm)) + (:italic fonts) + 8 + (+ x 0.12) + (- 11.0 y 0.19) + (- box-width 0.24) 0.25) - (draw-text-to-box cs - (:name spell) - (:bold fonts) - 10 - (+ x 0.12) - (- 11.0 y) - (- box-width 0.3) - 0.2) - (draw-text-to-box cs - (if ritual " (ritual)" "") - (:italic fonts) - 10 - (+ x 0.12 (string-width (:name spell) (:bold fonts) 10)) - (- 11.0 y) - (- box-width 0.3) - 0.2) - (draw-text-to-box cs - (if (not= class-nm "Homebrew") - (str (spell-school-level spell class-nm) " " dc-str (str " Spell Mod " (common/bonus-str attack-bonus))) - (spell-school-level spell class-nm)) - (:italic fonts) - 8 - (+ x 0.12) - (- 11.0 y 0.19) - (- box-width 0.24) - 0.25) - (if casting-time - (draw-spell-field cs - document - "magic-swirl" - (str (abbreviate-casting-time - (first - (s/split - casting-time - #",")))) - (+ x 0.12) - (- 11.0 y 0.45))) - (if range - (draw-spell-field cs - document - "arrow-dunk" - (abbreviate-range range) - (+ x 0.62) - (- 11.0 y 0.45))) - (draw-spell-field cs - document - "shiny-purse" - (s/join - "," - (remove - nil? - (map - (fn [[k v]] - (if (-> spell :components k) - v)) - {:verbal "V" - :somatic "S" - :material "M"}))) - (+ x 1.12) - (- 11.0 y 0.45)) - (if duration - (draw-spell-field cs - document - "sands-of-time" - (abbreviate-duration duration) - (+ x 1.62) - (- 11.0 y 0.45))) - (if (seq remaining-desc-lines) - (draw-imagex cs - over-img - (+ x 2.3) - (+ y 3.3) - 0.15 - 0.15)) - {:remaining-lines remaining-desc-lines - :spell-name (:name spell)}))))))))))) + (if casting-time + (draw-spell-field cs + document + "magic-swirl" + (str (abbreviate-casting-time + (first + (s/split + casting-time + #",")))) + (+ x 0.12) + (- 11.0 y 0.45))) + (if range + (draw-spell-field cs + document + "arrow-dunk" + (abbreviate-range range) + (+ x 0.62) + (- 11.0 y 0.45))) + (draw-spell-field cs + document + "shiny-purse" + (s/join + "," + (remove + nil? + (map + (fn [[k v]] + (if (-> spell :components k) + v)) + {:verbal "V" + :somatic "S" + :material "M"}))) + (+ x 1.12) + (- 11.0 y 0.45)) + (if duration + (draw-spell-field cs + document + "sands-of-time" + (abbreviate-duration duration) + (+ x 1.62) + (- 11.0 y 0.45))) + (if (seq remaining-desc-lines) + (draw-imagex cs + over-img + (+ x 2.3) + (+ y 3.3) + 0.15 + 0.15)) + {:remaining-lines remaining-desc-lines + :spell-name (:name spell)})))))))) (defn create-monsters-pdf [] (let [page (PDPage.) @@ -494,63 +492,63 @@ (doseq [i (range 0 5)] (let [monster (monsters i)] (draw-text-from-top cs - (:name monster) - PDType1Font/HELVETICA_BOLD - 14 - 0.1 - (+ (* i h) 0.25)) + (:name monster) + PDType1Font/HELVETICA_BOLD + 14 + 0.1 + (+ (* i h) 0.25)) (draw-text-from-top cs - (monsters/monster-subheader monster) - PDType1Font/HELVETICA_OBLIQUE - 12 - 0.1 - (+ (* i h) 0.45)) + (monsters/monster-subheader monster) + PDType1Font/HELVETICA_OBLIQUE + 12 + 0.1 + (+ (* i h) 0.45)) (doseq [j (range 0 6)] (let [ability ([:str :dex :con :int :wis :cha] j) x (+ 0.15 (* 0.65 j))] (draw-text-from-top cs - (name ability) - PDType1Font/HELVETICA_BOLD - 10 - x - (+ (* i h) 0.7)) - (draw-text-from-top cs - (str (ability monster) - " (" - (options/ability-bonus-str (ability monster)) - ")") - PDType1Font/HELVETICA - 12 - x - (+ (* i h) 0.85)))) - (draw-text-from-top cs - "Saving Throws" + (name ability) PDType1Font/HELVETICA_BOLD 10 - 0.1 - (+ (* i h) 1.1)) - (draw-text-from-top cs - (common/print-bonus-map (:saving-throws monster)) + x + (+ (* i h) 0.7)) + (draw-text-from-top cs + (str (ability monster) + " (" + (options/ability-bonus-str (ability monster)) + ")") PDType1Font/HELVETICA - 10 - (+ 0.1 (string-width - "Saving Throws " - PDType1Font/HELVETICA_BOLD - 10)) - (+ (* i h) 1.1)) + 12 + x + (+ (* i h) 0.85)))) (draw-text-from-top cs - "Skills" - PDType1Font/HELVETICA_BOLD - 10 - 0.1 - (+ (* i h) 1.3)) + "Saving Throws" + PDType1Font/HELVETICA_BOLD + 10 + 0.1 + (+ (* i h) 1.1)) (draw-text-from-top cs - (common/print-bonus-map (:skills monster)) - PDType1Font/HELVETICA - 10 - (+ 0.1 (string-width - "Skills " - PDType1Font/HELVETICA_BOLD - 10)) - (+ (* i h) 1.3))))))) + (common/print-bonus-map (:saving-throws monster)) + PDType1Font/HELVETICA + 10 + (+ 0.1 (string-width + "Saving Throws " + PDType1Font/HELVETICA_BOLD + 10)) + (+ (* i h) 1.1)) + (draw-text-from-top cs + "Skills" + PDType1Font/HELVETICA_BOLD + 10 + 0.1 + (+ (* i h) 1.3)) + (draw-text-from-top cs + (common/print-bonus-map (:skills monster)) + PDType1Font/HELVETICA + 10 + (+ 0.1 (string-width + "Skills " + PDType1Font/HELVETICA_BOLD + 10)) + (+ (* i h) 1.3))))))) (.save doc "/home/larry/Documents/test.pdf"))) \ No newline at end of file diff --git a/src/clj/orcpub/pedestal.clj b/src/clj/orcpub/pedestal.clj index 118358319..4e6733e85 100644 --- a/src/clj/orcpub/pedestal.clj +++ b/src/clj/orcpub/pedestal.clj @@ -15,9 +15,9 @@ (defn db-interceptor [conn] {:name :db-interceptor :enter (fn [context] - (let [conn (:conn conn)] - (let [db (d/db conn)] - (update context :request assoc :db db :conn conn))))}) + (let [conn (:conn conn) + db (d/db conn)] + (update context :request assoc :db db :conn conn)))}) (defmulti calculate-etag class) diff --git a/src/clj/orcpub/routes.clj b/src/clj/orcpub/routes.clj index 24dc10f0a..177a1e1af 100644 --- a/src/clj/orcpub/routes.clj +++ b/src/clj/orcpub/routes.clj @@ -3,10 +3,8 @@ [io.pedestal.http.route :as route] [io.pedestal.test :as test] [io.pedestal.http.ring-middlewares :as ring] - [ring.middleware.cookies :only [wrap-cookies]] [ring.middleware.resource :as ring-resource] [ring.util.response :as ring-resp] - [ring.middleware.etag :refer [wrap-etag]] [io.pedestal.http.body-params :as body-params] [io.pedestal.interceptor.error :as error-int] [io.pedestal.interceptor.chain :refer [terminate]] @@ -16,7 +14,7 @@ [buddy.sign.jwt :as jwt] [buddy.hashers :as hashers] [buddy.auth.middleware :refer [authentication-request]] - [pandect.algo.sha1 :refer [sha1]] + [clojure.edn :as edn] [clojure.java.io :as io] [clj-time.core :as t :refer [hours from-now ago]] [clj-time.coerce :as tc :refer [from-date]] @@ -233,7 +231,7 @@ (try (let [resp (login-response request)] resp) - (catch Throwable e (do (prn "E" e) (throw e))))) + (catch Throwable e (prn "E" e) (throw e)))) (defn user-for-email [db email] @@ -258,15 +256,15 @@ (defn do-verification [request params conn & [tx-data]] (let [verification-key (str (java.util.UUID/randomUUID)) now (java.util.Date.)] - (do @(d/transact - conn - [(merge - tx-data - {:orcpub.user/verified? false - :orcpub.user/verification-key verification-key - :orcpub.user/verification-sent now})]) - (send-verification-email request params verification-key) - {:status 200}))) + @(d/transact + conn + [(merge + tx-data + {:orcpub.user/verified? false + :orcpub.user/verification-key verification-key + :orcpub.user/verification-sent now})]) + (send-verification-email request params verification-key) + {:status 200})) (defn register [{:keys [json-params db conn] :as request}] (let [{:keys [username email password send-updates?]} json-params @@ -290,7 +288,7 @@ :orcpub.user/password (hashers/encrypt password) :orcpub.user/send-updates? send-updates? :orcpub.user/created (java.util.Date.)})) - (catch Throwable e (do (prn e) (throw e)))))) + (catch Throwable e (prn e) (throw e))))) (def user-for-verification-key-query '[:find ?e @@ -375,7 +373,7 @@ (if id (do-send-password-reset id email conn request) {:status 400 :body {:error :no-account}})) - (catch Throwable e (do (prn e) (throw e))))) + (catch Throwable e (prn e) (throw e)))) (defn do-password-reset [conn user-id password] @(d/transact @@ -395,7 +393,7 @@ (not= password verify-password) {:status 400 :message "Passwords do not match"} (seq (registration/validate-password password)) {:status 400 :message "New password is invalid"} :else (do-password-reset conn id password))) - (catch Throwable t (do (prn t) (throw t))))) + (catch Throwable t (prn t) (throw t)))) (def font-sizes (merge @@ -457,7 +455,7 @@ (catch Exception e (prn "FAILED ADDING SPELLS CARDS!" e)))) (defn character-pdf-2 [req] - (let [fields (-> req :form-params :body clojure.edn/read-string) + (let [fields (-> req :form-params :body edn/read-string) {:keys [image-url image-url-failed faction-image-url faction-image-url-failed spells-known custom-spells spell-save-dcs spell-attack-mods print-spell-cards?]} fields input (.openStream (io/resource (cond (find fields :spellcasting-class-6) "fillable-char-sheet-6-spells.pdf" @@ -717,7 +715,7 @@ (if (:db/id clean-character) (update-character db conn clean-character username) (create-new-character conn clean-character username)))) - (catch Exception e (do (prn "ERROR" e) (throw e)))))) + (catch Exception e (prn "ERROR" e) (throw e))))) (defn save-character [{:keys [db transit-params body conn identity] :as request}] (do-save-character db conn transit-params identity)) diff --git a/src/cljc/orcpub/dnd/e5/classes.cljc b/src/cljc/orcpub/dnd/e5/classes.cljc index 522ad4d91..402ac57fa 100644 --- a/src/cljc/orcpub/dnd/e5/classes.cljc +++ b/src/cljc/orcpub/dnd/e5/classes.cljc @@ -1659,8 +1659,8 @@ (defn favored-enemy-option [language-map [enemy-type info]] (let [vec-info? (sequential? info) languages (if vec-info? info (:languages info)) - name (if vec-info? (common/kw-to-name enemy-type) (:name info))] - (let [language-options (zipmap languages (repeat true))] + name (if vec-info? (common/kw-to-name enemy-type) (:name info)) + language-options (zipmap languages (repeat true))] (t/option-cfg {:name name :selections (if (> (count languages) 1) @@ -1672,7 +1672,7 @@ nil? [(if (= 1 (count languages)) (mod5e/language (first languages))) - (mod/set-mod ?ranger-favored-enemies enemy-type)])})))) + (mod/set-mod ?ranger-favored-enemies enemy-type)])}))) (defn favored-enemy-selection [language-map order] (t/selection-cfg diff --git a/src/cljc/orcpub/dnd/e5/options.cljc b/src/cljc/orcpub/dnd/e5/options.cljc index 5499f006e..a867e3e97 100644 --- a/src/cljc/orcpub/dnd/e5/options.cljc +++ b/src/cljc/orcpub/dnd/e5/options.cljc @@ -603,8 +603,8 @@ all-spells (select-keys (or spells (spell-lists (or spell-list-kw class-key))) (keys slots)) - acquire? (= :acquire known-mode)] - (let [options (flatten + acquire? (= :acquire known-mode) + options (flatten (map (fn [[lvl spell-keys]] (let [spell-keys (vec spell-keys) @@ -634,7 +634,7 @@ :class-name cls-nm :min num :max (if (not acquire?) num) - :options options}))])))) + :options options}))]))) {} spells-known)) diff --git a/src/cljc/orcpub/entity.cljc b/src/cljc/orcpub/entity.cljc index be83c6514..571f7dcdd 100644 --- a/src/cljc/orcpub/entity.cljc +++ b/src/cljc/orcpub/entity.cljc @@ -6,6 +6,7 @@ [orcpub.entity-spec :as es] [orcpub.template :as t] [orcpub.entity.strict :as strict] + [clojure.string :as s] [clojure.set :refer [difference union intersection]])) (spec/def ::key ::strict/key) @@ -229,7 +230,7 @@ (defn take-1 "Returns the pair [element, s'] where s' is set s with element removed." - [s] {:pre [(not (empty? s))]} + [s] {:pre [(seq s)]} (let [item (first s)] [item (without s item)])) @@ -694,8 +695,8 @@ (defn name-to-kw [name] (-> name - clojure.string/lower-case - (clojure.string/replace #"\W" "-") + s/lower-case + (s/replace #"\W" "-") keyword)) (defn get-option-value-path [template entity path] diff --git a/src/cljs/orcpub/dnd/e5/db.cljs b/src/cljs/orcpub/dnd/e5/db.cljs index 435499cf3..1f361603b 100644 --- a/src/cljs/orcpub/dnd/e5/db.cljs +++ b/src/cljs/orcpub/dnd/e5/db.cljs @@ -229,9 +229,9 @@ (if-let [stored-str (if js/window.localStorage (.getItem js/window.localStorage local-storage-key))] (try (reader/read-string stored-str) - (catch js/Object e (do (prn "E" e) - (js/console.warn "UNREADABLE ITEM FOUND, REMOVING.." local-storage-key stored-str) - (.removeItem js/window.localStorage local-storage-key)))))) + (catch js/Object e (prn "E" e) + (js/console.warn "UNREADABLE ITEM FOUND, REMOVING.." local-storage-key stored-str) + (.removeItem js/window.localStorage local-storage-key))))) (defn reg-local-store-cofx [key local-storage-key item-spec & [item-fn]] (re-frame/reg-cofx diff --git a/src/cljs/orcpub/dnd/e5/events.cljs b/src/cljs/orcpub/dnd/e5/events.cljs index de09a3b0e..6a0b65156 100644 --- a/src/cljs/orcpub/dnd/e5/events.cljs +++ b/src/cljs/orcpub/dnd/e5/events.cljs @@ -63,8 +63,8 @@ default-class default-subclass]] [orcpub.dnd.e5.autosave-fx] - [re-frame.core :refer [reg-event-db reg-event-fx reg-fx inject-cofx path trim-v - after dispatch dispatch-sync subscribe ->interceptor]] + [re-frame.core :refer [reg-event-db reg-event-fx reg-fx inject-cofx path + after dispatch subscribe ->interceptor]] [cljs.spec.alpha :as spec] [cljs-http.client :as http] [cljs.core.async :refer [= (count text) 3) + name-result (name-result search-text) + top-result (cond + dice-result {:type :dice-roll + :result dice-result} + (spells/spell-map kw) {:type :spell + :result (spells/spell-map kw)} + (monsters/monster-map kw) {:type :monster + :result (monsters/monster-map kw)} + (mi/magic-item-map kw) {:type :magic-item + :result (mi/magic-item-map kw)} + (= "tavern name" search-text) {:type :tavern-name + :result (char-rand5e/random-tavern-name)} + name-result name-result + :else nil) + filter-xform (filter-by-name-xform search-text :name) + top-spells (if (>= (count text) 3) + (sequence + filter-xform + spells/spells)) + top-monsters (if (>= (count text) 3) (sequence filter-xform - spells/spells)) - top-monsters (if (>= (count text) 3) - (sequence - filter-xform - monsters/monsters))] - (cond-> {} - top-result (assoc :top-result top-result) - (seq top-spells) (update :results conj {:type :spell - :results top-spells}) - (seq top-monsters) (update :results conj {:type :monster - :results top-monsters}))))) + monsters/monsters))] + (cond-> {} + top-result (assoc :top-result top-result) + (seq top-spells) (update :results conj {:type :spell + :results top-spells}) + (seq top-monsters) (update :results conj {:type :monster + :results top-monsters})))) (reg-event-db @@ -2405,27 +2405,27 @@ (or (first (drop-while #(>= % current-initiative) initiatives)) (first initiatives)) (second initiatives)) - round (get combat :round 1)] - (let [next-round? (and current-initiative - (> next-initiative current-initiative)) - updated (cond-> combat - true (assoc :current-initiative next-initiative) - next-round? (assoc :round (inc round)) - next-round? update-conditions) - removed-conditions (if next-round? - (filter - (comp seq :removed-conditions) - (flatten - (map - (fn [[monster-kw individuals]] - (map - (fn [[individual-index {:keys [removed-conditions]}]] - {:type :monster - :index individual-index - :name (get-in monster-map [monster-kw :name]) - :removed-conditions (map :type removed-conditions)}) - individuals)) - (:monster-data updated)))))] + round (get combat :round 1) + next-round? (and current-initiative + (> next-initiative current-initiative)) + updated (cond-> combat + true (assoc :current-initiative next-initiative) + next-round? (assoc :round (inc round)) + next-round? update-conditions) + removed-conditions (if next-round? + (filter + (comp seq :removed-conditions) + (flatten + (map + (fn [[monster-kw individuals]] + (map + (fn [[individual-index {:keys [removed-conditions]}]] + {:type :monster + :index individual-index + :name (get-in monster-map [monster-kw :name]) + :removed-conditions (map :type removed-conditions)}) + individuals)) + (:monster-data updated)))))] {:dispatch-n (cond-> [[::combat/set-combat updated]] (seq removed-conditions) (conj [:show-message @@ -2435,7 +2435,7 @@ (fn [i {:keys [name index removed-conditions]}] ^{:key i} [:div.m-b-5 (str name " #" (inc index) " is no longer " (common/list-print (map common/kw-to-name removed-conditions) "or") ".")]) - removed-conditions))]]))})))) + removed-conditions))]]))}))) (reg-event-db ::encounters/set-encounter-path-prop diff --git a/src/cljs/orcpub/dnd/e5/views.cljs b/src/cljs/orcpub/dnd/e5/views.cljs index 2e497e0e2..627a069de 100644 --- a/src/cljs/orcpub/dnd/e5/views.cljs +++ b/src/cljs/orcpub/dnd/e5/views.cljs @@ -22,7 +22,6 @@ [orcpub.dnd.e5.party :as party] [orcpub.dnd.e5.character.random :as char-random] [orcpub.dnd.e5.character.equipment :as char-equip] - [cljs.pprint :refer [pprint]] [orcpub.registration :as registration] [orcpub.dnd.e5 :as e5] [orcpub.dnd.e5.magic-items :as mi] @@ -1519,10 +1518,9 @@ [:span.m-l-5.m-r-5 "/"] (map (fn [{:keys [::char/class-name ::char/level ::char/subclass-name]}] - (let [] - [:span - [:div.class-name (str class-name) ] [:div.level (str "(" level ")")] - [:div.f-s-12.m-t-5.opacity-6.sub-class-name (if subclass-name subclass-name)]])) + [:span + [:div.class-name (str class-name)] [:div.level (str "(" level ")")] + [:div.f-s-12.m-t-5.opacity-6.sub-class-name (if subclass-name subclass-name)]]) classes)))])]] (if (and show-owner? (some? owner) @@ -7898,4 +7896,3 @@ {:style close-icon-style :on-click (make-event-handler ::char/filter-items "")}]]] [item-list-items]]])) - From dba6d15aec5770a85e0e0d087cb03974fde19841 Mon Sep 17 00:00:00 2001 From: Pireax Date: Fri, 17 Jul 2020 00:18:17 +0200 Subject: [PATCH 3/9] Fix remaining warnings --- src/clj/orcpub/pdf.clj | 6 +----- src/clj/orcpub/routes.clj | 11 ++--------- src/clj/orcpub/security.clj | 2 +- src/clj/orcpub/styles/core.clj | 3 +-- src/clj/orcpub/system.clj | 4 ++-- src/cljc/orcpub/components.cljc | 3 +-- src/cljc/orcpub/dnd/e5/classes.cljc | 2 +- src/cljc/orcpub/dnd/e5/magic_items.cljc | 9 ++++----- src/cljc/orcpub/dnd/e5/selections.cljc | 1 - src/cljc/orcpub/dnd/e5/templates/scag.cljc | 2 +- src/cljc/orcpub/dnd/e5/templates/ua_feats.cljc | 2 +- src/cljc/orcpub/dnd/e5/templates/ua_race_feats.cljc | 2 +- .../orcpub/dnd/e5/templates/ua_revised_ranger.cljc | 2 +- src/cljc/orcpub/dnd/e5/templates/ua_skill_feats.cljc | 2 +- .../dnd/e5/templates/ua_warlock_and_wizard.cljc | 2 +- src/cljc/orcpub/dnd/e5/views_2.cljc | 3 +-- src/cljs/orcpub/character_builder.cljs | 7 ++----- src/cljs/orcpub/dnd/e5/spell_subs.cljs | 6 ++---- src/cljs/orcpub/dnd/e5/views.cljs | 4 +--- web/cljs/orcpub/core.cljs | 2 -- 20 files changed, 25 insertions(+), 50 deletions(-) diff --git a/src/clj/orcpub/pdf.clj b/src/clj/orcpub/pdf.clj index 937781e20..fdbbb1b28 100644 --- a/src/clj/orcpub/pdf.clj +++ b/src/clj/orcpub/pdf.clj @@ -6,14 +6,10 @@ [orcpub.dnd.e5.display :as dis5e] [orcpub.dnd.e5.monsters :as monsters] [orcpub.dnd.e5.options :as options]) - (:import (org.apache.pdfbox.pdmodel.interactive.form PDCheckBox PDComboBox PDListBox PDRadioButton PDTextField) - (org.apache.pdfbox.cos COSName) + (:import (org.apache.pdfbox.pdmodel.interactive.form PDCheckBox PDTextField) (org.apache.pdfbox.pdmodel PDPage PDDocument PDPageContentStream PDResources) - (org.apache.pdfbox.pdmodel.graphics.image PDImageXObject) - (java.io ByteArrayOutputStream ByteArrayInputStream) (org.apache.pdfbox.pdmodel.graphics.image JPEGFactory LosslessFactory) (org.apache.pdfbox.pdmodel.font PDType1Font PDFont PDType0Font) - (org.eclipse.jetty.server.handler.gzip GzipHandler) (javax.imageio ImageIO) (java.net URL))) diff --git a/src/clj/orcpub/routes.clj b/src/clj/orcpub/routes.clj index 177a1e1af..ca31fa40d 100644 --- a/src/clj/orcpub/routes.clj +++ b/src/clj/orcpub/routes.clj @@ -43,15 +43,8 @@ [hiccup.page :as page] [environ.core :as environ] [clojure.set :as sets]) - (:import (org.apache.pdfbox.pdmodel.interactive.form PDCheckBox PDComboBox PDListBox PDRadioButton PDTextField) - - (org.apache.pdfbox.pdmodel PDDocument PDPage PDPageContentStream) - (org.apache.pdfbox.pdmodel.graphics.image PDImageXObject) - (java.io ByteArrayOutputStream ByteArrayInputStream) - (org.apache.pdfbox.pdmodel.graphics.image JPEGFactory LosslessFactory) - (org.eclipse.jetty.server.handler.gzip GzipHandler) - (javax.imageio ImageIO) - (java.net URL)) + (:import (org.apache.pdfbox.pdmodel PDDocument PDPage PDPageContentStream) + (java.io ByteArrayOutputStream ByteArrayInputStream)) (:gen-class)) (deftype FixedBuffer [^long len]) diff --git a/src/clj/orcpub/security.clj b/src/clj/orcpub/security.clj index c6d7c3696..9690a4e1a 100644 --- a/src/clj/orcpub/security.clj +++ b/src/clj/orcpub/security.clj @@ -1,5 +1,5 @@ (ns orcpub.security - (:require [clj-time.core :as t :refer [ago now minutes hours]])) + (:require [clj-time.core :as t :refer [ago minutes]])) (defn compare-dates [attempt-1 attempt-2] (compare (:date attempt-1) (:date attempt-2))) diff --git a/src/clj/orcpub/styles/core.clj b/src/clj/orcpub/styles/core.clj index 81d64d01e..34dbea4cb 100644 --- a/src/clj/orcpub/styles/core.clj +++ b/src/clj/orcpub/styles/core.clj @@ -1,6 +1,5 @@ (ns orcpub.styles.core - (:require [garden.def :refer [defstylesheet defstyles]] - [garden.stylesheet :refer [at-media at-keyframes]] + (:require [garden.stylesheet :refer [at-media at-keyframes]] [garden.units :refer [px]] [orcpub.constants :as const] [garden.selectors :as s])) diff --git a/src/clj/orcpub/system.clj b/src/clj/orcpub/system.clj index 169af70b7..f170f6eb2 100644 --- a/src/clj/orcpub/system.clj +++ b/src/clj/orcpub/system.clj @@ -1,6 +1,6 @@ (ns orcpub.system (:require [com.stuartsierra.component :as component] - [reloaded.repl :refer [init start stop go reset]] + [reloaded.repl :as rrepl] [io.pedestal.http :as http] [orcpub.pedestal :as pedestal] [orcpub.routes :as routes] @@ -53,4 +53,4 @@ (pedestal/new-pedestal) [:service-map :conn]))) -(reloaded.repl/set-init! #(system :prod)) +(rrepl/set-init! #(system :prod)) diff --git a/src/cljc/orcpub/components.cljc b/src/cljc/orcpub/components.cljc index a9bb3d7bf..a2c99c4e3 100644 --- a/src/cljc/orcpub/components.cljc +++ b/src/cljc/orcpub/components.cljc @@ -1,6 +1,5 @@ (ns orcpub.components - (:require [re-frame.core :refer [dispatch]] - [clojure.string :as s] + (:require [clojure.string :as s] #?(:cljs [reagent.core :refer [atom]]))) (defn checkbox [selected? disable?] diff --git a/src/cljc/orcpub/dnd/e5/classes.cljc b/src/cljc/orcpub/dnd/e5/classes.cljc index 402ac57fa..53524117a 100644 --- a/src/cljc/orcpub/dnd/e5/classes.cljc +++ b/src/cljc/orcpub/dnd/e5/classes.cljc @@ -13,7 +13,7 @@ [orcpub.dnd.e5.spells :as spells5e] [orcpub.dnd.e5.spell-lists :as sl5e] [orcpub.dnd.e5.template-base :as t-base] - [re-frame.core :refer [reg-sub reg-sub-raw dispatch subscribe]] + [re-frame.core :refer [subscribe]] [clojure.string :as s])) (spec/def ::name (spec/and string? common/starts-with-letter?)) diff --git a/src/cljc/orcpub/dnd/e5/magic_items.cljc b/src/cljc/orcpub/dnd/e5/magic_items.cljc index 9db954dcb..941f540f7 100644 --- a/src/cljc/orcpub/dnd/e5/magic_items.cljc +++ b/src/cljc/orcpub/dnd/e5/magic_items.cljc @@ -3,7 +3,6 @@ [orcpub.common :as common] [orcpub.modifiers :as mod] [orcpub.entity :as entity] - [orcpub.dnd.e5.weapons :as weapons] [orcpub.dnd.e5.armor :as armor5e] [orcpub.dnd.e5.weapons :as weapons5e] [orcpub.dnd.e5.equipment :as equip5e] @@ -2914,8 +2913,8 @@ The boots regain 2 hours of flying capability for every 12 hours they aren’t i (def weapons-and-ammunition (concat - weapons/weapons - weapons/ammunition)) + weapons5e/weapons + weapons5e/ammunition)) (defn add-key [item] (assoc item :key (common/name-to-kw (name-key item)))) @@ -2931,7 +2930,7 @@ The boots regain 2 hours of flying capability for every 12 hours they aren’t i (types type))) (defn subtypes-fn [subtypes] - (fn [{:keys [::weapons/subtype]}] + (fn [{:keys [::weapons5e/subtype]}] (subtypes subtype))) (defn keys-fn [keys] @@ -3059,7 +3058,7 @@ The boots regain 2 hours of flying capability for every 12 hours they aren’t i (def all-weapons-map (merge - weapons/weapons-map + weapons5e/weapons-map magic-weapon-map)) (def magic-armor-xform diff --git a/src/cljc/orcpub/dnd/e5/selections.cljc b/src/cljc/orcpub/dnd/e5/selections.cljc index 348953b5c..2d2820256 100644 --- a/src/cljc/orcpub/dnd/e5/selections.cljc +++ b/src/cljc/orcpub/dnd/e5/selections.cljc @@ -13,7 +13,6 @@ [orcpub.dnd.e5.spells :as spells5e] [orcpub.dnd.e5.spell-lists :as sl5e] [orcpub.dnd.e5.template-base :as t-base] - [re-frame.core :refer [reg-sub reg-sub-raw dispatch subscribe]] [clojure.string :as s])) (spec/def ::name (spec/and string? common/starts-with-letter?)) diff --git a/src/cljc/orcpub/dnd/e5/templates/scag.cljc b/src/cljc/orcpub/dnd/e5/templates/scag.cljc index e10e3bee1..86dc1ac48 100644 --- a/src/cljc/orcpub/dnd/e5/templates/scag.cljc +++ b/src/cljc/orcpub/dnd/e5/templates/scag.cljc @@ -10,7 +10,7 @@ [orcpub.dnd.e5.equipment :as equip5e] [orcpub.dnd.e5.spell-lists :as sl] [orcpub.dnd.e5.options :as opt5e] - [re-frame.core :refer [subscribe]])) + #_[re-frame.core :refer [subscribe]])) #_(def scag-barbarian {:name "Barbarian" diff --git a/src/cljc/orcpub/dnd/e5/templates/ua_feats.cljc b/src/cljc/orcpub/dnd/e5/templates/ua_feats.cljc index ef411a2f6..e02b71f26 100644 --- a/src/cljc/orcpub/dnd/e5/templates/ua_feats.cljc +++ b/src/cljc/orcpub/dnd/e5/templates/ua_feats.cljc @@ -4,7 +4,7 @@ [orcpub.dnd.e5.character :as char5e] [orcpub.template :as t] [orcpub.common :as common] - [re-frame.core :refer [subscribe]] + #_[re-frame.core :refer [subscribe]] [clojure.string :as s])) #_(defn weapon-attack-bonus-mod [weapons bonus] diff --git a/src/cljc/orcpub/dnd/e5/templates/ua_race_feats.cljc b/src/cljc/orcpub/dnd/e5/templates/ua_race_feats.cljc index 896ceae12..45c12af54 100644 --- a/src/cljc/orcpub/dnd/e5/templates/ua_race_feats.cljc +++ b/src/cljc/orcpub/dnd/e5/templates/ua_race_feats.cljc @@ -5,7 +5,7 @@ [orcpub.dnd.e5.units :as units5e] [orcpub.template :as t] [orcpub.common :as common] - [re-frame.core :refer [subscribe]] + #_[re-frame.core :refer [subscribe]] [clojure.string :as s])) #_(def grudge-bearer-foe-selection diff --git a/src/cljc/orcpub/dnd/e5/templates/ua_revised_ranger.cljc b/src/cljc/orcpub/dnd/e5/templates/ua_revised_ranger.cljc index 33b358f49..f1fd28945 100644 --- a/src/cljc/orcpub/dnd/e5/templates/ua_revised_ranger.cljc +++ b/src/cljc/orcpub/dnd/e5/templates/ua_revised_ranger.cljc @@ -7,7 +7,7 @@ [orcpub.template :as t] [orcpub.common :as common] [clojure.string :as s] - [re-frame.core :refer [subscribe]])) + #_[re-frame.core :refer [subscribe]])) #_(defn favored-enemy-selection [name types] (t/selection-cfg diff --git a/src/cljc/orcpub/dnd/e5/templates/ua_skill_feats.cljc b/src/cljc/orcpub/dnd/e5/templates/ua_skill_feats.cljc index f70c23376..37c8fd77b 100644 --- a/src/cljc/orcpub/dnd/e5/templates/ua_skill_feats.cljc +++ b/src/cljc/orcpub/dnd/e5/templates/ua_skill_feats.cljc @@ -4,7 +4,7 @@ [orcpub.dnd.e5.character :as char5e] [orcpub.template :as t] [orcpub.common :as common] - [re-frame.core :refer [subscribe]] + #_[re-frame.core :refer [subscribe]] [clojure.string :as s])) #_(def action #(mod5e/action %)) diff --git a/src/cljc/orcpub/dnd/e5/templates/ua_warlock_and_wizard.cljc b/src/cljc/orcpub/dnd/e5/templates/ua_warlock_and_wizard.cljc index e9bdd40c6..ce9da9808 100644 --- a/src/cljc/orcpub/dnd/e5/templates/ua_warlock_and_wizard.cljc +++ b/src/cljc/orcpub/dnd/e5/templates/ua_warlock_and_wizard.cljc @@ -6,7 +6,7 @@ [orcpub.dnd.e5.units :as units5e] [orcpub.modifiers :as mod] [orcpub.template :as t] - [re-frame.core :refer [subscribe]])) + #_[re-frame.core :refer [subscribe]])) #_(def warlock-option-cfg diff --git a/src/cljc/orcpub/dnd/e5/views_2.cljc b/src/cljc/orcpub/dnd/e5/views_2.cljc index 1cabd4b44..a59e6fdb3 100644 --- a/src/cljc/orcpub/dnd/e5/views_2.cljc +++ b/src/cljc/orcpub/dnd/e5/views_2.cljc @@ -1,7 +1,6 @@ (ns orcpub.dnd.e5.views-2 (:require [orcpub.route-map :as routes] - [clojure.string :as s] - #?(:cljs [re-frame.core :refer [subscribe dispatch dispatch-sync]]))) + [clojure.string :as s])) (defn style [style] #?(:cljs style) diff --git a/src/cljs/orcpub/character_builder.cljs b/src/cljs/orcpub/character_builder.cljs index 52f264f1e..2a08db3b6 100644 --- a/src/cljs/orcpub/character_builder.cljs +++ b/src/cljs/orcpub/character_builder.cljs @@ -33,21 +33,18 @@ [orcpub.dnd.e5.equipment :as equip5e] [orcpub.dnd.e5.skills :as skill5e] [orcpub.dnd.e5.events :as events5e] - [orcpub.dnd.e5.db :as db5e] + [orcpub.dnd.e5.db :as db] [orcpub.dnd.e5.views :as views5e] [orcpub.route-map :as routes] [orcpub.pdf-spec :as pdf-spec] [orcpub.user-agent :as user-agent] - [orcpub.dnd.e5.db :as db] [clojure.spec.alpha :as spec] [clojure.spec.test.alpha :as stest] - [cljs.core.async :refer [ Date: Fri, 17 Jul 2020 00:26:07 +0200 Subject: [PATCH 4/9] Add linting to CI --- .github/workflows/continuous-integration.yml | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index a9c346212..7a2718f01 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -3,21 +3,19 @@ name: Continuous Integration on: [pull_request] jobs: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Run linter + run: lein lint build-and-test: name: Build and Test runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2 - - name: Setup java - uses: actions/setup-java@v1 - with: - java-version: 1.8 - - name: Setup Clojure tools - uses: DeLaGuardo/setup-clojure@master - with: - tools-deps: latest - lein: latest - boot: latest - name: Run tests run: lein test From 5b67b26c839d4eaaea99b158bc2d23dfbfe03cd5 Mon Sep 17 00:00:00 2001 From: Pireax Date: Fri, 17 Jul 2020 01:42:44 +0200 Subject: [PATCH 5/9] Add kibit and fix code styling with kibit --- project.clj | 1 + src/clj/orcpub/pdf.clj | 6 ++-- src/clj/orcpub/routes.clj | 16 +++++------ src/clj/orcpub/security.clj | 4 +-- src/cljc/orcpub/dice.cljc | 2 +- src/cljc/orcpub/dnd/e5/character/random.cljc | 8 +++--- src/cljc/orcpub/route_map.cljc | 2 +- src/cljs/orcpub/character_builder.cljs | 18 ++++++------ src/cljs/orcpub/dnd/e5/db.cljs | 5 ++-- src/cljs/orcpub/dnd/e5/equipment_subs.cljs | 4 +-- src/cljs/orcpub/dnd/e5/events.cljs | 2 +- src/cljs/orcpub/dnd/e5/spell_subs.cljs | 30 ++++++++++---------- src/cljs/orcpub/dnd/e5/subs.cljs | 14 ++++----- src/cljs/orcpub/dnd/e5/views.cljs | 27 +++++++++--------- web/cljs/orcpub/core.cljs | 2 +- 15 files changed, 69 insertions(+), 72 deletions(-) diff --git a/project.clj b/project.clj index 7ddee03e4..682bf49dd 100644 --- a/project.clj +++ b/project.clj @@ -70,6 +70,7 @@ [lein-garden "0.3.0"] [lein-environ "1.1.0"] [lein-cljfmt "0.6.8"] + [lein-kibit "0.1.8"] #_[lein-resource "16.9.1"]] :source-paths ["src/clj" "src/cljc" "src/cljs"] diff --git a/src/clj/orcpub/pdf.clj b/src/clj/orcpub/pdf.clj index fdbbb1b28..22363019b 100644 --- a/src/clj/orcpub/pdf.clj +++ b/src/clj/orcpub/pdf.clj @@ -147,7 +147,7 @@ (defn draw-lines-to-box [cs lines font font-size x y height] (let [leading (* font-size 1.1) - max-lines (- (/ (* 72 height) leading) 1) + max-lines (dec (/ (* 72 height) leading)) units-x (* 72 x) units-y (* 72 y) fitting-lines (vec (take max-lines lines))] @@ -384,9 +384,9 @@ (- 11.0 y 1.08) ;from the top down (- box-width 0.24) (- box-height 1.13))] - (if (-> components :material-component) + (if (:material-component components) (draw-text-to-box cs - (str (s/capitalize (-> components :material-component))) + (str (s/capitalize (:material-component components))) (:italic fonts) 8 (+ x 0.12) diff --git a/src/clj/orcpub/routes.clj b/src/clj/orcpub/routes.clj index ca31fa40d..a166ad730 100644 --- a/src/clj/orcpub/routes.clj +++ b/src/clj/orcpub/routes.clj @@ -644,12 +644,12 @@ (let [current-character (d/pull db '[*] id) problems [] #_(dnd-e5-char-type-problems current-character) current-valid? (spec/valid? ::se/entity current-character)] - (if (not current-valid?) - (do (prn "INVALID CHARACTER FOUND, REPLACING" #_current-character) - (prn "INVALID CHARACTER EXPLANATION" #_(spec/explain-data ::se/entity current-character)))) + (when-not current-valid? + (prn "INVALID CHARACTER FOUND, REPLACING" #_current-character) + (prn "INVALID CHARACTER EXPLANATION" #_(spec/explain-data ::se/entity current-character))) (if (seq problems) {:status 400 :body problems} - (if (not current-valid?) + (if-not current-valid? (let [new-character (entity/remove-ids character) tx [[:db/retractEntity (:db/id current-character)] (-> new-character @@ -664,8 +664,7 @@ new-ids (entity/db-ids new-character) retract-ids (sets/difference current-ids new-ids) retractions (map - (fn [retract-id] - [:db/retractEntity retract-id]) + :db/retractEntity retract-ids) tx (conj retractions (-> new-character @@ -691,7 +690,7 @@ (update-in character [::se/values ::char5e/xps] #(try - (if (not (s/blank? %)) + (if-not (s/blank? %) (Long/parseLong %) 0) (catch NumberFormatException e 0))) @@ -947,8 +946,7 @@ (def expanded-index-routes (route/expand-routes - (into #{} index-page-routes))) - + (set index-page-routes))) (def service-error-handler (error-int/error-dispatch [ctx ex] diff --git a/src/clj/orcpub/security.clj b/src/clj/orcpub/security.clj index 9690a4e1a..ef64384d9 100644 --- a/src/clj/orcpub/security.clj +++ b/src/clj/orcpub/security.clj @@ -54,10 +54,10 @@ @failed-login-attempts-by-username)) (defn usernames-for-attempts [attempts] - (into #{} (map :user attempts))) + (set (map :user attempts))) (defn ips-for-attempts [attempts] - (into #{} (map :ip attempts))) + (set (map :ip attempts))) (defn multiple-account-access-aux [ip attempts-by-ip] (some-> ip diff --git a/src/cljc/orcpub/dice.cljc b/src/cljc/orcpub/dice.cljc index a9b1bc95b..a9ea7fb53 100644 --- a/src/cljc/orcpub/dice.cljc +++ b/src/cljc/orcpub/dice.cljc @@ -8,7 +8,7 @@ (inc (rand-int sides))) (defn roll-n [num sides] - (take num (repeatedly #(die-roll sides)))) + (repeatedly num #(die-roll sides))) (defn dice-roll [{:keys [num sides drop-num modifier]}] (apply + diff --git a/src/cljc/orcpub/dnd/e5/character/random.cljc b/src/cljc/orcpub/dnd/e5/character/random.cljc index 33949b9e9..13f8a4227 100644 --- a/src/cljc/orcpub/dnd/e5/character/random.cljc +++ b/src/cljc/orcpub/dnd/e5/character/random.cljc @@ -1643,7 +1643,7 @@ (def sexes [::male ::female]) -(def sexes-set (into #{} sexes)) +(def sexes-set (set sexes)) (def human-subraces [::calishite @@ -1655,7 +1655,7 @@ ::rashemi ::mulan]) -(def subraces-set (into #{} human-subraces)) +(def subraces-set (set human-subraces)) (def races [::elf @@ -1665,7 +1665,7 @@ ::human ::human]) -(def races-set (into #{} races)) +(def races-set (set races)) (defn random-sex [] (rand-nth sexes)) @@ -1788,7 +1788,7 @@ (set-name mulan-names ::female))) (def human-subraces-set - (into #{} human-subraces)) + (set human-subraces)) (def races-and-subraces (concat (vec human-subraces) diff --git a/src/cljc/orcpub/route_map.cljc b/src/cljc/orcpub/route_map.cljc index 22a11778b..ba34805b0 100644 --- a/src/cljc/orcpub/route_map.cljc +++ b/src/cljc/orcpub/route_map.cljc @@ -190,4 +190,4 @@ (apply bidi/path-for routes args)) (defn match-route [path] - (->> path (bidi/match-route routes))) + (bidi/match-route routes path)) diff --git a/src/cljs/orcpub/character_builder.cljs b/src/cljs/orcpub/character_builder.cljs index 2a08db3b6..5b3ffb055 100644 --- a/src/cljs/orcpub/character_builder.cljs +++ b/src/cljs/orcpub/character_builder.cljs @@ -256,7 +256,7 @@ (let [options (::t/options selection) selected-classes @(subscribe [::char5e/levels]) unselected-classes (remove - (into #{} (keys selected-classes)) + (set (keys selected-classes)) (map ::t/key options)) unselected-classes-set (set unselected-classes) remaining-classes (filter @@ -439,7 +439,7 @@ (let [{:keys [::t/key]} selection selected-items @(subscribe [:entity-option key]) item-map @(subscribe item-map-sub) - selected-keys (into #{} (map ::entity/key selected-items)) + selected-keys (set (map ::entity/key selected-items)) options (entity/selection-options selection) magic-weapons (= key :magic-weapons)] [:div @@ -619,7 +619,7 @@ {:class-name (if (not homebrew?) "opacity-5 hover-opacity-full") :on-click (toggle-homebrew path)} [tooltip - (if (not homebrew?) + (if-not homebrew? (str "Homebrew is off for " title " - enabling this option allows you select options you would not normally have (turns on homebrew rules)") (str "Homebrew is on for " title " - you can select anything and make it homebrew")) (views5e/svg-icon "beer-stein" 18)]])] @@ -826,7 +826,7 @@ (<= min num-increased max)) 0 (- min num-increased)) - allowed-abilities (into #{} (map ::t/key options)) + allowed-abilities (set (map ::t/key options)) ancestors-title (views-aux/ancestor-names-string built-template path)] ^{:key i} [:div @@ -1102,7 +1102,7 @@ (def point-buy-starting-abilities-fn #(set-abilities! (char5e/abilities 8 8 8 8 8 8))) -(def reroll-abilities-fn #(reroll-abilities)) +(def reroll-abilities-fn reroll-abilities) (def standard-abilities-fn #(set-abilities! (char5e/abilities 15 14 13 12 10 8))) @@ -1180,8 +1180,8 @@ selected-skills (get-in character path) selected-count (count selected-skills) remaining (- max selected-count) - available-skills (into #{} (map ::t/key options)) - selected-skill-keys (into #{} (map ::entity/key selected-skills))] + available-skills (set (map ::t/key options)) + selected-skill-keys (set (map ::entity/key selected-skills))] (doall (map (fn [{:keys [name key ability icon description]}] @@ -1563,7 +1563,7 @@ name]) [:div.t-a-c (views5e/svg-icon icon 32)]] - (if (not (= total-remaining 0)) + (if (not (zero? total-remaining)) [:div.flex.justify-cont-end.m-t--10.p-l-20 (remaining-indicator total-remaining 12 11)])])) pages))])) @@ -1904,7 +1904,7 @@ (defn al-legality [] (let [expanded? (r/atom false)] (fn [al-illegal-reasons used-resources] - (let [num-resources (count (into #{} (map :resource-key used-resources))) + (let [num-resources (count (set (map :resource-key used-resources))) multiple-resources? (> num-resources 1) has-homebrew? @(subscribe [:has-homebrew?]) mobile? @(subscribe [:mobile?]) diff --git a/src/cljs/orcpub/dnd/e5/db.cljs b/src/cljs/orcpub/dnd/e5/db.cljs index 1f361603b..a3613ecf7 100644 --- a/src/cljs/orcpub/dnd/e5/db.cljs +++ b/src/cljs/orcpub/dnd/e5/db.cljs @@ -49,9 +49,8 @@ (defn parse-route [] (let [route (if js/window.location (bidi/match-route route-map/routes js/window.location.pathname))] - (if route - route - default-route))) + (or route + default-route))) (def default-character (char5e/set-class t5e/character :barbarian 0 (class5e/barbarian-option nil nil nil nil nil))) diff --git a/src/cljs/orcpub/dnd/e5/equipment_subs.cljs b/src/cljs/orcpub/dnd/e5/equipment_subs.cljs index dac80f98c..32e6deb75 100644 --- a/src/cljs/orcpub/dnd/e5/equipment_subs.cljs +++ b/src/cljs/orcpub/dnd/e5/equipment_subs.cljs @@ -41,7 +41,7 @@ {:headers (auth-headers @app-db)}))] (dispatch [:set-loading false]) (case (:status response) - 200 (dispatch [::mi5e/set-custom-items (-> response :body)]) + 200 (dispatch [::mi5e/set-custom-items (:body response)]) 401 nil ;;(dispatch [:route routes/login-page-route {:secure? true}]) 500 (dispatch (events/show-generic-error))))) (ra/make-reaction @@ -251,7 +251,7 @@ {:headers (auth-headers @app-db)}))] (dispatch [:set-loading false]) (case (:status response) - 200 (dispatch [::mi5e/add-remote-item (-> response :body)]) + 200 (dispatch [::mi5e/add-remote-item (:body response)]) 500 (dispatch (events/show-generic-error))))) (ra/make-reaction (fn [] (get-in @app-db [::mi5e/remote-items id] {}))))) diff --git a/src/cljs/orcpub/dnd/e5/events.cljs b/src/cljs/orcpub/dnd/e5/events.cljs index 6a0b65156..c0b83a856 100644 --- a/src/cljs/orcpub/dnd/e5/events.cljs +++ b/src/cljs/orcpub/dnd/e5/events.cljs @@ -2075,7 +2075,7 @@ (reg-event-fx ::char5e/add-level (fn [{:keys [db]} [_ id]] - (update-character-fx db id #(add-level %)))) + (update-character-fx db id add-level))) (reg-event-fx ::char5e/level-up diff --git a/src/cljs/orcpub/dnd/e5/spell_subs.cljs b/src/cljs/orcpub/dnd/e5/spell_subs.cljs index 492ac5be7..2014fe6a0 100644 --- a/src/cljs/orcpub/dnd/e5/spell_subs.cljs +++ b/src/cljs/orcpub/dnd/e5/spell_subs.cljs @@ -67,19 +67,19 @@ (map (fn [background] (assoc background :edit-event [::bg5e/edit-background background])) - (apply concat (map (comp vals ::e5/backgrounds) plugins))))) + (mapcat (comp vals ::e5/backgrounds) plugins)))) (reg-sub ::langs5e/plugin-languages :<- [::e5/plugin-vals] (fn [plugins _] - (apply concat (map (comp vals ::e5/languages) plugins)))) + (mapcat (comp vals ::e5/languages) plugins))) (reg-sub ::selections5e/plugin-selections :<- [::e5/plugin-vals] (fn [plugins _] - (apply concat (map (comp vals ::e5/selections) plugins)))) + (mapcat (comp vals ::e5/selections) plugins))) (reg-sub ::selections5e/selection-map @@ -111,7 +111,7 @@ (:key race)) (spell-modifiers race (:name race))) :edit-event [::races5e/edit-race race])) - (apply concat (map (comp vals ::e5/races) plugins))))) + (mapcat (comp vals ::e5/races) plugins)))) (reg-sub ::races5e/plugin-subraces @@ -124,7 +124,7 @@ (:key subrace)) (spell-modifiers subrace (:name subrace))) :edit-event [::races5e/edit-subrace subrace])) - (apply concat (map (comp vals ::e5/subraces) plugins))))) + (mapcat (comp vals ::e5/subraces) plugins)))) (defn level-modifier [class-key {:keys [type value]}] (case type @@ -298,7 +298,7 @@ level-specs)) (defn to-class-level [spell-level] - (- (* 2 spell-level) 1)) + (dec (* 2 spell-level))) (defn level-selection [class-key selection-map {:keys [type num]}] (let [{:keys [name options]} (selection-map type)] @@ -405,7 +405,7 @@ (:key subclass)) :levels levels :edit-event [::classes5e/edit-subclass subclass]))) - (apply concat (map (comp vals ::e5/subclasses) plugins))))) + (mapcat (comp vals ::e5/subclasses) plugins)))) (reg-sub ::classes5e/plugin-classes @@ -421,19 +421,19 @@ :modifiers (opt5e/plugin-modifiers (:props class) (:key class)) :levels levels))) - (apply concat (map (comp vals ::e5/classes) plugins))))) + (mapcat (comp vals ::e5/classes) plugins)))) (reg-sub ::feats5e/plugin-feats :<- [::e5/plugin-vals] (fn [plugins _] - (apply concat (map (comp vals ::e5/feats) plugins)))) + (mapcat (comp vals ::e5/feats) plugins))) (reg-sub ::classes5e/plugin-invocations :<- [::e5/plugin-vals] (fn [plugins _] - (apply concat (map (comp vals ::e5/invocations) plugins)))) + (mapcat (comp vals ::e5/invocations) plugins))) (reg-sub ::classes5e/plugin-boons @@ -958,7 +958,7 @@ (map (fn [spell] (assoc spell :edit-event [::spells5e/edit-spell spell])) - (apply concat (map (comp vals ::e5/spells) plugins))))) + (mapcat (comp vals ::e5/spells) plugins)))) (reg-sub ::spells5e/plugin-spells-map @@ -970,13 +970,13 @@ ::monsters5e/plugin-monsters :<- [::e5/plugin-vals] (fn [plugins _] - (apply concat (map (comp vals ::e5/monsters) plugins)))) + (mapcat (comp vals ::e5/monsters) plugins))) (reg-sub ::encounters5e/plugin-encounters :<- [::e5/plugin-vals] (fn [plugins _] - (apply concat (map (comp vals ::e5/encounters) plugins)))) + (mapcat (comp vals ::e5/encounters) plugins))) (defn true-types [m] (sequence @@ -1083,13 +1083,13 @@ :<- [::char5e/monster-text-filter] :<- [::char5e/monster-filters] (fn [[sorted-monsters filter-text monster-filters]] - (filter-monsters sorted-monsters (if filter-text filter-text "") monster-filters))) + (filter-monsters sorted-monsters (or filter-text "") monster-filters))) (reg-sub ::monsters5e/filtered-monster-names :<- [::monsters5e/filtered-monsters] (fn [filtered-monsters] - (into #{} (map :name filtered-monsters)))) + (set (map :name filtered-monsters)))) (reg-sub ::spells5e/base-spells diff --git a/src/cljs/orcpub/dnd/e5/subs.cljs b/src/cljs/orcpub/dnd/e5/subs.cljs index 963a364bb..f52471afa 100644 --- a/src/cljs/orcpub/dnd/e5/subs.cljs +++ b/src/cljs/orcpub/dnd/e5/subs.cljs @@ -333,7 +333,7 @@ {:headers (auth-headers @app-db)}))] (dispatch [:set-loading false]) (case (:status response) - 200 (dispatch [::char5e/set-characters (-> response :body)]) + 200 (dispatch [::char5e/set-characters (:body response)]) 401 (if (not login-optional?) (dispatch [:route-to-login])) 500 (dispatch (events/show-generic-error))))) @@ -348,7 +348,7 @@ {:headers (auth-headers @app-db)}))] (dispatch [:set-loading false]) (case (:status response) - 200 (dispatch [::party5e/set-parties (-> response :body)]) + 200 (dispatch [::party5e/set-parties (:body response)]) 401 (if (not login-optional?) (dispatch [:route-to-login])) 500 (dispatch (events/show-generic-error))))) @@ -374,7 +374,7 @@ :following-users :<- [:user] (fn [user _] - (into #{} (:following user)))) + (set (:following user)))) (reg-sub ::char5e/character-map @@ -415,7 +415,7 @@ (case (:status response) 200 (dispatch [::char5e/set-character int-id - (char5e/from-strict (-> response :body))]) + (char5e/from-strict (:body response))]) 401 (dispatch [:route-to-login]) 500 (dispatch (events/show-generic-error)))))) (ra/make-reaction @@ -808,17 +808,17 @@ (reg-sub ::char5e/monster-types (fn [_ _] - (into #{} (map :type monsters5e/monsters)))) + (set (map :type monsters5e/monsters)))) (reg-sub ::char5e/monster-subtypes (fn [_ _] - (into #{} (mapcat :subtypes monsters5e/monsters)))) + (set (mapcat :subtypes monsters5e/monsters)))) (reg-sub ::char5e/monster-sizes (fn [_ _] - (into #{} (map :size monsters5e/monsters)))) + (set (map :size monsters5e/monsters)))) (reg-sub ::char5e/spell-text-filter diff --git a/src/cljs/orcpub/dnd/e5/views.cljs b/src/cljs/orcpub/dnd/e5/views.cljs index 8e3f33942..661b3823b 100644 --- a/src/cljs/orcpub/dnd/e5/views.cljs +++ b/src/cljs/orcpub/dnd/e5/views.cljs @@ -1384,7 +1384,7 @@ (defn content-page [title button-cfgs content & {:keys [hide-header-message? frame?]}] (let [on-scroll (fn [e] - (when (not @(subscribe [:orcacle-open?])) + (when-not @(subscribe [:orcacle-open?]) (let [app-header (js/document.getElementById "app-header") header-height (.-offsetHeight app-header) scroll-top (.-scrollTop (.-documentElement (.-target e))) @@ -1394,10 +1394,10 @@ (set! (.-display (.-style sticky-header)) "none")))))] (r/create-class {:component-did-mount (fn [comp] - (when (not frame?) + (when-not frame? (js/window.addEventListener "scroll" on-scroll))) :component-will-unmount (fn [comp] - (when (not frame?) + (when-not frame? (js/window.removeEventListener "scroll" on-scroll))) :reagent-render (fn [title button-cfgs content & {:keys [hide-header-message? frame?]}] @@ -1407,15 +1407,15 @@ mobile? @(subscribe [:mobile?])] [:div.app.min-h-full {:class-name theme - :on-scroll (if (not frame?) + :on-scroll (when-not frame? (fn [e]))} - (when (not frame?) + (when-not frame? [download-form]) (when @(subscribe [:loading]) [:div {:style loading-style} [:div.flex.justify-cont-s-a.align-items-c.h-100-p [:img.h-200.w-200.m-t-200 {:src "/image/spiral.gif"}]]]) - (when (not frame?) + (when-not frame? [app-header]) (when orcacle-open? [orcacle]) @@ -1777,7 +1777,7 @@ (let [mobile? @(subscribe [:mobile?]) button [:button.roll-button {:on-click (button-roll-handler message roll)} - (if text text "Roll")]] + (or text "Roll")]] (if (or mobile? disable-tooltip) button [:div.tooltip @@ -3170,7 +3170,7 @@ (traits-by-type :other)) attacks @(subscribe [::char/attacks id]) all-traits (concat actions bonus-actions reactions traits attacks) - freqs (into #{} (map has-frequency-units? all-traits))] + freqs (set (map has-frequency-units? all-traits))] [:div.details-columns {:class-name (if (= 2 num-columns) "flex")} @@ -3307,11 +3307,10 @@ (let [device-type @(subscribe [:device-type]) selected-tab @(subscribe [::char/selected-display-tab]) two-columns? (= 2 num-columns) - tab (if selected-tab - selected-tab - (if two-columns? - "combat" - "summary"))] + tab (or selected-tab + (if two-columns? + "combat" + "summary"))] [:div.w-100-p [:div (if show-summary? @@ -5318,7 +5317,7 @@ [:div.m-b-30 [:div.f-s-24.f-w-b.m-b-10 "Ability Increase Levels"] [:div.flex.flex-wrap - (let [asi-levels-set (into #{} (:ability-increase-levels class))] + (let [asi-levels-set (set (:ability-increase-levels class))] (doall (map (fn [level] diff --git a/web/cljs/orcpub/core.cljs b/web/cljs/orcpub/core.cljs index 04e4f2081..5b42a792e 100644 --- a/web/cljs/orcpub/core.cljs +++ b/web/cljs/orcpub/core.cljs @@ -86,7 +86,7 @@ (defonce history (doto (make-history) (goog.events/listen EventType.NAVIGATE - #(handle-url-change %)) + handle-url-change) (.setEnabled true))) (defn query-map [query-str] From bd0c685a01a0cd0da3f2725c5d0ec495817ca933 Mon Sep 17 00:00:00 2001 From: Pireax Date: Fri, 17 Jul 2020 21:34:41 +0200 Subject: [PATCH 6/9] Fix update function --- .clj-kondo/config.edn | 3 ++- src/clj/orcpub/routes.clj | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.clj-kondo/config.edn b/.clj-kondo/config.edn index af974ea9a..4e901577e 100644 --- a/.clj-kondo/config.edn +++ b/.clj-kondo/config.edn @@ -26,6 +26,7 @@ (orcpub.dnd.e5.modifiers/bonus-action) (orcpub.dnd.e5.modifiers/reaction) (orcpub.dnd.e5.modifiers/level-val) - (orcpub.entity-spec/make-entity)]}} + (orcpub.entity-spec/make-entity) + (orcpub.routes-test/with-conn)]}} :lint-as {reagent.core/with-let clojure.core/let hiccup.def/defhtml clojure.core/defn}} diff --git a/src/clj/orcpub/routes.clj b/src/clj/orcpub/routes.clj index a166ad730..b523696bd 100644 --- a/src/clj/orcpub/routes.clj +++ b/src/clj/orcpub/routes.clj @@ -664,7 +664,8 @@ new-ids (entity/db-ids new-character) retract-ids (sets/difference current-ids new-ids) retractions (map - :db/retractEntity + (fn [retract-id] + [:db/retractEntity retract-id]) retract-ids) tx (conj retractions (-> new-character @@ -710,6 +711,7 @@ (catch Exception e (prn "ERROR" e) (throw e))))) (defn save-character [{:keys [db transit-params body conn identity] :as request}] + (println transit-params) (do-save-character db conn transit-params identity)) (defn owns-item [db username item-id] From 580de49c7fb3e002267a1e65119add7c9ccf6bec Mon Sep 17 00:00:00 2001 From: Pireax Date: Sat, 18 Jul 2020 19:37:18 +0200 Subject: [PATCH 7/9] Remove temporary print statement --- src/clj/orcpub/routes.clj | 1 - 1 file changed, 1 deletion(-) diff --git a/src/clj/orcpub/routes.clj b/src/clj/orcpub/routes.clj index b523696bd..ee6bf2640 100644 --- a/src/clj/orcpub/routes.clj +++ b/src/clj/orcpub/routes.clj @@ -711,7 +711,6 @@ (catch Exception e (prn "ERROR" e) (throw e))))) (defn save-character [{:keys [db transit-params body conn identity] :as request}] - (println transit-params) (do-save-character db conn transit-params identity)) (defn owns-item [db username item-id] From e97a300a9739160b9af62c9b5e96a27c08e2cc08 Mon Sep 17 00:00:00 2001 From: Pireax Date: Sun, 19 Jul 2020 01:34:45 +0200 Subject: [PATCH 8/9] Add tests to prevent bug from recurring --- src/clj/orcpub/routes.clj | 30 ++++++---- test/clj/orcpub/routes_test.clj | 98 ++++++++++++++++++++++++++------- 2 files changed, 95 insertions(+), 33 deletions(-) diff --git a/src/clj/orcpub/routes.clj b/src/clj/orcpub/routes.clj index ee6bf2640..09f694c1a 100644 --- a/src/clj/orcpub/routes.clj +++ b/src/clj/orcpub/routes.clj @@ -20,6 +20,7 @@ [clj-time.coerce :as tc :refer [from-date]] [clojure.string :as s] [clojure.spec.alpha :as spec] + [clojure.pprint] [orcpub.dnd.e5.skills :as skill5e] [orcpub.dnd.e5.character :as char5e] [orcpub.dnd.e5.spells :as spells] @@ -648,7 +649,8 @@ (prn "INVALID CHARACTER FOUND, REPLACING" #_current-character) (prn "INVALID CHARACTER EXPLANATION" #_(spec/explain-data ::se/entity current-character))) (if (seq problems) - {:status 400 :body problems} + (throw (ex-info "Character has problems" + {:error :character-problems :problems problems})) (if-not current-valid? (let [new-character (entity/remove-ids character) tx [[:db/retractEntity (:db/id current-character)] @@ -657,8 +659,7 @@ :orcpub.entity.strict/owner username) add-dnd-5e-character-tags)] result @(d/transact conn tx)] - {:status 200 - :body (d/pull (d/db conn) '[*] (-> result :tempids (get "tempid")))}) + (d/pull (d/db conn) '[*] (-> result :tempids (get "tempid")))) (let [new-character (entity/remove-orphan-ids character) current-ids (entity/db-ids current-character) new-ids (entity/db-ids new-character) @@ -672,9 +673,9 @@ (assoc :orcpub.entity.strict/owner username) add-dnd-5e-character-tags))] @(d/transact conn tx) - {:status 200 - :body (d/pull (d/db conn) '[*] id)})))) - {:status 401 :body "You do not own this character"}))) + (d/pull (d/db conn) '[*] id))))) + (throw (ex-info "Not user character" + {:error :not-user-character}))))) (defn create-new-character [conn character username] (let [result @(d/transact conn @@ -683,8 +684,7 @@ ::se/owner username) add-dnd-5e-character-tags)]) new-id (get-new-id "tempid" result)] - {:status 200 - :body (d/pull (d/db conn) '[*] new-id)})) + (d/pull (d/db conn) '[*] new-id))) (defn clean-up-character [character] (if (-> character ::se/values ::char5e/xps string?) @@ -704,10 +704,16 @@ (try (if-let [data (spec/explain-data ::se/entity character)] {:status 400 :body data} - (let [clean-character (clean-up-character character)] - (if (:db/id clean-character) - (update-character db conn clean-character username) - (create-new-character conn clean-character username)))) + (let [clean-character (clean-up-character character) + updated-character (if (:db/id clean-character) + (update-character db conn clean-character username) + (create-new-character conn clean-character username))] + {:status 200 :body updated-character})) + (catch clojure.lang.ExceptionInfo e + (let [data (ex-data e)] + (case (:error data) + :character-problems {:status 400 :body (:problems data)} + :not-user-character {:status 401 :body "You do not own this character"}))) (catch Exception e (prn "ERROR" e) (throw e))))) (defn save-character [{:keys [db transit-params body conn identity] :as request}] diff --git a/test/clj/orcpub/routes_test.clj b/test/clj/orcpub/routes_test.clj index 18de183a9..a49771782 100644 --- a/test/clj/orcpub/routes_test.clj +++ b/test/clj/orcpub/routes_test.clj @@ -1,17 +1,18 @@ (ns orcpub.routes-test - (:require [orcpub.routes :as routes] - [orcpub.dnd.e5.magic-items :as mi] - [orcpub.dnd.e5.character :as char] - [orcpub.modifiers :as mod] - [orcpub.entity :as entity] - [clojure.test :refer [deftest is testing]] - [orcpub.errors :as errors] - [io.pedestal.http :as http] - [io.pedestal.test :refer [response-for]] - [orcpub.db.schema :as schema] - [datomic.api :as d] - [datomock.core :as dm] - [clojure.set :refer [intersection]]) + (:require + [clojure.test :refer [deftest is testing]] + [clojure.set :refer [intersection]] + [datomic.api :as d] + [datomock.core :as dm] + [io.pedestal.http :as http] + [orcpub.routes :as routes] + [orcpub.dnd.e5.magic-items :as mi] + [orcpub.dnd.e5.character :as char5e] + [orcpub.modifiers :as mod] + [orcpub.entity :as entity] + [orcpub.entity.strict :as se] + [orcpub.errors :as errors] + [orcpub.db.schema :as schema]) (:import [java.util UUID])) #_(def service @@ -27,11 +28,66 @@ (defmacro with-conn [conn-binding & body] `(let [uri# (str "datomic:mem:orcpub-test-" (UUID/randomUUID)) - ~conn-binding (do (d/create-database uri#) - (d/connect uri#))] + ~conn-binding (do + (d/create-database uri#) + (d/connect uri#))] (try ~@body (finally (d/delete-database uri#))))) +(defn test-character [] + {::se/selections + [{::se/key :ability-scores + ::se/option + {::se/key :standard-scores + ::se/map-value + {::char5e/str 15 + ::char5e/dex 14 + ::char5e/con 13 + ::char5e/int 12 + ::char5e/wis 10 + ::char5e/cha 8}}} + {::se/key :class + ::se/options + [{::se/key :barbarian + ::se/selections + [{::se/key :levels + ::se/options [{::se/key :level-1}]}]}]} + {::se/key :weapons + ::se/options + [{::se/key :javelin + ::se/map-value {:orcpub.dnd.e5.character.equipment/quantity 4 + :orcpub.dnd.e5.character.equipment/equipped? true + :orcpub.dnd.e5.character.equipment/class-starting-equipment? true}}]}] + ::se/summary + {::char5e/character-name "Charry" + ::char5e/classes + [{::char5e/class-name "Barbarian" + ::char5e/level 1}]}}) + +(deftest test-do-save-character + (with-conn conn + (let [mocked-conn (dm/fork-conn conn)] + @(d/transact mocked-conn schema/all-schemas) + @(d/transact mocked-conn [{:orcpub.user/username "testy" + :orcpub.user/email "test@test.com"} + {:orcpub.user/username "testy-2" + :orcpub.user/email "test-2@test.com"}]) + (testing "Save new character" + (let [character (test-character) + saved-character (:body (routes/do-save-character (d/db mocked-conn) mocked-conn character {:user "testy"}))] + (is (= "testy" (::se/owner saved-character))))) + (testing "Update character" + (let [character (test-character) + saved-character (:body (routes/do-save-character (d/db mocked-conn) mocked-conn character {:user "testy"})) + updated-character (:body (routes/do-save-character + (d/db mocked-conn) + mocked-conn + (assoc-in saved-character [::se/summary ::char5e/character-name] "Charry-2") + {:user "testy"}))] + (is (= "testy" (::se/owner updated-character))) + (is (= "Charry" (-> saved-character ::se/summary ::char5e/character-name))) + (is (= "Charry-2" (-> updated-character ::se/summary ::char5e/character-name)))))))) + (deftest test-save-entity (with-conn conn (let [mocked-conn (dm/fork-conn conn)] @@ -47,11 +103,11 @@ (is (= "testy" (::mi/owner saved-entity))) (is (int? (:db/id saved-entity))) (is (= "Cool Item" (::mi/name saved-entity))))) - + (testing "Create and update entity" (let [entity {::mi/modifiers [{::mod/key :saving-throw-bonus - ::mod/args [{::mod/keyword-arg ::char/str} - {::mod/int-arg 1}]}]} + ::mod/args [{::mod/keyword-arg ::char5e/str} + {::mod/int-arg 1}]}]} saved-entity (routes/save-entity mocked-conn "testy" entity ::mi/owner)] (is (= "testy" (::mi/owner saved-entity))) (is (int? (:db/id saved-entity))) @@ -60,7 +116,7 @@ (testing "Update other user's entity" (let [entity {::mi/modifiers [{::mod/key :saving-throw-bonus - ::mod/args [{::mod/keyword-arg ::char/str} + ::mod/args [{::mod/keyword-arg ::char5e/str} {::mod/int-arg 1}]}]} saved-entity (routes/save-entity mocked-conn "testy" entity ::mi/owner) saved-entity-2 (routes/save-entity mocked-conn "testy-2" entity ::mi/owner)] @@ -69,7 +125,7 @@ (testing "Removal of orphans" (let [entity {::mi/modifiers [{::mod/key :saving-throw-bonus - ::mod/args [{::mod/keyword-arg ::char/str} + ::mod/args [{::mod/keyword-arg ::char5e/str} {::mod/int-arg 1}]}]} saved-entity (routes/save-entity mocked-conn "testy" entity ::mi/owner) root-id (:db/id saved-entity) @@ -82,7 +138,7 @@ (testing "Removal of non-children ids" (let [entity {::mi/modifiers [{::mod/key :saving-throw-bonus - ::mod/args [{::mod/keyword-arg ::char/str} + ::mod/args [{::mod/keyword-arg ::char5e/str} {::mod/int-arg 1}]}]} saved-entity (routes/save-entity mocked-conn "testy" entity ::mi/owner) root-id (:db/id saved-entity) From 4e7ad67df5ebf77f6afc049cefc4f79475bebf6e Mon Sep 17 00:00:00 2001 From: DatDamnZotz Date: Thu, 17 Sep 2020 08:52:35 -0600 Subject: [PATCH 9/9] Add :prep-tasks [["garden" "once"]] since it doesn't create the css otherwise --- project.clj | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/project.clj b/project.clj index 682bf49dd..ffade8bd5 100644 --- a/project.clj +++ b/project.clj @@ -62,8 +62,7 @@ [vvvvalvalval/datomock "0.2.0"] [com.datomic/datomic-free "0.9.5697"] [funcool/cuerdas "2.2.0"] - [camel-snake-kebab "0.4.0"] - ] + [camel-snake-kebab "0.4.0"]] :plugins [[lein-figwheel "0.5.19"] [lein-cljsbuild "1.1.7" :exclusions [[org.clojure/clojure]]] @@ -83,22 +82,23 @@ :uberjar-name "orcpub.jar" - :garden {:builds [{ ;; Optional name of the build: + :garden {:builds [{;; Optional name of the build: :id "screen" ;; Source paths where the stylesheet source code is :source-paths ["src/clj" "src/cljc"] ;; The var containing your stylesheet: :stylesheet orcpub.styles.core/app ;; Compiler flags passed to `garden.core/css`: - :compiler { ;; Where to save the file: + :compiler {;; Where to save the file: :output-to "resources/public/css/compiled/styles.css" ;; Compress the output? :pretty-print? false}}]} + :prep-tasks [["garden" "once"]] + :cljsbuild {:builds {:dev - { - :source-paths ["web/cljs" "src/cljc" "src/cljs"] + {:source-paths ["web/cljs" "src/cljc" "src/cljs"] ;; the presence of a :figwheel configuration here ;; will cause figwheel to inject the figwheel client @@ -114,10 +114,9 @@ :asset-path "/js/compiled/out" :output-to "resources/public/js/compiled/orcpub.js" :output-dir "resources/public/js/compiled/out" - :source-map-timestamp true}}} - } + :source-map-timestamp true}}}} - :figwheel { ;; :http-server-root "public" ;; default and assumes "resources" + :figwheel {;; :http-server-root "public" ;; default and assumes "resources" ;; :server-port 3449 ;; default ;; :server-ip "127.0.0.1" @@ -153,12 +152,11 @@ ;; :server-logfile "tmp/logs/figwheel-logfile.log" } - :repl-options { - ;; If nREPL takes too long to load it may timeout, + :repl-options {;; If nREPL takes too long to load it may timeout, ;; increase this to wait longer before timing out. ;; Defaults to 30000 (30 seconds) - :timeout 300000 ; 5 mins to wait - } + :timeout 300000 ; 5 mins to wait + } ;; setting up nREPL for Figwheel and ClojureScript dev ;; Please see: @@ -220,8 +218,7 @@ :omit-source true :cljsbuild {:builds {:prod - { - :source-paths ["web/cljs" "src/cljc" "src/cljs"] + {:source-paths ["web/cljs" "src/cljc" "src/cljs"] :compiler {:main orcpub.core :asset-path "/js/compiled/out" :output-to "resources/public/js/compiled/orcpub.js"