From ce3c055819da53bf03de8f22a36bac7cf67198db Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 2 Dec 2020 11:19:27 +0100 Subject: [PATCH] :sparkles: Fix linter issues on backend util namespace directory. --- backend/src/app/util/async.clj | 5 ++--- backend/src/app/util/data.clj | 2 +- backend/src/app/util/dispatcher.clj | 11 ++++------- backend/src/app/util/emails.clj | 21 +++++++++------------ backend/src/app/util/http.clj | 10 ++++++---- backend/src/app/util/migrations.clj | 9 ++++++--- backend/src/app/util/redis.clj | 14 ++++++++------ backend/src/app/util/sql.clj | 2 +- backend/src/app/util/storage.clj | 13 +++++-------- backend/src/app/util/svg.clj | 22 ++++++++++++---------- backend/src/app/util/template.clj | 13 ++++++------- backend/src/app/util/time.clj | 6 +++--- backend/src/app/util/transit.clj | 10 ++++------ backend/src/app/worker.clj | 20 ++++++++------------ 14 files changed, 75 insertions(+), 83 deletions(-) diff --git a/backend/src/app/util/async.clj b/backend/src/app/util/async.clj index f455f03ca..afb221b59 100644 --- a/backend/src/app/util/async.clj +++ b/backend/src/app/util/async.clj @@ -6,9 +6,8 @@ (ns app.util.async (:require - [clojure.spec.alpha :as s] - [clojure.tools.logging :as log] - [clojure.core.async :as a]) + [clojure.core.async :as a] + [clojure.spec.alpha :as s]) (:import java.util.concurrent.Executor)) diff --git a/backend/src/app/util/data.clj b/backend/src/app/util/data.clj index d5e12cd8b..32bd107ee 100644 --- a/backend/src/app/util/data.clj +++ b/backend/src/app/util/data.clj @@ -12,7 +12,7 @@ ;; TODO: move to app.common.helpers (defn dissoc-in - [m [k & ks :as keys]] + [m [k & ks]] (if ks (if-let [nextmap (get m k)] (let [newmap (dissoc-in nextmap ks)] diff --git a/backend/src/app/util/dispatcher.clj b/backend/src/app/util/dispatcher.clj index 8aad12455..e86ae408c 100644 --- a/backend/src/app/util/dispatcher.clj +++ b/backend/src/app/util/dispatcher.clj @@ -8,14 +8,11 @@ "A generic service dispatcher implementation." (:refer-clojure :exclude [defmethod]) (:require - [clojure.spec.alpha :as s] - [expound.alpha :as expound] - [app.common.exceptions :as ex]) + [app.common.exceptions :as ex] + [clojure.spec.alpha :as s]) (:import - clojure.lang.IDeref - clojure.lang.MapEntry - java.util.Map - java.util.HashMap)) + java.util.HashMap + java.util.Map)) (definterface IDispatcher (^void add [key f])) diff --git a/backend/src/app/util/emails.clj b/backend/src/app/util/emails.clj index 2558c5207..f1371f594 100644 --- a/backend/src/app/util/emails.clj +++ b/backend/src/app/util/emails.clj @@ -5,27 +5,25 @@ ;; This Source Code Form is "Incompatible With Secondary Licenses", as ;; defined by the Mozilla Public License, v. 2.0. ;; -;; Copyright (c) 2019-2020 Andrey Antukh +;; Copyright (c) 2020 UXBOX Labs SL (ns app.util.emails (:require + [app.common.exceptions :as ex] + [app.common.spec :as us] + [app.util.template :as tmpl] [clojure.java.io :as io] [clojure.spec.alpha :as s] - [cuerdas.core :as str] - [app.common.spec :as us] - [app.common.exceptions :as ex] - [app.util.template :as tmpl]) + [cuerdas.core :as str]) (:import java.util.Properties - javax.mail.Message - javax.mail.Transport javax.mail.Message$RecipientType - javax.mail.PasswordAuthentication javax.mail.Session + javax.mail.Transport javax.mail.internet.InternetAddress - javax.mail.internet.MimeMultipart javax.mail.internet.MimeBodyPart - javax.mail.internet.MimeMessage)) + javax.mail.internet.MimeMessage + javax.mail.internet.MimeMultipart)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Email Building @@ -205,8 +203,7 @@ (defn- build-email-template [id context] - (let [lang (:lang context :en) - subj (render-email-template-part :subj id context) + (let [subj (render-email-template-part :subj id context) text (render-email-template-part :txt id context) html (render-email-template-part :html id context)] (when (or (not subj) diff --git a/backend/src/app/util/http.clj b/backend/src/app/util/http.clj index e2f46493b..fa8d5be28 100644 --- a/backend/src/app/util/http.clj +++ b/backend/src/app/util/http.clj @@ -2,14 +2,16 @@ ;; License, v. 2.0. If a copy of the MPL was not distributed with this ;; file, You can obtain one at http://mozilla.org/MPL/2.0/. ;; -;; Copyright (c) 2019 Andrey Antukh +;; This Source Code Form is "Incompatible With Secondary Licenses", as +;; defined by the Mozilla Public License, v. 2.0. +;; +;; Copyright (c) 2020 UXBOX Labs SL (ns app.util.http "Http client abstraction layer." (:require - [promesa.core :as p] - [promesa.exec :as px] - [java-http-clj.core :as http])) + [java-http-clj.core :as http] + [promesa.exec :as px])) (def default-client (delay (http/build-client {:executor @px/default-executor}))) diff --git a/backend/src/app/util/migrations.clj b/backend/src/app/util/migrations.clj index 479ffb7a2..9829082bc 100644 --- a/backend/src/app/util/migrations.clj +++ b/backend/src/app/util/migrations.clj @@ -2,13 +2,16 @@ ;; License, v. 2.0. If a copy of the MPL was not distributed with this ;; file, You can obtain one at http://mozilla.org/MPL/2.0/. ;; -;; Copyright (c) 2019 Andrey Antukh +;; This Source Code Form is "Incompatible With Secondary Licenses", as +;; defined by the Mozilla Public License, v. 2.0. +;; +;; Copyright (c) 2020 UXBOX Labs SL (ns app.util.migrations (:require - [clojure.tools.logging :as log] [clojure.java.io :as io] [clojure.spec.alpha :as s] + [clojure.tools.logging :as log] [cuerdas.core :as str] [next.jdbc :as jdbc])) @@ -45,7 +48,7 @@ ((:fn migration) pool)))) (defn- impl-migrate - [conn migrations {:keys [fake] :or {fake false}}] + [conn migrations _opts] (s/assert ::migrations migrations) (let [mname (:name migrations) steps (:steps migrations)] diff --git a/backend/src/app/util/redis.clj b/backend/src/app/util/redis.clj index 1c6991132..0be8b5b46 100644 --- a/backend/src/app/util/redis.clj +++ b/backend/src/app/util/redis.clj @@ -2,14 +2,17 @@ ;; License, v. 2.0. If a copy of the MPL was not distributed with this ;; file, You can obtain one at http://mozilla.org/MPL/2.0/. ;; -;; Copyright (c) 2019 Andrey Antukh +;; This Source Code Form is "Incompatible With Secondary Licenses", as +;; defined by the Mozilla Public License, v. 2.0. +;; +;; Copyright (c) 2020 UXBOX Labs SL (ns app.util.redis "Asynchronous posgresql client." (:refer-clojure :exclude [run!]) (:require - [promesa.core :as p] - [clojure.core.async :as a]) + [clojure.core.async :as a] + [promesa.core :as p]) (:import io.lettuce.core.RedisClient io.lettuce.core.RedisURI @@ -18,7 +21,6 @@ io.lettuce.core.api.StatefulRedisConnection io.lettuce.core.pubsub.RedisPubSubListener io.lettuce.core.pubsub.StatefulRedisPubSubConnection - io.lettuce.core.pubsub.api.async.RedisPubSubAsyncCommands io.lettuce.core.pubsub.api.sync.RedisPubSubCommands )) @@ -87,7 +89,7 @@ output)) (defn subscribe - [{:keys [uri] :as client} {:keys [topic topics xform]}] + [{:keys [uri] :as client} {:keys [topics xform]}] (let [topics (if (vector? topics) (into-array String (map str topics)) (into-array String [(str topics)]))] @@ -100,7 +102,7 @@ true false)) -(defmulti impl-run (fn [conn cmd parmas] cmd)) +(defmulti impl-run (fn [_ cmd _] cmd)) (defn run! [conn cmd params] diff --git a/backend/src/app/util/sql.clj b/backend/src/app/util/sql.clj index f61e2963d..61274db15 100644 --- a/backend/src/app/util/sql.clj +++ b/backend/src/app/util/sql.clj @@ -164,7 +164,7 @@ (defn- process-param-tokens [sql] (let [cnt (java.util.concurrent.atomic.AtomicInteger. 1)] - (str/replace sql #"\?" (fn [& args] + (str/replace sql #"\?" (fn [& _args] (str "$" (.getAndIncrement cnt)))))) (def ^:private select-formatters diff --git a/backend/src/app/util/storage.clj b/backend/src/app/util/storage.clj index b4329df3c..e9b28d062 100644 --- a/backend/src/app/util/storage.clj +++ b/backend/src/app/util/storage.clj @@ -5,7 +5,7 @@ ;; This Source Code Form is "Incompatible With Secondary Licenses", as ;; defined by the Mozilla Public License, v. 2.0. ;; -;; Copyright (c) 2020 Andrey Antukh +;; Copyright (c) 2020 UXBOX Labs SL (ns app.util.storage "A local filesystem storage implementation." @@ -16,17 +16,14 @@ [clojure.java.io :as io] [clojure.spec.alpha :as s] [cuerdas.core :as str] - [datoteka.core :as fs] - [datoteka.proto :as fp]) + [datoteka.core :as fs]) (:import java.io.ByteArrayInputStream java.io.InputStream java.io.OutputStream java.net.URI - java.nio.file.Files java.nio.file.NoSuchFileException - java.nio.file.Path - java.security.MessageDigest)) + java.nio.file.Path)) (defn uri [v] @@ -54,7 +51,7 @@ (defn- transform-path [storage ^Path path] (if-let [xf (::xf storage)] - ((xf (fn [a b] b)) nil path) + ((xf (fn [_ b] b)) nil path) path)) (defn blob @@ -89,7 +86,7 @@ (normalize-path (::base-path storage)) (fs/delete)) true - (catch java.nio.file.NoSuchFileException e + (catch NoSuchFileException _e false))) (defn clear! diff --git a/backend/src/app/util/svg.clj b/backend/src/app/util/svg.clj index bb37d83b8..04d404a81 100644 --- a/backend/src/app/util/svg.clj +++ b/backend/src/app/util/svg.clj @@ -2,21 +2,23 @@ ;; License, v. 2.0. If a copy of the MPL was not distributed with this ;; file, You can obtain one at http://mozilla.org/MPL/2.0/. ;; -;; Copyright (c) 2016-2019 Andrey Antukh +;; This Source Code Form is "Incompatible With Secondary Licenses", as +;; defined by the Mozilla Public License, v. 2.0. +;; +;; Copyright (c) 2020 UXBOX Labs SL (ns app.util.svg "Icons SVG parsing helpers." (:require - [clojure.spec.alpha :as s] - [cuerdas.core :as str] + [app.common.exceptions :as ex] [app.common.spec :as us] - [app.common.exceptions :as ex]) + [clojure.spec.alpha :as s] + [cuerdas.core :as str]) (:import org.jsoup.Jsoup org.jsoup.nodes.Attribute org.jsoup.nodes.Element - org.jsoup.nodes.Document - java.io.InputStream)) + org.jsoup.nodes.Document)) (s/def ::content string?) (s/def ::width ::us/number) @@ -65,19 +67,19 @@ content (.html element) attrs (parse-attrs element)] (assoc attrs :content content)) - (catch java.lang.IllegalArgumentException e + (catch java.lang.IllegalArgumentException _e (ex/raise :type :validation :code ::invalid-input :message "Input does not seems to be a valid svg.")) - (catch java.lang.NullPointerException e + (catch java.lang.NullPointerException _e (ex/raise :type :validation :code ::invalid-input :message "Input does not seems to be a valid svg.")) - (catch org.jsoup.UncheckedIOException e + (catch org.jsoup.UncheckedIOException _e (ex/raise :type :validation :code ::invalid-input :message "Input does not seems to be a valid svg.")) - (catch Exception e + (catch Exception _e (ex/raise :type :internal :code ::unexpected)))) diff --git a/backend/src/app/util/template.clj b/backend/src/app/util/template.clj index 0148c9894..f2dc3facd 100644 --- a/backend/src/app/util/template.clj +++ b/backend/src/app/util/template.clj @@ -2,18 +2,17 @@ ;; License, v. 2.0. If a copy of the MPL was not distributed with this ;; file, You can obtain one at http://mozilla.org/MPL/2.0/. ;; -;; Copyright (c) 2016-2019 Andrey Antukh +;; This Source Code Form is "Incompatible With Secondary Licenses", as +;; defined by the Mozilla Public License, v. 2.0. +;; +;; Copyright (c) 2020 UXBOX Labs SL (ns app.util.template "A lightweight abstraction over mustache.java template engine. The documentation can be found: http://mustache.github.io/mustache.5.html" (:require - [clojure.tools.logging :as log] - [clojure.walk :as walk] - [clojure.java.io :as io] - [cuerdas.core :as str] - [selmer.parser :as sp] - [app.common.exceptions :as ex])) + [app.common.exceptions :as ex] + [selmer.parser :as sp])) ;; (sp/cache-off!) diff --git a/backend/src/app/util/time.clj b/backend/src/app/util/time.clj index c855afd24..e8d62d877 100644 --- a/backend/src/app/util/time.clj +++ b/backend/src/app/util/time.clj @@ -5,12 +5,12 @@ ;; This Source Code Form is "Incompatible With Secondary Licenses", as ;; defined by the Mozilla Public License, v. 2.0. ;; -;; Copyright (c) 2016-2020 Andrey Antukh +;; Copyright (c) 2020 UXBOX Labs SL (ns app.util.time (:require - [clojure.spec.alpha :as s] [app.common.exceptions :as ex] + [clojure.spec.alpha :as s] [cognitect.transit :as t]) (:import java.time.Instant @@ -106,7 +106,7 @@ (string? v) (try (parse-duration v) - (catch java.time.format.DateTimeParseException e + (catch java.time.format.DateTimeParseException _e ::s/invalid)) :else diff --git a/backend/src/app/util/transit.clj b/backend/src/app/util/transit.clj index e188e9b04..59630313d 100644 --- a/backend/src/app/util/transit.clj +++ b/backend/src/app/util/transit.clj @@ -9,13 +9,11 @@ (ns app.util.transit (:require - [cognitect.transit :as t] - [clojure.java.io :as io] - [linked.core :as lk] - [app.util.time :as dt] - [app.util.data :as data] + [app.common.geom.matrix :as gmt] [app.common.geom.point :as gpt] - [app.common.geom.matrix :as gmt]) + [app.util.time :as dt] + [cognitect.transit :as t] + [linked.core :as lk]) (:import linked.set.LinkedSet java.io.ByteArrayInputStream diff --git a/backend/src/app/worker.clj b/backend/src/app/worker.clj index 4c0084f10..b3bd38016 100644 --- a/backend/src/app/worker.clj +++ b/backend/src/app/worker.clj @@ -15,12 +15,11 @@ [app.db :as db] [app.tasks.delete-object] [app.tasks.delete-profile] - [app.tasks.remove-media] [app.tasks.maintenance] + [app.tasks.remove-media] [app.tasks.sendmail] [app.tasks.trim-file] [app.util.async :as aa] - [app.util.blob :as blob] [app.util.time :as dt] [clojure.core.async :as a] [clojure.spec.alpha :as s] @@ -31,10 +30,7 @@ org.eclipse.jetty.util.thread.QueuedThreadPool java.util.concurrent.ExecutorService java.util.concurrent.Executors - java.util.concurrent.Executor - java.time.Duration - java.time.Instant - java.util.Date)) + java.time.Instant)) (declare start-scheduler-worker!) (declare start-worker!) @@ -149,7 +145,7 @@ nil)))) (defn- run-task - [{:keys [tasks conn]} item] + [{:keys [tasks]} item] (try (log/debugf "Started task '%s/%s/%s'." (:name item) (:id item) (:retry-num item)) (handle-task tasks item) @@ -187,7 +183,7 @@ for update skip locked") (defn- event-loop-fn* - [{:keys [tasks executor batch-size] :as opts}] + [{:keys [executor batch-size] :as opts}] (db/with-atomic [conn db/pool] (let [queue (:queue opts "default") items (->> (db/exec! conn [sql:select-next-tasks queue batch-size]) @@ -222,7 +218,7 @@ :opt-un [::poll-interval])) (defn start-worker! - [{:keys [poll-interval executor] + [{:keys [poll-interval] :or {poll-interval 5000} :as opts}] (us/assert ::start-worker-params opts) @@ -290,7 +286,7 @@ do update set cron_expr=?") (defn- synchronize-schedule-item - [conn {:keys [id cron] :as item}] + [conn {:keys [id cron]}] (let [cron (str cron)] (log/debugf "Initialize scheduled task '%s' (cron: '%s')." id cron) (db/exec-one! conn [sql:upsert-scheduled-task id cron cron]))) @@ -311,7 +307,7 @@ (.printStackTrace ^Throwable error (java.io.PrintWriter. *out*)))) (defn- execute-scheduled-task - [{:keys [scheduler executor] :as opts} {:keys [id cron] :as task}] + [{:keys [executor] :as opts} {:keys [id] :as task}] (letfn [(run-task [conn] (try (when (db/exec-one! conn [sql:lock-scheduled-task id]) @@ -384,7 +380,7 @@ (defn thread-pool ([] (thread-pool {})) - ([{:keys [min-threads max-threads idle-timeout name] + ([{:keys [min-threads max-threads name] :or {min-threads 0 max-threads 128 idle-timeout 60000}}] (let [executor (QueuedThreadPool. max-threads min-threads)] (.setName executor (or name "default-tp"))