Skip to content

Commit

Permalink
style: clj kondo fixes (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsmassa authored Apr 12, 2023
1 parent d31f15f commit c904fc3
Show file tree
Hide file tree
Showing 34 changed files with 276 additions and 289 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ workflows:
only: main
requires:
- tools/unittest
- tools/cljstest
- tools/release:
context:
- github-token
Expand Down
5 changes: 5 additions & 0 deletions .clj-kondo/config.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{:hooks {:analyze-call {superv.async/go-try- hooks.go-try-/go-try-}}
:lint-as {konserve.utils/with-promise clj-kondo.lint-as/def-catch-all}
:linters {:unresolved-symbol {:exclude [(konserve.utils/async+sync [do])]}
:unused-referred-var {:exclude {konserve.core [locked]}}
:clojure-lsp/unused-public-var {:exclude [build]}}}
11 changes: 11 additions & 0 deletions .clj-kondo/hooks/go_try_.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(ns hooks.go-try-
(:require [clj-kondo.hooks-api :as api]))

(defn go-try- [{:keys [:node]}]
(let [new-node (api/list-node
(apply list
(concat
[(api/token-node 'try)]
(rest (:children node))
[(api/list-node (list (api/token-node 'finally)))])))]
{:node new-node}))
4 changes: 2 additions & 2 deletions benchmark/src/benchmark/common.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns benchmark.common
(:require [konserve.core :as k]
[konserve.filestore :refer [new-fs-store delete-store]]
[konserve.filestore :refer [connect-fs-store delete-store]]
[konserve.memory :refer [new-mem-store]]
[clojure.core.async :refer [<!!] :as async]))

Expand All @@ -13,7 +13,7 @@

(defmethod get-store :file [_]
(delete-store fs-store-path)
(<!! (new-fs-store fs-store-path)))
(<!! (connect-fs-store fs-store-path)))

(defmethod get-store :memory [_]
(<!! (new-mem-store)))
Expand Down
6 changes: 3 additions & 3 deletions benchmark/src/benchmark/measure/create.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(:require [benchmark.common :refer [setup-store statistics timed plots benchmark fs-store-path]]
[benchmark.plot :refer [plot bar]]
[clojure.core.async :refer [<!!]]
[konserve.filestore :refer [new-fs-store]]
[konserve.filestore :refer [connect-fs-store]]
[konserve.memory :refer [new-mem-store]]
[oz.core :as oz]))

Expand All @@ -11,8 +11,8 @@
(case store-type
:memory (if sync? (timed (new-mem-store opts))
(timed (<!! (new-mem-store opts))))
:file (if sync? (timed (new-fs-store fs-store-path :opts opts))
(timed (<!! (new-fs-store fs-store-path :opts opts))))) )
:file (if sync? (timed (connect-fs-store fs-store-path :opts opts))
(timed (<!! (connect-fs-store fs-store-path :opts opts))))) )

(defmethod benchmark :create [_function stores store-sizes iterations]
(->> (for [store-type stores
Expand Down
11 changes: 11 additions & 0 deletions bin/run-all
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -o errexit
set -o pipefail

./bin/run-cljstests

echo
echo

./bin/run-unittests
2 changes: 2 additions & 0 deletions bin/run-cljstests
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ clojure -M:run-cljs-tests
#[ -d "node_modules/ws" ] || npm install ws
#clojure -M:test:cljs -m kaocha.runner unit-node

echo
echo

echo "Running tests for browser"
# kaocha version:
Expand Down
2 changes: 2 additions & 0 deletions bin/run-unittests
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

echo "Running unittests"

TIMBRE_LEVEL=':warn' clojure -M:test -m kaocha.runner unit
11 changes: 7 additions & 4 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{:paths ["src"]
:deps {org.clojure/clojure {:mvn/version "1.11.1"}
org.clojure/data.fressian {:mvn/version "1.0.0"} ;; for filestore
fress/fress {:mvn/version "0.4.0"}
mvxcvi/clj-cbor {:mvn/version "1.1.1"}
io.replikativ/incognito {:mvn/version "0.3.66"}
io.replikativ/hasch {:mvn/version "0.3.94"}
io.replikativ/superv.async {:mvn/version "0.3.46"}
io.replikativ/geheimnis {:mvn/version "0.1.1"}
org.clojars.mmb90/cljs-cache {:mvn/version "0.1.4"}
com.github.pkpkpk/cljs-node-io {:mvn/version "2.0.332"}
org.lz4/lz4-java {:mvn/version "1.8.0"}
com.taoensso/timbre {:mvn/version "6.0.1"}}
com.taoensso/timbre {:mvn/version "6.0.1"}
;; cljs
com.github.pkpkpk/cljs-node-io {:mvn/version "2.0.332"}
fress/fress {:mvn/version "0.4.0"}
org.clojars.mmb90/cljs-cache {:mvn/version "0.1.4"}}
:aliases {:cljs {:extra-deps {org.clojure/clojurescript {:mvn/version "1.11.60"}
thheller/shadow-cljs {:mvn/version "2.22.0"}
binaryage/devtools {:mvn/version "1.0.6"}}
Expand Down Expand Up @@ -45,5 +46,7 @@
:main-opts ["-m" "cljfmt.main" "check"]}
:ffix {:extra-deps {cljfmt/cljfmt {:mvn/version "0.9.2"}}
:main-opts ["-m" "cljfmt.main" "fix"]}
:lint {:replace-deps {clj-kondo/clj-kondo {:mvn/version "2023.02.17"}}
:main-opts ["-m" "clj-kondo.main" "--lint" "src"]}
:outdated {:extra-deps {com.github.liquidz/antq {:mvn/version "2.2.983"}}
:main-opts ["-m" "antq.core"]}}}
9 changes: 6 additions & 3 deletions src/konserve/cache.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
accessing the store, otherwise you should implement your own caching strategy."
(:refer-clojure :exclude [assoc-in assoc exists? dissoc get get-in
keys update-in update])
(:require [konserve.protocols :refer [-exists? -get-in -assoc-in
(:require [konserve.protocols :refer [-get-in -assoc-in
-update-in -dissoc]]
#?(:clj [clojure.core.cache :as cache]
:cljs [cljs.cache :as cache])
Expand Down Expand Up @@ -101,6 +101,7 @@
(swap! cache cache/miss key new-val))
[old-val new-val])))))

#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn update
"Updates a position described by key by applying up-fn and storing
the result atomically. Returns a vector [old new] of the previous
Expand All @@ -123,7 +124,7 @@
(go-locked
store (first key-vec)
(let [cache (:cache store)
[old-val new-val :as res] (<?- (-assoc-in store key-vec (partial meta-update (first key-vec) :edn) val opts))
[old-val new-val] (<?- (-assoc-in store key-vec (partial meta-update (first key-vec) :edn) val opts))
had-key? (cache/has? @cache key)]
(swap! cache cache/evict (first key-vec))
(when had-key?
Expand Down Expand Up @@ -154,9 +155,11 @@
(<?- (-dissoc store key opts)))))))

;; alias core functions without caching for convenience

#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(def append core/append)
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(def log core/log)
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(def reduce-log core/reduce-log)

(def bassoc core/bassoc)
Expand Down
13 changes: 5 additions & 8 deletions src/konserve/compliance_test.cljc
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
(ns konserve.compliance-test
(:require [clojure.core.async :refer [#?(:clj <!!) go chan <!]]
(:require [clojure.core.async :refer [#?(:clj <!!) <! go]]
[konserve.core :as k]
#?(:cljs [cljs.test :refer [deftest is testing async]])
#?(:clj [clojure.test :refer :all])
#?(:clj [konserve.serializers :refer [key->serializer]])
#?(:clj [konserve.utils :refer [async+sync]])
[konserve.memory :refer [new-mem-store]]))
#?(:cljs [cljs.test :refer [is]])
#?(:clj [clojure.test :refer [are is testing]])))

(deftype UnknownType [])
#_(deftype UnknownType [])

#?(:clj (defn exception? [thing]
#_(:clj (defn exception? [thing]
(instance? Throwable thing)))

#?(:clj
Expand Down
9 changes: 5 additions & 4 deletions src/konserve/compressor.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

(defrecord UnsupportedLZ4Compressor [serializer]
PStoreSerializer
(-deserialize [_ read-handlers bytes]
(-deserialize [_ _read-handlers bytes]
(throw (ex-info "Unsupported LZ4 compressor." {:bytes bytes})))
(-serialize [_ bytes write-handlers val]
(-serialize [_ bytes _write-handlers _val]
(throw (ex-info "Unsupported LZ4 compressor." {:bytes bytes}))))

#?(:clj
Expand All @@ -41,8 +41,9 @@
#?(:clj
(defmacro native-image-build? []
(try
(and (Class/forName "org.graalvm.nativeimage.ImageInfo")
#_(eval '(org.graalvm.nativeimage.ImageInfo/inImageBuildtimeCode)))
;(and
(Class/forName "org.graalvm.nativeimage.ImageInfo")
;(eval '(org.graalvm.nativeimage.ImageInfo/inImageBuildtimeCode))) ;; TODO: when will this be uncommented?
(catch Exception _
false))))

Expand Down
10 changes: 6 additions & 4 deletions src/konserve/core.cljc
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
(ns konserve.core
(:refer-clojure :exclude [get get-in update update-in assoc assoc-in exists? dissoc keys])
(:require [clojure.core.async :refer [chan put! poll!]]
(:require [clojure.core.async :refer [chan put! #?(:clj poll!)]]
[hasch.core :as hasch]
[konserve.protocols :refer [-exists? -get-meta -get-in -assoc-in
-update-in -dissoc -bget -bassoc
-keys]]
[konserve.utils :refer [meta-update async+sync #?(:clj *default-sync-translation*)]]
[konserve.utils :refer [meta-update async+sync *default-sync-translation*]]
[superv.async :refer [go-try- <?-]]
[taoensso.timbre :refer [trace debug]])
[taoensso.timbre :refer [trace #?(:cljs debug)]])
#?(:cljs (:require-macros [konserve.core :refer [go-locked locked]])))

;; ACID
Expand All @@ -27,11 +27,12 @@
(clojure.core/assoc old key c))))
key))))

(defn wait [lock]
(defn wait [#?(:clj lock :cljs _)]
#?(:clj (while (not (poll! lock))
(Thread/sleep (long (rand-int 20))))
:cljs (debug "WARNING: konserve lock is not active. Only use the synchronous variant with the memory store in JavaScript.")))

#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defmacro locked [store key & code]
`(let [l# (get-lock ~store ~key)]
(try
Expand Down Expand Up @@ -122,6 +123,7 @@
store (first key-vec)
(<?- (-update-in store key-vec (partial meta-update (first key-vec) :edn) up-fn opts))))))

#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn update
"Updates a position described by key by applying up-fn and storing
the result atomically. Returns a vector [old new] of the previous
Expand Down
Loading

0 comments on commit c904fc3

Please sign in to comment.