Skip to content

Commit

Permalink
Add splint, fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahTheDuke committed Nov 25, 2024
1 parent 78ed40b commit 9de38c4
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 11 deletions.
42 changes: 42 additions & 0 deletions .splint.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
;; Splint configuration auto-generated on 2024-11-25.
;; All failing rules have been disabled and can be enabled as time allows.

{
;; Diagnostics count: 2
;; Using unquote-splicing on a body in a macro can lead to subtly broken code that's hard to debug.
lint/body-unquote-splicing {:enabled false}

;; Diagnostics count: 48
;; Specify a function name for defmethod bodies.
lint/defmethod-names {:enabled false}

;; Diagnostics count: 2
;; Prefer `vec` or `set` to `(into [] ...)`.
lint/into-literal {:enabled false}

;; Diagnostics count: 50
;; Prefer `(y x)` to `(-> x y)`.
;; :supported-styles [:inline :avoid-collections]
lint/thread-macro-one-arg {:enabled false}

;; Diagnostics count: 40
;; Always set *warn-on-reflection* to avoid reflection in interop.
lint/warn-on-reflection {:enabled false}

;; Diagnostics count: 22
;; Avoid functions longer than 10 lines of code (default).
;; :supported-styles [:body :defn]
metrics/fn-length {:enabled false}

;; Diagnostics count: 14
;; Avoid calling assoc with multiple pairs.
performance/assoc-many {:enabled false}

;; Diagnostics count: 28
;; Rely on `.equals` when comparing against string literals.
performance/dot-equals {:enabled false}

;; Diagnostics count: 1
;; Prefer `condp` to `cond` when testing same base case.
style/prefer-condp {:enabled false}
}
3 changes: 3 additions & 0 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
;; Run the tests with `-M:provided:dev:test:run`.
:test {:extra-paths ["test/clojure"]}

:splint {:extra-deps {io.github.noahtheduke/splint {:mvn/version "1.18.0"}}
:main-opts ["-m" "noahtheduke.splint"]}

:ci {:main-opts ["-m" "lazytest.main"
"--doctests"
"--md" "README.md"
Expand Down
6 changes: 4 additions & 2 deletions src/clojure/lazytest/color.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
(ns lazytest.color)
(ns lazytest.color
(:require
[clojure.string :as str]))

(def ^:dynamic *color*
(contains? #{"yes" "true"} (System/getProperty "lazytest.colorize" "true")))
Expand Down Expand Up @@ -34,7 +36,7 @@
"Return ANSI color codes for the given sequence of colors, which are
keywords in color-table."
[& colors]
(apply str (map (fn [c] (str (char 27) (color-table c))) colors)))
(str/join (map (fn [c] (str (char 27) (color-table c))) colors)))

(defn colorize
"Wrap string s in ANSI colors if colorize? is true."
Expand Down
2 changes: 1 addition & 1 deletion src/clojure/lazytest/extensions/expectations.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@
[n & body]
(with-meta
(if (and (= (count body) 2)
(not (some contains-expect? body)))
(not-any? contains-expect? body))
;; treat (defexpect my-name pred (expr)) as a special case
`(lt/defdescribe ~n (lt/it "" (expect ~@body)))
;; #13 match deftest behavior starting in 2.0.0
Expand Down
2 changes: 1 addition & 1 deletion src/clojure/lazytest/reporters.clj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
(defn reporter-dispatch [_config m] (:type m))

(defn- indent [n]
(print (apply str (repeat n " "))))
(print (str/join (repeat n " "))))

;; FOCUSED
;; Prints a message when tests are focused.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
(is (= 7 (+ 3 4)) "is works"))
(testing "are works"
(are [x y] (= x y)
2 (+ 1 1)
4 (* 2 2))))
4 (+ 2 2)
8 (* 2 4))))

(in-ns 'lazytest.experimental.interfaces.clojure-test-test)

Expand Down
6 changes: 3 additions & 3 deletions test/clojure/lazytest/experimental/interfaces/qunit_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
(prep-ns-suite!)

(test! "initial"
(assert! (= false (pos? 0))))
(assert! (false? (pos? 0))))

(module! "Group A")

(test! "foo"
(assert! (= true (pos? 1))))
(assert! (true? (pos? 1))))

(test! "bar"
(assert! (= true (pos? 1))))
(assert! (true? (pos? 1))))

(in-ns 'lazytest.experimental.interfaces.qunit-test)

Expand Down
2 changes: 1 addition & 1 deletion test/clojure/lazytest/extensions/expectations_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

(sut/defexpect simple-test 1 1)

(sut/defexpect simple-call-test (+ 1 2) (+ 1 1 1))
(sut/defexpect simple-call-test (+ 2 4) (+ 2 2 2))

(sut/defexpect either-expect-works
(it "handles lazytest" (expect (= 1 1)))
Expand Down
2 changes: 1 addition & 1 deletion test/clojure/lazytest/suite_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

;; manually writing test cases (instead of using `it`)
(defn common-test-cases [x]
[(when (= x 0)
[(when (zero? 0)
(test-case {:doc (str x " equals zero")
:body #(expect (= x 1))}))
(when (= x 1)
Expand Down

0 comments on commit 9de38c4

Please sign in to comment.