Skip to content

Commit

Permalink
Fix a lot of linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
egli committed Oct 7, 2024
1 parent 2edcd3c commit bd7b278
Show file tree
Hide file tree
Showing 31 changed files with 165 additions and 179 deletions.
8 changes: 4 additions & 4 deletions src/clj/daisyproducer2/db/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(:require
[next.jdbc.date-time]
[next.jdbc.result-set]
[clojure.string :as string]
[clojure.string :as str]
[clojure.tools.logging :as log]
[conman.core :as conman]
[camel-snake-kebab.extras :refer [transform-keys]]
Expand All @@ -29,9 +29,9 @@
(let [prepend #(str %2 %1)
append #(str %1 %2)]
(cond-> s
(not (string/starts-with? s "^")) (prepend "%")
(not (string/ends-with? s "$")) (append "%")
true (string/replace #"[$^]" ""))))
(not (str/starts-with? s "^")) (prepend "%")
(not (str/ends-with? s "$")) (append "%")
true (str/replace #"[$^]" ""))))

(defn get-generated-key
"Extract the generated key from the return value of an insert statement.
Expand Down
20 changes: 10 additions & 10 deletions src/clj/daisyproducer2/documents/abacus.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
(:require [clojure.data.zip.xml :refer [text xml1->]]
[clojure.java.io :as io]
[clojure.spec.alpha :as s]
[clojure.string :as string]
[clojure.string :as str]
[clojure.tools.logging :as log]
[clojure.xml :as xml]
[clojure.zip :as zip]
Expand All @@ -25,7 +25,7 @@
[medley.core :as medley]))

(s/def ::product-number (s/and string? #(re-matches #"^(PS|GD|EB|ET)\d{4,7}$" %)))
(s/def ::isbn (s/and string? (fn [s] (or (string/blank? s) (re-matches #"^SBS[0-9]{6}|(?:978-|979-)?\d{1,5}-\d{1,7}-\d{1,6}-[0-9xX]" s)))))
(s/def ::isbn (s/and string? (fn [s] (or (str/blank? s) (re-matches #"^SBS[0-9]{6}|(?:978-|979-)?\d{1,5}-\d{1,7}-\d{1,6}-[0-9xX]" s)))))

(def ^:private root-path [:Task :Transaction :DocumentData])

Expand All @@ -50,29 +50,29 @@
(cond
(not= production-series-number "0") "PPP"
(and (= production-series-number "0")
(not (string/blank? reihe))
(string/includes? reihe "SJW")) "SJW"
(not (str/blank? reihe))
(str/includes? reihe "SJW")) "SJW"
:else ""))

(defn- production-series-number
[{:keys [production-series-number reihe]}]
(cond
(not= production-series-number "0") production-series-number
(and (= production-series-number "0")
(not (string/blank? reihe))
(string/includes? reihe "SJW")) (re-find #"\d+" reihe)
(not (str/blank? reihe))
(str/includes? reihe "SJW")) (re-find #"\d+" reihe)
:else ""))

(defn- source
[{:keys [source]}]
(cond
(string/blank? source) ""
(str/blank? source) ""
(= source "keine") ""
:else source))

(defn- product-type
[{:keys [product-number]}]
(condp #(string/starts-with? %2 %1) product-number
(condp #(str/starts-with? %2 %1) product-number
"PS" :braille
"GD" :large-print
"EB" :ebook
Expand Down Expand Up @@ -101,8 +101,8 @@
(assoc :production-series production-series)
(assoc :production-series-number production-series-number)
(cond-> product-type (assoc :product-type product-type))
(cond-> (not (string/blank? verkaufstext)) (assoc :author (-> verkaufstext (string/split #"\[xx\]") first string/trim)))
(cond-> (not (string/blank? verkaufstext)) (assoc :title (-> verkaufstext (string/split #"\[xx\]") second string/trim))))))
(cond-> (not (str/blank? verkaufstext)) (assoc :author (-> verkaufstext (str/split #"\[xx\]") first str/trim)))
(cond-> (not (str/blank? verkaufstext)) (assoc :title (-> verkaufstext (str/split #"\[xx\]") second str/trim))))))

(defn extract-value
"Extract values from a `zipper` from an ABACUS export file for `key`"
Expand Down
4 changes: 2 additions & 2 deletions src/clj/daisyproducer2/documents/documents.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns daisyproducer2.documents.documents
(:require [babashka.fs :as fs]
[clojure.string :as string]
[clojure.string :as str]
[daisyproducer2.config :refer [env]]
[daisyproducer2.db.core :as db]
[daisyproducer2.metrics :as metrics]
Expand All @@ -25,7 +25,7 @@

(defn get-document-for-source-or-title-and-source-edition
[{:keys [source title source-edition] :as params}]
(or (and source (not (string/blank? source)) (db/get-document-for-source params))
(or (and source (not (str/blank? source)) (db/get-document-for-source params))
(and title source-edition (db/get-document-for-title-and-source-edition params))))

(defn initialize-document
Expand Down
6 changes: 3 additions & 3 deletions src/clj/daisyproducer2/documents/metadata_validation.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns daisyproducer2.documents.metadata-validation
"Validate the metadata of DTBook XML files"
(:require [clojure.java.io :as io]
[clojure.string :as string]
[clojure.string :as str]
[clojure.xml :as xml]
[clojure.zip :as zip]
[clojure.data.zip.xml :refer [xml1-> attr= attr text]])
Expand Down Expand Up @@ -61,9 +61,9 @@
"Return an error message for `key` that has the value `expected`
instead of the values in `actuals`"
[key expected actuals]
(let [name (string/capitalize (name key))]
(let [name (str/capitalize (name key))]
(str name " should be '" expected "' instead of "
(string/join
(str/join
" and "
(map #(if (some? %) (str "'" % "'") "undefined")
actuals)))))
Expand Down
4 changes: 2 additions & 2 deletions src/clj/daisyproducer2/documents/preview/dtbook2sbsform.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
(:require
[babashka.fs :as fs]
[babashka.process :as process]
[clojure.string :as string]
[clojure.string :as str]
[clojure.tools.logging :as log]
[clojure.java.io :as io]))

Expand Down Expand Up @@ -49,7 +49,7 @@

(defn- stringify-opts
[[k v]]
(let [opt-key (string/replace (name k) #"-" "_")]
(let [opt-key (str/replace (name k) #"-" "_")]
(cond
(boolean? v) (format "?%s=%s" opt-key (if v "true()" "false()"))
(integer? v) (format "?%s=%s" opt-key v)
Expand Down
4 changes: 2 additions & 2 deletions src/clj/daisyproducer2/hyphenate.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
hyphenation dictionaries in the file system the hyphenators list
needs to be reloaded."
(:require [clojure.java.io :as io]
[clojure.string :as string]
[clojure.string :as str]
[clojure.tools.logging :as log]
[daisyproducer2.config :refer [env]]
[mount.core :refer [defstate]])
Expand Down Expand Up @@ -33,7 +33,7 @@
(defn- hyphenate*
"Hyphenate given `text` using a given `hyphenator`"
[text ^Hyphenator hyphenator]
(if (string/blank? text)
(if (str/blank? text)
""
(.hyphenate hyphenator text \- nil)))

Expand Down
2 changes: 1 addition & 1 deletion src/clj/daisyproducer2/hyphenations.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
(defn delete-hyphenation [word spelling]
(log/debug "Delete hyphenation" word)
(let [deleted (db/delete-hyphenation {:word word :spelling spelling})]
(when (> deleted 0)
(when (pos? deleted)
(hyphenations/export))
deleted))

Expand Down
7 changes: 4 additions & 3 deletions src/clj/daisyproducer2/louis.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns daisyproducer2.louis
(:require [clojure.tools.logging :as log])
(:require [clojure.tools.logging :as log]
[clojure.string :as str])
(:import (org.liblouis Translator)))

(def base-tables ["sbs-wordsplit.dis" "sbs-de-core6.cti" "sbs-de-accents.cti",
Expand All @@ -26,12 +27,12 @@
:else grade2-tables)))

(defn translator [tables]
(let [tables-string (apply str (interpose \, tables))]
(let [tables-string (str/join \, tables)]
(Translator. ^String tables-string)))

(defn translate [word ^Translator translator]
(let [length (count word)
inter-character-attributes (int-array (repeat (- length 1) 0))]
inter-character-attributes (int-array (repeat (dec length) 0))]
(try
(.getBraille (.translate translator word nil nil inter-character-attributes))
;; log the params that caused the exception and bubble it up
Expand Down
14 changes: 7 additions & 7 deletions src/clj/daisyproducer2/pipeline1.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[babashka.fs :as fs]
[babashka.process :as process]
[clojure.set :as set]
[clojure.string :as s]
[clojure.string :as str]
[clojure.tools.logging :as log]
[daisyproducer2.config :refer [env]]
[medley.core :refer [update-existing]]))
Expand All @@ -22,16 +22,16 @@

(defn- clean-line [line file]
(-> line
(s/replace "[ERROR, Validator]" "")
(s/replace (str "Location: file:" file) "Line:")
s/trim))
(str/replace "[ERROR, Validator]" "")
(str/replace (str "Location: file:" file) "Line:")
str/trim))

(defn- filter-output [output file]
(->> output
s/split-lines
str/split-lines
;; make sure we merge continuation lines with their log line
(partition-by continuation-line?)
(map s/join)
(map str/join)
(filter #(re-matches #"^\[ERROR, Validator\].*" %))
(map #(clean-line % file))))

Expand All @@ -43,7 +43,7 @@
;; the pipeline1 validator is not so brilliant when it comes to
;; returning error conditions. For that reason we check for
;; existence of the input file before hand
(if (not (and (fs/exists? file) (fs/readable? file)))
(if-not (and (fs/exists? file) (fs/readable? file))
[(format "Input file '%s' does not exist or is not readable" file)]
(let [args ["daisy-pipeline"
(str (fs/path (env :pipeline1-install-path)
Expand Down
2 changes: 1 addition & 1 deletion src/clj/daisyproducer2/pipeline2/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
[[job job-create-form] & body]
`(let [~job ~job-create-form]
(try
~@body
(do ~@body)
(catch Exception e#
(throw (ex-info
(format "Failed to run Pipeline2 job because %s" (ex-message e#))
Expand Down
6 changes: 3 additions & 3 deletions src/clj/daisyproducer2/pipeline2/scripts.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
(:require
[clojure.java.io :as io]
[clojure.set :as set]
[clojure.string :as string]
[clojure.string :as str]
[daisyproducer2.pipeline2.core :as pipeline2]
[medley.core :refer [update-existing]]))

Expand All @@ -17,7 +17,7 @@
(let [completed (pipeline2/wait-for job)
results (pipeline2/get-results completed)
epub-stream (->> results
(filter #(string/ends-with? % ".epub"))
(filter #(str/ends-with? % ".epub"))
first
pipeline2/get-stream)]
(with-open [in epub-stream
Expand Down Expand Up @@ -56,7 +56,7 @@
(let [completed (pipeline2/wait-for job)
results (pipeline2/get-results completed)
odt-stream (->> results
(filter #(string/ends-with? % ".odt"))
(filter #(str/ends-with? % ".odt"))
first
pipeline2/get-stream)]
(with-open [in odt-stream
Expand Down
36 changes: 18 additions & 18 deletions src/clj/daisyproducer2/routes/services.clj
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
:homograph-disambiguation string?}}
:handler (fn [{{word :body} :parameters}]
(let [deleted (global/delete-word word)]
(if (>= deleted 1)
(if (pos? deleted)
(no-content)
(not-found))))}}]]

Expand Down Expand Up @@ -238,7 +238,7 @@
:spelling ::spelling}}
:handler (fn [{{word :body} :parameters}]
(let [deleted (local/delete-word word)]
(if (>= deleted 1)
(if (pos? deleted)
(no-content) ; we found something and deleted it
(not-found))))}}] ; couldn't find and delete the requested resource

Expand Down Expand Up @@ -273,7 +273,7 @@
:isignored boolean?}}
:handler (fn [{{word :body} :parameters}]
(let [modified (unknown/put-word word)]
(if (> modified 0)
(if (pos? modified)
(no-content)
(not-found))))}}]

Expand Down Expand Up @@ -350,9 +350,9 @@
opts :query} :parameters}]
(if-let [doc (documents/get-document id)]
(try
(let [[name _] (preview/sbsform doc opts)]
(let [url (str "/download/" name)]
(created url {:location url})))
(let [[name _] (preview/sbsform doc opts)
url (str "/download/" name)]
(created url {:location url}))
(catch clojure.lang.ExceptionInfo e
(log/error (ex-message e))
(internal-server-error {:status-text (ex-message e)}))
Expand All @@ -377,9 +377,9 @@
opts :query} :parameters}]
(if-let [doc (documents/get-document id)]
(try
(let [[name _] (preview/large-print id opts)]
(let [url (str "/download/" name)]
(created url {:location url})))
(let [[name _] (preview/large-print id opts)
url (str "/download/" name)]
(created url {:location url}))
(catch clojure.lang.ExceptionInfo e
(log/error (ex-message e))
(internal-server-error {:status-text (ex-message e)}))
Expand All @@ -402,9 +402,9 @@
opts :query} :parameters}]
(if-let [doc (documents/get-document id)]
(try
(let [[name _] (preview/open-document id opts)]
(let [url (str "/download/" name)]
(created url {:location url})))
(let [[name _] (preview/open-document id opts)
url (str "/download/" name)]
(created url {:location url}))
(catch clojure.lang.ExceptionInfo e
(log/error (ex-message e))
(internal-server-error {:status-text (ex-message e)}))
Expand Down Expand Up @@ -469,7 +469,7 @@
:parameters {:path {:id int? :version-id int?}}
:handler (fn [{{{:keys [id version-id]} :path} :parameters}]
(let [deleted (versions/delete-version id version-id)]
(if (> deleted 0)
(if (pos? deleted)
(no-content) ; we found something and deleted it
(not-found))))}}]]

Expand Down Expand Up @@ -509,7 +509,7 @@
:handler (fn [{{{:keys [id]} :path} :parameters
{{uid :uid} :user} :identity}]
(let [deleted (images/delete-all-images id)]
(if (> deleted 0)
(if (pos? deleted)
(ok {:deleted deleted}) ; we found something and deleted it
(not-found))))}}]
["/:image-id"
Expand All @@ -525,7 +525,7 @@
:parameters {:path {:id int? :image-id int?}}
:handler (fn [{{{:keys [id image-id]} :path} :parameters}]
(let [deleted (images/delete-image id image-id)]
(if (> deleted 0)
(if (pos? deleted)
(no-content) ; we found something and deleted it
(not-found))))}}]]
["/products"
Expand Down Expand Up @@ -567,7 +567,7 @@
:parameters {:path {:id int? :product-id int?}}
:handler (fn [{{{:keys [product-id]} :path} :parameters}]
(let [deleted (products/delete-product product-id)]
(if (> deleted 0)
(if (pos? deleted)
(no-content) ; we found something and deleted it
(not-found))))}}]]]

Expand All @@ -593,7 +593,7 @@
:spelling ::spelling}}
:handler (fn [{{word :body} :parameters}]
(let [modified (confirm/put-word word)]
(if (> modified 0)
(if (pos? modified)
(no-content)
(not-found))))}}]

Expand Down Expand Up @@ -628,7 +628,7 @@
:hyphenation string?}}
:handler (fn [{{{:keys [word spelling]} :body} :parameters}]
(let [deleted (hyphenations/delete-hyphenation word spelling)]
(if (> deleted 0)
(if (pos? deleted)
(no-content) ; we found something and deleted it
;; if there was no deletion it can mean that either the hyphenation doesn't
;; exist or and this is more likely that the associated word still exists in
Expand Down
Loading

0 comments on commit bd7b278

Please sign in to comment.