Skip to content

Commit

Permalink
Merge pull request #339 from reducecombine/kondo
Browse files Browse the repository at this point in the history
Introduce and satisfy clj-kondo
  • Loading branch information
lvh committed May 24, 2022
2 parents c7adbae + ec0087b commit 87fd10f
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 32 deletions.
3 changes: 2 additions & 1 deletion .circleci/config.yml
Expand Up @@ -50,6 +50,7 @@ jobs:
- save_cache:
paths:
- ~/.m2
- << parameters.working_directory >>/.clj-kondo/cache
key: v1-dependencies-<< parameters.clojure_version >>-<< parameters.command >>-{{ checksum "<< parameters.working_directory >>/project.clj" }}
- run:
working_directory: << parameters.working_directory >>
Expand Down Expand Up @@ -93,6 +94,6 @@ workflows:
clojure_version: ["1.11"]
jdk_version: [openjdk17]
working_directory: ["./cloverage", "./lein-cloverage"]
command: ["cljfmt check", "kibit"]
command: ["cljfmt check", "kibit", "kondo-ci"]
filters:
<<: *filters
6 changes: 6 additions & 0 deletions cloverage/.clj-kondo/config.edn
@@ -0,0 +1,6 @@
{:linters {:docstring-leading-trailing-whitespace {:level :warning}
:reduce-without-init {:level :warning}
:single-key-in {:level :warning}
:used-underscored-binding {:level :warning}
:unresolved-symbol {:exclude [(clojure.test/is [expand=])]}
:unused-private-var {:exclude [cloverage.coverage-test/my-long]}}}
14 changes: 14 additions & 0 deletions cloverage/project.clj
Expand Up @@ -41,6 +41,7 @@
:eastwood {:ignored-faults {:implicit-dependencies {cloverage.report.emma-xml ~(case clojure-profile
("1.8" "1.9") [{:line 42}]
[])}}}}
:clj-kondo {:plugins [[com.github.clj-kondo/lein-clj-kondo "0.1.4"]]}
:humane {:dependencies [[pjstadig/humane-test-output "0.11.0"]]
:injections [(require 'pjstadig.humane-test-output)
(pjstadig.humane-test-output/activate!)]}
Expand All @@ -55,6 +56,19 @@
:ci {:pedantic? :abort}}
:aliases {"all" ["with-profile" "+1.8:+1.9:+1.10:+1.11"]
"kaocha" ["test-ci"]
"kondo-deps" ["with-profile"
"+dev,+test,+ci,+clj-kondo"
"clj-kondo"
"--copy-configs"
"--dependencies"
"--lint"
"$classpath"]
"kondo-ci" ["do" ["kondo-deps"]
["with-profile"
~(str "+dev,+test,+ci,+clj-kondo,+" clojure-profile)
"clj-kondo"
"--lint"
"src" "test"]]
"eastwood-ci" ["with-profile"
~(str "-dev,+test,+ci,+eastwood,+" clojure-profile)
"eastwood"]
Expand Down
4 changes: 2 additions & 2 deletions cloverage/src/cloverage/coverage.clj
Expand Up @@ -205,7 +205,7 @@
{:errors (:failures (apply f nses))})
(throw (RuntimeException. "Failed to load Midje."))))

(defmethod runner-fn :clojure.test [{:keys [junit? output] :as opts}]
(defmethod runner-fn :clojure.test [{:keys [junit? output] :as _opts}]
(fn [nses]
(let [run-tests (fn []
(apply require (map symbol nses))
Expand Down Expand Up @@ -297,7 +297,7 @@
failed?)))

(defn run-main
[[{:keys [debug? junit? fail-threshold help? runner test-selectors selector], :as opts} add-nses help] project-opts]
[[{:keys [debug? fail-threshold help?], :as opts} add-nses help] project-opts]
(binding [*ns* (find-ns 'cloverage.coverage)
debug/*debug* debug?]
(if help?
Expand Down
20 changes: 10 additions & 10 deletions cloverage/src/cloverage/instrument.clj
Expand Up @@ -75,7 +75,7 @@
(if-let [o ((ns-map *ns*) s)]
(if (class? o)
(symbol (.getName ^Class o))
(if (var? o)
(when (var? o)
(let [^clojure.lang.Var o o]
(symbol (-> o .ns .name name) (-> o .sym name)))))
;; changed to returned unnamespaced symbol if it fails to resolve
Expand Down Expand Up @@ -193,7 +193,7 @@
"Traverse the given form and wrap all its sub-forms in a function that evals
the form and records that it was called."
{:arglists '([f line form env])}
(fn [f line form env]
(fn [_f _line form env]
(form-type form env)))

(defmacro wrapm
Expand Down Expand Up @@ -227,9 +227,9 @@
e.g. - `a (+ a b)` (let or loop)"
[f line-hint [args & body :as form]]
(d/tprnl "Wrapping overload" args body)
(let [line (or (:line (meta form)) line-hint)]
(let [wrapped (doall (map (wrapper f line) body))]
`(~args ~@wrapped))))
(let [line (or (:line (meta form)) line-hint)
wrapped (doall (map (wrapper f line) body))]
`(~args ~@wrapped)))

(defn wrap-overload
"Wrap a single function overload.
Expand Down Expand Up @@ -271,7 +271,7 @@
e)))))))

;; Don't wrap or descend into unknown forms
(defmethod do-wrap :unknown [f line form _]
(defmethod do-wrap :unknown [_f _line form _]
(log/warn (str "Unknown special form " (seq form)))
form)

Expand Down Expand Up @@ -339,7 +339,7 @@
(d/tprnl "Wrapping fn " form)
(f line (wrap-fn-body f line form)))

(defmethod do-wrap :let [f line [let-sym bindings & body :as form] _]
(defmethod do-wrap :let [f line [let-sym bindings & body :as _form] _]
(f line
`(~let-sym
[~@(mapcat (partial wrap-binding f line)
Expand All @@ -361,7 +361,7 @@
bindings)]
~@(doall (map (wrapper f line) body))))))

(defmethod do-wrap :def [f line [def-sym name & body :as form] _]
(defmethod do-wrap :def [f line [def-sym name & body :as _form] _]
(cond
(empty? body) (f line `(~def-sym ~name))
(= 1 (count body)) (let [init (first body)]
Expand All @@ -378,11 +378,11 @@
(let [[def-sym name fn-expr] (macroexpand-1 form)]
(f line `(~def-sym ~name ~(wrap-fn-body f line fn-expr)))))

(defmethod do-wrap :new [f line [new-sym class-name & args :as form] _]
(defmethod do-wrap :new [f line [new-sym class-name & args :as _form] _]
(f line `(~new-sym ~class-name ~@(doall (map (wrapper f line) args)))))

(defmethod do-wrap :dotjava
[f line [_ class-or-instance & more] env]
[f line [_ class-or-instance & more] _env]
;; form is either of the syntax
;;
;; (. class-or-instance method & args)
Expand Down
3 changes: 0 additions & 3 deletions cloverage/src/cloverage/report.clj
Expand Up @@ -17,9 +17,6 @@
(defn- group-by-line [forms]
(into (sorted-map) (group-by :line forms)))

(defn- group-by-file [forms]
(into (sorted-map) (group-by :file forms)))

(defn- postprocess-file [lib file forms]
(with-open [in (io/reader (resource-reader file))]
(let [forms-by-line (group-by-line forms)
Expand Down
4 changes: 3 additions & 1 deletion cloverage/src/cloverage/report/coveralls.clj
Expand Up @@ -26,7 +26,9 @@
(let [lines (line-stats file-forms)]
{:name file
:source_digest (md5 (s/join "\n" (map :text lines)))
:coverage (map #(if (:instrumented? %) (:hit %)) lines)}))
:coverage (map #(when (:instrumented? %)
(:hit %))
lines)}))

(defn report [^String out-dir forms]
(let [output-file (io/file out-dir "coveralls.json")
Expand Down
1 change: 1 addition & 0 deletions cloverage/src/cloverage/report/raw.clj
@@ -1,6 +1,7 @@
(ns cloverage.report.raw
(:require
[clojure.java.io :as io]
[clojure.pprint]
[cloverage.report :refer [with-out-writer]]))

(defn report [^String out-dir stats covered]
Expand Down
7 changes: 3 additions & 4 deletions cloverage/test/cloverage/coverage_test.clj
Expand Up @@ -6,8 +6,7 @@
[cloverage.instrument :as inst]
[cloverage.source :as src]
[riddley.walk :as rw]
[clojure.java.io :as io])
(:import java.io.File))
[clojure.java.io :as io]))

(defn- denamespace
"Helper function to allow backticking w/o namespace interpolation."
Expand Down Expand Up @@ -434,7 +433,7 @@
(t/testing "check that eftest runner-fn just runs with opts as a seq of vectors, no errors"
(let [runner-opts {:runner-opts '([:test-warn-time 100]
[:multithread? false])}]
(with-redefs [cov/resolve-var (fn [x] (constantly {:error 0 :fail 0}))
(with-redefs [cov/resolve-var (fn [_x] (constantly {:error 0 :fail 0}))
cov/find-nses (constantly [])
cov/require-ns (constantly "test")
require (constantly nil)]
Expand All @@ -444,7 +443,7 @@
(t/testing "check that eftest runner-fn just runs with opts as a map and returns errors"
(let [runner-opts {:runner-opts {:test-warn-time 100
:multithread? false}}]
(with-redefs [cov/resolve-var (fn [x] (constantly {:error 1 :fail 2}))
(with-redefs [cov/resolve-var (fn [_x] (constantly {:error 1 :fail 2}))
cov/find-nses (constantly [])
cov/require-ns (constantly "test")
require (constantly nil)]
Expand Down
4 changes: 2 additions & 2 deletions cloverage/test/cloverage/report/console_test.clj
@@ -1,7 +1,7 @@
(ns cloverage.report.console-test
(:require
[clojure.test :refer :all]
[cloverage.report.console :refer :all]))
[clojure.test :refer [deftest is]]
[cloverage.report.console :refer [ansi colorize pad-right print-table printable-count strip-ansi]]))

(deftest check-ansi
(is (nil? (ansi :green nil)))
Expand Down
9 changes: 5 additions & 4 deletions cloverage/test/cloverage/report_test.clj
@@ -1,9 +1,10 @@
(ns cloverage.report-test
(:require
[clojure.test :refer :all]
[cloverage.report :refer :all]
[clojure.test :refer [deftest is]]
[cloverage.report :refer [gather-stats total-stats]]
[cloverage.source]
[cloverage.report.lcov]
[cloverage.report.html :refer [relative-path]]
[clojure.tools.reader :as r]
[clojure.java.io :as io]))

(defn- parse-readable
Expand Down Expand Up @@ -46,7 +47,7 @@
(is (= [] (gather-stats []))))

(deftest gather-stats-converts-file-forms
(with-redefs [cloverage.report/postprocess-file (fn [lib file forms] {:lib lib :file file})]
(with-redefs [cloverage.report/postprocess-file (fn [lib file _forms] {:lib lib :file file})]
(is (= '([:lib "lib"] [:file "file"]) (gather-stats [{:lib "lib" :file "file" :line 1}])))))

(deftest gather-starts-converts-raw-forms
Expand Down
4 changes: 4 additions & 0 deletions lein-cloverage/.clj-kondo/config.edn
@@ -0,0 +1,4 @@
{:linters {:docstring-leading-trailing-whitespace {:level :warning}
:reduce-without-init {:level :warning}
:single-key-in {:level :warning}
:used-underscored-binding {:level :warning}}}
20 changes: 17 additions & 3 deletions lein-cloverage/project.clj
Expand Up @@ -16,7 +16,20 @@
:lein-release {:scm :git ; Because we're not in the top-level directory, so it doesn't auto-detect
:deploy-via :clojars}
:aliases {"test-ci" ["with-profile" "-dev,+test,+ci" "test"]
"eastwood-ci" ["with-profile" "-dev,+test,+ci" "eastwood"]}
"eastwood-ci" ["with-profile" "-dev,+test,+ci" "eastwood"]
"kondo-deps" ["with-profile"
"+dev,+test,+ci,+clj-kondo"
"clj-kondo"
"--copy-configs"
"--dependencies"
"--lint"
"$classpath"]
"kondo-ci" ["do" ["kondo-deps"]
["with-profile"
"+dev,+test,+ci,+clj-kondo"
"clj-kondo"
"--lint"
"src" "test"]]}
:release-tasks [["vcs" "assert-committed"]
["change" "version" "leiningen.release/bump-version" "release"]
["vcs" "commit"]
Expand All @@ -31,8 +44,9 @@
["vcs" "push"]]

:min-lein-version "2.0.0"
:profiles {:dev {:plugins [[lein-cljfmt "0.6.4"]
:profiles {:dev {:plugins [[lein-cljfmt "0.8.0"]
[jonase/eastwood "1.2.3"]
[lein-kibit "0.1.7"]]}
[lein-kibit "0.1.8"]]}
:clj-kondo {:plugins [[com.github.clj-kondo/lein-clj-kondo "0.1.4"]]}
:ci {:pedantic? :abort}}
:eval-in-leiningen true)
4 changes: 2 additions & 2 deletions lein-cloverage/src/leiningen/cloverage.clj
Expand Up @@ -24,8 +24,8 @@
(let [project (project/merge-profiles project [:leiningen/test :test])
project (if (already-has-cloverage? project)
project
(update-in project [:dependencies]
conj ['cloverage (get-lib-version)]))
(update project :dependencies
conj ['cloverage (get-lib-version)]))
test-selectors (:test-selectors project)
opts (assoc (:cloverage project)
:src-ns-path (vec (:source-paths project))
Expand Down

0 comments on commit 87fd10f

Please sign in to comment.