Fork me on GitHub
#clojure-dev
<
2020-01-09
>
carocad14:01:04

hey everyone, is clojure.spec intented to be use as a linter ? I mean currently it only outputs errors but I see many opportunities it outputting warnings instead. However I dont see anything in spec to “capture” the error and print it as a warning instead :thinking_face: ps: not sure if this question belongs in this channel

seancorfield17:01:17

@carocad Linters check code statically, Spec checks data structures and functions at runtime -- can you elaborate on how you image Spec being used in the former scenario?

carocad17:01:27

> Linters check code statically afaik, no such restriction exists. That is just the “standard” way > Spec checks data structures and functions at runtime maybe I am being naive but since you have access to the code on macro expansion it should be possible to pattern match the input code to issue warning/errors. Throwing would probably be bad but clojure introduced tap so I guess it should be possible to just send the warning/errors over there. Not sure yet how to make this work outside of a repl but so far this is just an idea 🙂

seancorfield17:01:56

So you'd basically have to write a Spec for Clojure code and read in files and conform them to that Spec? 👀

seancorfield17:01:56

I'll be very interested in anything you produce in that vein. Sounds fascinating (but I'm seriously skeptical of the feasibility right now).

carocad17:01:51

> I’m seriously skeptical of the feasibility right now me too … that is why I posted it here hoping that people with way more experience on the inner workings of clojure would point out any “obvious” error 😅

carocad17:01:57

> So you’d basically have to write a Spec for Clojure code and read in files and conform them to that Spec? that would be for cli usage. I was hoping to “just” instrument the macro symbol and lint while on repl

borkdude19:01:16

if you want warnings instead of errors you could just catch the spec exceptions and handle them maybe?

borkdude19:01:00

@carocad are you aiming on specs for clojure.core? that has been done here as well: https://github.com/borkdude/speculative

carocad21:01:32

@U04V15CAJ yeah I checked your work on speculative great work btw 🙂 . Unfortunately it seems to only include functions not macros so I came here looking for more info 🙂 > if you want warnings instead of errors you could just catch the spec exceptions and handle them maybe? I have not seen a way to do this since the error is thrown by the compiler. Not sure if the repl has a hook that I can use :thinking_face: