Fork me on GitHub
#clojure
<
2020-07-25
>
Kevin08:07:14

Is anyone aware of a tool that checks all your project's publics and report any functions that have no docstring or spec definition?

borkdude09:07:18

@kevin.van.rooijen clj-kondo has a linter for missing docstrings

Kevin09:07:15

Thanks, found it 🙂

borkdude09:07:52

I think you can write a script/function to iterate over all namespaces (all-ns), find the publics (ns-publics) and check if there's a spec for it (get-spec).

borkdude09:07:53

That will also work for docstrings btw, you can check meta. But clj-kondo reports it while you're typing.

Kevin09:07:28

Yeah it doesn't sound too difficult to implement. But if it already existed I might as well use that. I'll take a look at the spec implementation. Thanks!

borkdude09:07:36

@kevin.van.rooijen Quick repl session:

$ clj
Clojure 1.10.1
user=> (require '[clojure.spec.alpha :as s])
nil
user=> (s/fdef user/foo :args (s/cat :i int?))
user/foo
user=> (defn foo [x])
#'user/foo
user=> (defn bar [])
#'user/bar
user=> (doseq [[_ v] (ns-publics *ns*)] (when-not (s/get-spec (symbol (str (ns-name *ns*)) (str (:name (meta v))))) (prn "No spec for" v)))
"No spec for" #'user/bar
nil

3
borkdude09:07:09

Note that you might have to exclude non-function vars, but that can be done by checking :arglists on the meta of the var possibly

sveri09:07:17

I just debugged some code and figured out that there is no conversion available for java.nio.file.Path in (https://github.com/clojure/clojure/blob/master/src/clj/clojure/java/io.clj#L44) I wonder what I am missing here. That basically means we can never use Path with http://clojure.io?

borkdude11:07:25

@sveri Is that protocol open for extension to Path?

Alex Miller (Clojure team)13:07:10

Everything in in http://clojure.java.io predates the existence of Path

Alex Miller (Clojure team)13:07:39

Circling back and updating it is a future project

borkdude14:07:57

would be exciting to see it updated

9
Alex Miller (Clojure team)14:07:04

Yeah, needs some thinking

hammock 6
Alex Miller (Clojure team)14:07:19

Having done a lot of Java file stuff lately, it’s a little frustrating how often you need to convert between file and path to use different apis

Alex Miller (Clojure team)14:07:24

I wish they had done more to really make path do everything

potetm15:07:56

What does file do that path doesn’t?

sveri15:07:41

I think it's more the other way around. java.nio. is the new API which has more capabilities than the old one. For me it was not even about functionality. I just stumbled upon code that tried to call (io/file ... on a java.nio.file.Path object which it cannot convert. This is one of these so called *surprise things where an API does things that you would not expect it to. Or better, I would have expected it to work, given that it is partof the JDK since 1.7.

potetm16:07:52

Did you used to have [raynes/fs](https://github.com/Raynes/fs/) on the classpath somewhere?

potetm16:07:33

it adds a coercer that would make that work

potetm16:07:00

i was bitten by this once

sveri16:07:07

No, I did not, that's good to know. Thank you 🙂

deactivateduser17:07:20

Shame that isn’t baked into core, especially as Clojure 1.10+ dropped support for JVMs that lack java.nio.file.

potetm16:07:28

yeah, that was my general impression. hence the q.

Drew Verlee19:07:06

Would it be possible to make a clojure.core/for version of a transducer? I have no actual need for this. It just occurred to me watching the clojure North video on prolog

mpenet19:07:50

cgrand/xforms has this

👏 9