Skip to content

Commit bd6a630

Browse files
authored
Merge pull request #477 from walmartlabs/hls/20260603-better-cond
chore: replace cond-let with better-cond.core/cond, setup linter, remove all warnings
2 parents 584da83 + 6c5a200 commit bd6a630

36 files changed

Lines changed: 1047 additions & 1029 deletions

.clj-kondo/config.edn

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{:config-paths ["imports/better-cond/better-cond"
2+
"imports/io.pedestal/pedestal.log"]
3+
4+
:linters
5+
{;; Protocol/interface implementations routinely have unused bindings for
6+
;; parameters they must declare but don't use.
7+
:unused-binding {:level :off}
8+
9+
;; `coercion-failure` and `as-conformer` are deprecated for external use but are
10+
;; still used internally in schema.clj for default scalar definitions, in parser.clj
11+
;; as part of parsing, and in tests that validate backward-compatibility behaviour.
12+
:deprecated-var {:level :off}
13+
14+
;; `wrap-list` and `expand-implements` are private vars that appear unused to kondo
15+
;; but are exercised at runtime.
16+
:unused-private-var {:exclude [com.walmartlabs.lacinia.schema/wrap-list
17+
com.walmartlabs.lacinia.schema/expand-implements]}
18+
19+
;; Some functions use {:added "x.y.z"} metadata maps in their body; kondo flags
20+
;; these as unused values. This pattern is valid in Clojure.
21+
:unused-value {:level :off}
22+
23+
;; Redundant-let warnings fire inside b/cond :let blocks; suppress globally since
24+
;; the false-positive rate is high and real redundant lets are trivially visible.
25+
:redundant-let {:level :off}}}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ build.xml
2020
.classpath
2121
*.pom.asc
2222
.cpcache
23+
.clj-kondo/*
24+
!.clj-kondo/config.edn

build.clj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
(ns build
1818
(:require [clojure.string :as string]
19+
[clj-commons.ansi :refer [pout]]
1920
[clojure.tools.build.api :as build]
2021
[net.lewisship.build :as b]))
2122

@@ -69,3 +70,21 @@
6970
(println "Pushing changes ...")
7071
(build/process {:dir publish-dir
7172
:command-args ["git" "push"]}))
73+
74+
(defn lint
75+
"Lint source files using clj-kondo."
76+
[opts]
77+
(let [lint-options (merge {:lint ["src" "test"]
78+
:config
79+
{:linters
80+
{:unresolved-symbol
81+
{:exclude '[(clojure.test/is [match?])]}}}}
82+
opts)
83+
kondo-run! (requiring-resolve 'clj-kondo.core/run!)
84+
kondo-print! (requiring-resolve 'clj-kondo.core/print!)
85+
results (kondo-run! lint-options)]
86+
(kondo-print! results)
87+
(when (pos? (get-in results [:summary :errors] 0))
88+
(pout [:red [:bold "ERROR"] ": clj-kondo found errors 😢"])
89+
(System/exit -1))
90+
(pout [:bold.green "clj-kondo approves ☺️"])))

deps.edn

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,39 @@
1-
{:deps {org.clojure/clojure {:mvn/version "1.12.5"}
2-
org.antlr/antlr4-runtime {:mvn/version "4.13.2"}
3-
org.flatland/ordered {:mvn/version "1.15.12"}
4-
org.clojure/data.json {:mvn/version "2.5.2"}}
1+
{:deps {org.clojure/clojure {:mvn/version "1.12.5"}
2+
org.antlr/antlr4-runtime {:mvn/version "4.13.2"}
3+
org.flatland/ordered {:mvn/version "1.15.12"}
4+
org.clojure/data.json {:mvn/version "2.5.2"}
5+
better-cond/better-cond {:mvn/version "2.1.5"}}
56
:paths ["src" "resources" "target/classes"]
67

78
:deps/prep-lib
89
{:ensure "target/classes"
9-
:alias :build
10-
:fn compile-java}
10+
:alias :build
11+
:fn compile-java}
1112
:aliases
1213
{:dev
13-
{:extra-deps {criterium/criterium {:mvn/version "0.4.6"}
14-
org.clojure/core.async {:mvn/version "1.9.865"}
15-
expound/expound {:mvn/version "0.9.0"}
16-
joda-time/joda-time {:mvn/version "2.14.2"}
17-
com.walmartlabs/test-reporting {:mvn/version "1.2"}
18-
io.github.hlship/trace {:mvn/version "1.4"}
19-
io.pedestal/pedestal.log {:mvn/version "0.8.1"}
20-
org.clojure/test.check {:mvn/version "1.1.3"}
21-
org.clojure/data.csv {:mvn/version "1.1.1"}
22-
org.clojure/tools.cli {:mvn/version "1.4.256"}
23-
com.clojure-goes-fast/clj-async-profiler {:mvn/version "1.7.0"}}
24-
:jvm-opts ["-Xmx1g"
25-
"-Xms1g"
26-
"-XX:NewSize=200m"
27-
"-XX:MaxNewSize=500m"
28-
"-XX:-OmitStackTraceInFastThrow"
29-
"-XX:+UnlockDiagnosticVMOptions"
30-
"-XX:+DebugNonSafepoints"
31-
"-XX:FlightRecorderOptions=stackdepth=256"
32-
"-Djdk.attach.allowAttachSelf"
33-
"-Dapple.awt.UIElement=true"]
14+
{:extra-deps {criterium/criterium {:mvn/version "0.4.6"}
15+
org.clj-commons/pretty {:mvn/version "3.8.0"}
16+
io.github.tonsky/clj-reload {:mvn/version "1.0.0"}
17+
org.clojure/core.async {:mvn/version "1.9.865"}
18+
expound/expound {:mvn/version "0.9.0"}
19+
joda-time/joda-time {:mvn/version "2.14.2"}
20+
com.walmartlabs/test-reporting {:mvn/version "1.2"}
21+
io.github.hlship/trace {:mvn/version "1.4"}
22+
io.pedestal/pedestal.log {:mvn/version "0.8.1"}
23+
org.clojure/test.check {:mvn/version "1.1.3"}
24+
org.clojure/data.csv {:mvn/version "1.1.1"}
25+
org.clojure/tools.cli {:mvn/version "1.4.256"}
26+
com.clojure-goes-fast/clj-async-profiler {:mvn/version "1.7.0"}}
27+
:jvm-opts ["-Xmx1g"
28+
"-Xms1g"
29+
"-XX:NewSize=200m"
30+
"-XX:MaxNewSize=500m"
31+
"-XX:-OmitStackTraceInFastThrow"
32+
"-XX:+UnlockDiagnosticVMOptions"
33+
"-XX:+DebugNonSafepoints"
34+
"-XX:FlightRecorderOptions=stackdepth=256"
35+
"-Djdk.attach.allowAttachSelf"
36+
"-Dapple.awt.UIElement=true"]
3437
:extra-paths ["test" "dev-resources"]}
3538

3639
:clojure-11 {}
@@ -55,7 +58,9 @@
5558

5659
;; clj -T:build <command>
5760
:build {:deps {io.github.hlship/build-tools
58-
{:git/tag "0.12.1" :git/sha "05f3ae"}}
61+
{:git/tag "0.12.1" :git/sha "05f3ae"}
62+
clj-kondo/clj-kondo {:mvn/version "2026.04.15"}
63+
org.clj-commons/pretty {:mvn/version "3.8.0"}}
5964
:ns-default build}}
6065
:net.lewisship.build/scm
6166
{:license :asl}

src/com/walmartlabs/lacinia.clj

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
[com.walmartlabs.lacinia.constants :as constants]
1818
[com.walmartlabs.lacinia.executor :as executor]
1919
[com.walmartlabs.lacinia.validator :as validator]
20-
[com.walmartlabs.lacinia.internal-utils :refer [cond-let]]
20+
[better-cond.core :as b]
2121
[com.walmartlabs.lacinia.util :refer [as-error-map]]
2222
[com.walmartlabs.lacinia.resolve :as resolve]
2323
[com.walmartlabs.lacinia.tracing :as tracing])
@@ -37,7 +37,7 @@
3737
{:pre [(map? parsed-query)
3838
(or (nil? context)
3939
(map? context))]}
40-
(cond-let
40+
(b/cond
4141
:let [{:keys [::tracing/timing-start]} parsed-query
4242
;; Validation phase encompasses preparing with query variables and actual validation.
4343
;; It's somewhat all mixed together.
@@ -59,7 +59,7 @@
5959
:else
6060
(executor/execute-query (assoc context constants/parsed-query-key (assoc prepared
6161
::tracing/validation {:start-offset start-offset
62-
:duration (tracing/duration start-nanos)})))))
62+
:duration (tracing/duration start-nanos)})))))
6363

6464
(defn execute-parsed-query
6565
"Prepares a query, by applying query variables to it, resulting in a prepared
@@ -72,19 +72,19 @@
7272
([parsed-query variables context]
7373
(execute-parsed-query parsed-query variables context nil))
7474
([parsed-query variables context options]
75-
(let [*result (promise)
75+
(let [*result (promise)
7676
{:keys [timeout-ms timeout-error]
77-
:or {timeout-ms 0
78-
timeout-error {:message "Query execution timed out."}}} options
77+
:or {timeout-ms 0
78+
timeout-error {:message "Query execution timed out."}}} options
7979
execution-result (execute-parsed-query-async parsed-query variables context)
80-
result (do
81-
(resolve/on-deliver! execution-result *result)
82-
;; Block on that deliver, then return the final result.
83-
(if (pos? timeout-ms)
84-
(deref *result
85-
timeout-ms
86-
{:errors [timeout-error]})
87-
@*result))]
80+
result (do
81+
(resolve/on-deliver! execution-result *result)
82+
;; Block on that deliver, then return the final result.
83+
(if (pos? timeout-ms)
84+
(deref *result
85+
timeout-ms
86+
{:errors [timeout-error]})
87+
@*result))]
8888
(when (instance? Throwable result)
8989
(throw result))
9090

0 commit comments

Comments
 (0)