0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-04-15 16:31:25 -05:00

Fix linter issues on backend util namespace directory.

This commit is contained in:
Andrey Antukh 2020-12-02 11:19:27 +01:00 committed by Hirunatan
parent 74077a0ead
commit ce3c055819
14 changed files with 75 additions and 83 deletions

View file

@ -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))

View file

@ -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)]

View file

@ -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]))

View file

@ -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 <niwi@niwi.nz>
;; 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)

View file

@ -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 <niwi@niwi.nz>
;; 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})))

View file

@ -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 <niwi@niwi.nz>
;; 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)]

View file

@ -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 <niwi@niwi.nz>
;; 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]

View file

@ -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

View file

@ -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 <niwi@niwi.nz>
;; 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!

View file

@ -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 <niwi@niwi.nz>
;; 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))))

View file

@ -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 <niwi@niwi.nz>
;; 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!)

View file

@ -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 <niwi@niwi.nz>
;; 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

View file

@ -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

View file

@ -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"))