Skip to content

Commit

Permalink
Make sure clojure.core.specs.alpha is loaded (cljdoc fix). Fix Ko…
Browse files Browse the repository at this point in the history
…ndo linter bugs (#143)

* Make sure `clojure.core.specs.alpha` is loaded (`cljdoc` fix)

* Fix Kondo errors (#141)

* Don't use square brackets for class names in describe strings

* Update tests
  • Loading branch information
camsaul authored Jan 19, 2023
1 parent d65f076 commit 258d0d1
Show file tree
Hide file tree
Showing 17 changed files with 45 additions and 33 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ There is still room for even more performance improvement!

## License

Code, documentation, and artwork copyright © 2019-2022 Cam Saul.
Code, documentation, and artwork copyright © 2019-2023 Cam Saul.

Distributed under the [Eclipse Public
License](https://raw.githubusercontent.com/metabase/camsaul/methodical/LICENSE), same as Clojure.
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,24 @@
[(hooks/token-node 'do)
multimethod]
(filter some? (vals other-stuff))
[(hooks/list-node
(list*
(hooks/token-node 'fn)
(hooks/token-node (if (contains? #{nil :around} (some-> (:qualifier parsed) hooks/sexpr))
'next-method
'__FN__NAME__THAT__YOU__CANNOT__REFER__TO__))
fn-tail))]))]
[(-> (hooks/list-node
(list*
(hooks/token-node 'fn)
(hooks/token-node (if (contains? #{nil :around} (some-> (:qualifier parsed) hooks/sexpr))
'next-method
'__FN__NAME__THAT__YOU__CANNOT__REFER__TO__))
fn-tail))
(vary-meta update :clj-kondo/ignore conj :redundant-fn-wrapper))]))]
#_(println "=>")
#_(clojure.pprint/pprint (hooks/sexpr result))
{:node result})))

;;; this stuff is for debugging things to make sure we didn't do something dumb
(comment
(defn defmethod* [form]
(hooks/sexpr (:node (defmethod {:node (hooks/parse-string (str form))}))))
(binding [*print-meta* true]
(clojure.pprint/pprint
(hooks/sexpr (:node (defmethod {:node (hooks/parse-string (str form))}))))))

(defmethod* '(defmethod mf :second [& _] 2))

Expand All @@ -140,7 +143,12 @@

(defmethod* '(m/defmethod mf1 :docstring
"Docstring"
[_x])))
[_x]))

(defmethod* '(m/defmethod mf1 :around :dispatch-value
"Docstring"
[x]
(next-method x))))

(defn defmulti
[{{[_ multimethod-name & args] :children, :as node} :node}]
Expand Down
2 changes: 1 addition & 1 deletion src/methodical/impl/cache/simple.clj
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@

describe/Describable
(describe [this]
(format "It caches methods using a [[%s]]." (.getCanonicalName (class this)))))
(format "It caches methods using a `%s`." (.getCanonicalName (class this)))))
2 changes: 1 addition & 1 deletion src/methodical/impl/cache/watching.clj
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

describe/Describable
(describe [this]
(format "It caches methods using a [[%s]]." (.getCanonicalName (class this)))))
(format "It caches methods using a `%s`." (.getCanonicalName (class this)))))

(defn- cache-watch-fn [cache]
(let [cache-weak-ref (WeakReference. cache)]
Expand Down
2 changes: 1 addition & 1 deletion src/methodical/impl/combo/clojure.clj
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@

describe/Describable
(describe [this]
(format "It uses the method combination [[%s]]." (.getCanonicalName (class this)))))
(format "It uses the method combination `%s`." (.getCanonicalName (class this)))))
2 changes: 1 addition & 1 deletion src/methodical/impl/combo/clos.clj
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@

describe/Describable
(describe [this]
(format "It uses the method combination [[%s]]." (.getCanonicalName (class this)))))
(format "It uses the method combination `%s`." (.getCanonicalName (class this)))))
6 changes: 4 additions & 2 deletions src/methodical/impl/combo/operator.clj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
(:refer-clojure :exclude [methods])
(:require
[clojure.core.protocols :as clojure.protocols]
[clojure.core.specs.alpha]
[clojure.spec.alpha :as s]
[methodical.impl.combo.common :as combo.common]
[methodical.interface]
Expand All @@ -53,7 +54,8 @@

(set! *warn-on-reflection* true)

(comment methodical.interface/keep-me)
(comment clojure.core.specs.alpha/keep-me ; for the specs
methodical.interface/keep-me)

(defmulti operator
"Define a new operator that can be used as part of an `OperatorMethodCombination`. See examples below for more
Expand Down Expand Up @@ -204,7 +206,7 @@

describe/Describable
(describe [this]
(format "It uses the method combination [[%s]]\nwith the operator `%s`."
(format "It uses the method combination `%s`\nwith the operator `%s`."
(.getCanonicalName (class this))
(pr-str operator-name))))

Expand Down
2 changes: 1 addition & 1 deletion src/methodical/impl/combo/threaded.clj
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@

describe/Describable
(describe [this]
(format "It uses the method combination [[%s]]\nwith the threading strategy `%s`."
(format "It uses the method combination `%s`\nwith the threading strategy `%s`."
(.getCanonicalName (class this))
(pr-str threading-type))))

Expand Down
2 changes: 1 addition & 1 deletion src/methodical/impl/dispatcher/everything.clj
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@

describe/Describable
(describe [this]
(format "It uses the dispatcher [[%s]]\nwith hierarchy `%s`\nand prefs `%s`."
(format "It uses the dispatcher `%s`\nwith hierarchy `%s`\nand prefs `%s`."
(.getCanonicalName (class this))
(pr-str hierarchy-var)
(pr-str prefs))))
2 changes: 1 addition & 1 deletion src/methodical/impl/dispatcher/multi_default.clj
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@

describe/Describable
(describe [this]
(format "It uses the dispatcher [[%s]]\nwith hierarchy `%s`\nand prefs `%s`.\n\nThe default value is `%s`."
(format "It uses the dispatcher `%s`\nwith hierarchy `%s`\nand prefs `%s`.\n\nThe default value is `%s`."
(.getCanonicalName (class this))
(pr-str hierarchy-var)
(pr-str prefs)
Expand Down
2 changes: 1 addition & 1 deletion src/methodical/impl/dispatcher/standard.clj
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@

describe/Describable
(describe [this]
(format "It uses the dispatcher [[%s]]\nwith hierarchy `%s`\nand prefs `%s`.\n\nThe default value is `%s`."
(format "It uses the dispatcher `%s`\nwith hierarchy `%s`\nand prefs `%s`.\n\nThe default value is `%s`."
(.getCanonicalName (class this))
(pr-str hierarchy-var)
(pr-str prefs)
Expand Down
2 changes: 1 addition & 1 deletion src/methodical/impl/method_table/clojure.clj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@

describe/Describable
(describe [this]
(format "It uses the method table [[%s]]. These primary methods are known:\n\n%s"
(format "It uses the method table `%s`. These primary methods are known:\n\n%s"
(.getCanonicalName (class this))
(method-table.common/describe-primary-methods m))))
2 changes: 1 addition & 1 deletion src/methodical/impl/method_table/standard.clj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,6 @@

describe/Describable
(describe [this]
(str (format "It uses the method table [[%s]]." (.getCanonicalName (class this)))
(str (format "It uses the method table `%s`." (.getCanonicalName (class this)))
(method-table.common/describe-primary-methods primary)
(method-table.common/describe-aux-methods aux))))
3 changes: 3 additions & 0 deletions src/methodical/macros.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"Methodical versions of vanilla Clojure [[defmulti]] and [[defmethod]] macros."
(:refer-clojure :exclude [defmulti defmethod])
(:require
[clojure.core.specs.alpha]
[clojure.spec.alpha :as s]
[clojure.string :as str]
[methodical.impl :as impl]
Expand All @@ -13,6 +14,8 @@

(set! *warn-on-reflection* true)

(comment clojure.core.specs.alpha/keep-me) ; for the specs below

(s/def ::fn-tail
(s/alt :arity-1 :clojure.core.specs.alpha/params+body
:arity-n (s/+ (s/spec :clojure.core.specs.alpha/params+body))))
Expand Down
8 changes: 4 additions & 4 deletions test/methodical/macros_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -584,18 +584,18 @@
(let [original-hash (::macros/defmulti-hash (meta (resolve 'methodical.macros-test/metadata-updates-mf)))
expected-doc ["metadata-updates-mf is defined in [[methodical.macros-test]] (methodical/macros_test.clj:574)."
""
"It caches methods using a [[methodical.impl.cache.watching.WatchingCache]]."
"It caches methods using a `methodical.impl.cache.watching.WatchingCache`."
""
"It uses the method combination [[methodical.impl.combo.threaded.ThreadingMethodCombination]]"
"It uses the method combination `methodical.impl.combo.threaded.ThreadingMethodCombination`"
"with the threading strategy `:thread-last`."
""
"It uses the dispatcher [[methodical.impl.dispatcher.multi_default.MultiDefaultDispatcher]]"
"It uses the dispatcher `methodical.impl.dispatcher.multi_default.MultiDefaultDispatcher`"
"with hierarchy `#'clojure.core/global-hierarchy`"
"and prefs `{}`."
""
"The default value is `:default`."
""
"It uses the method table [[methodical.impl.method_table.standard.StandardMethodTable]]."
"It uses the method table `methodical.impl.method_table.standard.StandardMethodTable`."
""
"These primary methods are known:"
""
Expand Down
5 changes: 2 additions & 3 deletions test/methodical/test_runner.clj
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@
(let [stdout-reporter (if ci?
eftest.report.pretty/report
eftest.report.progress/report)]
(fn handle-event [event]
#_(test-runner.junit/handle-event! event) ; TODO
(stdout-reporter event))))
#_(test-runner.junit/handle-event! event) ; TODO
stdout-reporter))

(defn run
"Run `test-vars` with `options`, which are passed directly to [[eftest.runner/run-tests]].
Expand Down
8 changes: 4 additions & 4 deletions test/methodical/util/describe_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@
(def ^:private expected-description
["mf is defined in [[methodical.util.describe-test]] (methodical/util/describe_test.clj:12)."
""
"It caches methods using a [[methodical.impl.cache.watching.WatchingCache]]."
"It caches methods using a `methodical.impl.cache.watching.WatchingCache`."
""
"It uses the method combination [[methodical.impl.combo.threaded.ThreadingMethodCombination]]"
"It uses the method combination `methodical.impl.combo.threaded.ThreadingMethodCombination`"
"with the threading strategy `:thread-last`."
""
"It uses the dispatcher [[methodical.impl.dispatcher.multi_default.MultiDefaultDispatcher]]"
"It uses the dispatcher `methodical.impl.dispatcher.multi_default.MultiDefaultDispatcher`"
"with hierarchy `#'clojure.core/global-hierarchy`"
"and prefs `{:x #{:y}}`."
""
"The default value is `:default`."
""
"It uses the method table [[methodical.impl.method_table.standard.StandardMethodTable]]."
"It uses the method table `methodical.impl.method_table.standard.StandardMethodTable`."
""
"These primary methods are known:"
""
Expand Down

0 comments on commit 258d0d1

Please sign in to comment.