Skip to content

Commit 6453b30

Browse files
authored
dev: add Eastwood linting (#573)
* dev: add Eastwood linting For some other Etaoin wip, I wanted to address some reflection warnings for new code and noticed we did not have any existing checks for reflection. I find Eastwood helps out with this nicely. In addition to reflection warnings, I also addressed some other issues Eastwood reported: - A booboo in a test assertion for `etaoin.unit.unit-test/test-chrome-profile`. Fixed! - URL constructors are deprecated, starting with JDK 20. I switched to using lambdaisland/uri. - it noticed `is` assert messages that were not obviously strings. I ^String type hinted the message generating fn. - it thought string `"always"` for a constant truthy looked suspicious. I switched to the more conventional `:always`. - several tests had empty assertions like `(is true "text found")` or `(is 1)`. Perhaps some linter once warned about a test without assertions? We don't have such a thing today, so I turfed these meaningless assertions. The unwritten assertion for these tests is that they do not throw an exception. * add/ignore lint stuff - add some kondo lib config brought in by kondo - git ignore .eastwood dir
1 parent 18124a3 commit 6453b30

File tree

22 files changed

+80
-43
lines changed

22 files changed

+80
-43
lines changed

.clj-kondo/taoensso/encore/config.edn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{:hooks {:analyze-call {taoensso.encore/defalias taoensso.encore/defalias}}}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
(ns taoensso.encore
2+
(:require
3+
[clj-kondo.hooks-api :as hooks]))
4+
5+
(defn defalias [{:keys [node]}]
6+
(let [[sym-raw src-raw] (rest (:children node))
7+
src (if src-raw src-raw sym-raw)
8+
sym (if src-raw
9+
sym-raw
10+
(symbol (name (hooks/sexpr src))))]
11+
{:node (with-meta
12+
(hooks/list-node
13+
[(hooks/token-node 'def)
14+
(hooks/token-node (hooks/sexpr sym))
15+
(hooks/token-node (hooks/sexpr src))])
16+
(meta src))}))

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ TAGS
1717
*.iml
1818
build.xml
1919
/.idea
20+
/.eastwood
2021

2122
# ignore cache under .clj-kondo and .lsp
2223
.cache

bb.edn

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,12 @@
7878
(filterv (fn [p] (re-find pattern (:command p))))
7979
(doric/table [:pid :start-instant :is-alive :command :arguments])
8080
println))}
81-
lint {:doc "[--rebuild] lint source code"
81+
lint-kondo {:doc "[--rebuild] lint source code with clj-kondo"
8282
:task lint/-main}
83+
lint-eastwood {:doc "Run Eastwood linter on source code"
84+
:task (shell/clojure "-M:eastwood")}
85+
lint {:doc "Run all linters"
86+
:depends [lint-kondo lint-eastwood]}
8387
cljdoc-preview {:doc "preview what docs will look like on cljdoc, use --help for args"
8488
:task cljdoc-preview/-main}
8589
tools-versions {:doc "report on tools versions"

deps.edn

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
slingshot/slingshot {:mvn/version "0.12.2"}
88
cheshire/cheshire {:mvn/version "5.12.0"}
99
org.clojure/tools.cli {:mvn/version "1.1.230"}
10-
org.clojure/tools.logging {:mvn/version "1.3.0"}}
10+
org.clojure/tools.logging {:mvn/version "1.3.0"}
11+
lambdaisland/uri {:mvn/version "1.19.155"}}
1112
:aliases
1213
{:1.11 {:replace-deps {org.clojure/clojure {:mvn/version "1.11.2"}}}
1314
:1.12 {:replace-deps {org.clojure/clojure {:mvn/version "1.12.0-alpha9"}}}
@@ -47,6 +48,13 @@
4748
:clj-kondo {:extra-deps {clj-kondo/clj-kondo {:mvn/version "2024.03.13"}}
4849
:main-opts ["-m" "clj-kondo.main"]}
4950

51+
:eastwood {:extra-deps {jonase/eastwood {:mvn/version "1.4.2"}}
52+
:extra-paths ["test"]
53+
:main-opts ["-m" "eastwood.lint" {:source-paths ["src"]
54+
:test-paths ["test"]
55+
:add-linters [:performance]
56+
:exclude-linters [:local-shadows-var]}]}
57+
5058
:build {:deps {io.github.clojure/tools.build {:mvn/version "0.10.0"}
5159
slipset/deps-deploy {:mvn/version "0.2.2"}}
5260
:ns-default build}

src/etaoin/api.clj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@
160160
java.text.SimpleDateFormat
161161
(java.util Base64 Date)))
162162

163+
(set! *warn-on-reflection* true)
164+
163165
;;
164166
;; WebDriver defaults
165167
;;
@@ -2813,7 +2815,7 @@
28132815
"Clojure returns a seq of chars for a string.
28142816
This does not handle wide (unicode) characters.
28152817
Here we return a seq of codepoint strings for string `s`."
2816-
[s]
2818+
[^String s]
28172819
(->> s
28182820
.codePoints
28192821
.iterator
@@ -3166,7 +3168,7 @@
31663168

31673169
(defn- b64-decode [s]
31683170
(-> (Base64/getDecoder)
3169-
(.decode s)))
3171+
(.decode ^String s)))
31703172

31713173
(defmulti ^:private b64-to-file
31723174
"Dumps a Base64-encoded string into a file.

src/etaoin/api2.clj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
(:require
44
[etaoin.api :as e]))
55

6+
(set! *warn-on-reflection* true)
7+
68
(defmacro with-firefox
79
"Executes `body` with a Firefox driver session bound to `bind`.
810

src/etaoin/dev.clj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
[clojure.string :as str]
66
[etaoin.api :as api]))
77

8+
(set! *warn-on-reflection* true)
9+
810
(defn- try-parse-int
911
[line]
1012
(try (Integer/parseInt line)

src/etaoin/ide/flow.clj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
[etaoin.ide.impl.api :refer [run-command-with-log str->var]]
99
[etaoin.ide.impl.spec :as spec]))
1010

11+
(set! *warn-on-reflection* true)
12+
1113
(declare execute-commands)
1214

1315
(defn- execute-branch

src/etaoin/ide/impl/api.clj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
[etaoin.impl.util :refer [defmethods]]
1313
[etaoin.keys :as k]))
1414

15+
(set! *warn-on-reflection* true)
16+
1517
(defn absolute-path?
1618
[path]
1719
(-> path
@@ -158,7 +160,7 @@
158160
(str base-url "/" target)))
159161

160162
(defn make-assert-msg
161-
[command actual expected]
163+
^String [command actual expected]
162164
(format "\nAssert command:\"%s\"\nExpected: %s\nActual: %s"
163165
(name command) expected actual))
164166

@@ -628,7 +630,7 @@
628630
(not (str/blank? target))
629631
(str (format " on '%s'" target))
630632

631-
"always"
633+
:always
632634
(str (format "Command: %s" (name command)))))
633635

634636
(defn run-command-with-log

0 commit comments

Comments
 (0)